Skip to content

Require compile-time constants in JspBase.unsafe() - #8370

Merged
labkey-adam merged 6 commits into
developfrom
fb_unsafe
Nov 21, 2026
Merged

labkey-adam merged 6 commits into
developfrom
fb_unsafe

Conversation

@labkey-adam

@labkey-adam labkey-adam commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Rationale

This PR makes JspBase.unsafe() accept only compile-time constants, so JSPs can no longer write dynamic strings to the page without encoding them. Error Prone enforces the new @CompileTimeConstant annotation, and this PR converts the callers that passed dynamic strings in the most common patterns. About 75 non-constant callers remain for follow-up work, nearly all in platform; they fail only in builds run with -PerrorProne.

Related Pull Requests

Changes

  • JspBase.unsafe() requires a compile-time constant, and its CharSequence overload is removed
  • JSPs that built markup from strings now use HtmlString, h(), link and button builders, or JavaScript-safe encoding (q(), JSON) inside script blocks
  • The export-script view writes plain text directly instead of going through a JSP
  • PageConfig.makeId() rejects invalid prefixes
  • LabKeyCollectors.joining() keeps delimiters next to empty elements and when combining parallel results
  • HtmlStringBuilder appends another builder directly, without copying it into an intermediate HtmlString
  • Minor cleanups in ReturnUrlForm and the devtools module
  • The analytics tracking script is returned as trusted HTML from the service instead of being passed to unsafe() by each page template

Verified with -PerrorProne compiles of the api, core, and search modules, the PageConfig and LabKeyCollectors unit tests on a local server, AbstractExportTest, and manual checks of the folder type, search, and export script pages.

Annotate JspBase.unsafe() with @CompileTimeConstant and convert JSPs that passed it dynamic strings to HtmlString, h(), link builders, or JSON.
The tracking script is trusted markup, so the service declares it once instead of each template passing it to unsafe().

@labkey-matthewb labkey-matthewb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only comment that might need action is search.jsp.

labkey-adam added a commit to LabKey/targetedms that referenced this pull request Nov 21, 2026
## Rationale
This PR makes `JspBase.unsafe()` accept only compile-time constants, so
JSPs can no longer write dynamic strings to the page without encoding
them. Error Prone enforces the new `@CompileTimeConstant` annotation,
and this PR converts the callers that passed dynamic strings in the most
common patterns. About 75 non-constant callers remain for follow-up
work, nearly all in platform; they fail only in builds run with
`-PerrorProne`.

## Related Pull Requests
- LabKey/platform#8370
- LabKey/testAutomation#3314
- LabKey/commonAssays#1115
- LabKey/customModules#295
- LabKey/ehrModules#1250
- LabKey/premiumModules#877
- LabKey/LabDevKitModules#332
- LabKey/internalModules#177
- LabKey/clientModules#158
- LabKey/MacCossLabModules#695
- LabKey/wnprc-modules#1095

## Changes
- The download menu's tracking check works with the analytics tracking
script now being returned as HTML
- The figures of merit page and the spectrum viewer write their CV limit
and chart selector as JavaScript values instead of passing strings to
`unsafe()`

Not compiled locally because this module isn't in my build; checked with
IntelliJ inspections.
@labkey-adam
labkey-adam merged commit e42a082 into develop Nov 21, 2026
8 checks passed
@labkey-adam
labkey-adam deleted the fb_unsafe branch November 21, 2026 05:35
labkey-adam added a commit to LabKey/wnprc-modules that referenced this pull request Nov 21, 2026
## Rationale
This PR makes `JspBase.unsafe()` accept only compile-time constants, so
JSPs can no longer write dynamic strings to the page without encoding
them. Error Prone enforces the new `@CompileTimeConstant` annotation,
and this PR converts the callers that passed dynamic strings in the most
common patterns. About 75 non-constant callers remain for follow-up
work, nearly all in platform; they fail only in builds run with
`-PerrorProne`.

## Related Pull Requests
- LabKey/platform#8370
- LabKey/testAutomation#3314
- LabKey/commonAssays#1115
- LabKey/customModules#295
- LabKey/ehrModules#1250
- LabKey/premiumModules#877
- LabKey/LabDevKitModules#332
- LabKey/internalModules#177
- LabKey/clientModules#158
- LabKey/MacCossLabModules#695
- LabKey/targetedms#1310

## Changes
- The necropsy report, necropsy collection list, and death notification
encode database values, including multiline notes, instead of passing
them to `unsafe()`, keeping their fixed "not specified" markup as
trusted constants
- The pathology case list and water calendar write their JSON data to
the page as JSON values

Not compiled locally because this module isn't in my build; checked with
IntelliJ inspections.
labkey-adam added a commit to LabKey/customModules that referenced this pull request Nov 21, 2026
## Rationale
This PR makes `JspBase.unsafe()` accept only compile-time constants, so
JSPs can no longer write dynamic strings to the page without encoding
them. Error Prone enforces the new `@CompileTimeConstant` annotation,
and this PR converts the callers that passed dynamic strings in the most
common patterns. About 75 non-constant callers remain for follow-up
work, nearly all in platform; they fail only in builds run with
`-PerrorProne`.

## Related Pull Requests
- LabKey/platform#8370
- LabKey/testAutomation#3314
- LabKey/commonAssays#1115
- LabKey/ehrModules#1250
- LabKey/premiumModules#877
- LabKey/LabDevKitModules#332
- LabKey/internalModules#177
- LabKey/clientModules#158
- LabKey/MacCossLabModules#695
- LabKey/targetedms#1310
- LabKey/wnprc-modules#1095

## Changes
- `JspBase.unsafe()` requires a compile-time constant, and its
`CharSequence` overload is removed
- JSPs that built markup from strings now use `HtmlString`, `h()`, link
and button builders, or JavaScript-safe encoding (`q()`, JSON) inside
script blocks
- The export-script view writes plain text directly instead of going
through a JSP
- `PageConfig.makeId()` rejects invalid prefixes
- `LabKeyCollectors.joining()` keeps delimiters next to empty elements
and when combining parallel results
- Minor cleanups in `ReturnUrlForm` and the devtools module
- Specimen visit report cells are built as `HtmlString`, with links
built from `ActionURL` and `LinkBuilder` instead of query strings and
hand-coded tags
- The specimen display-settings enum renders itself directly, and the
remaining specimen pages encode plain-text values with `h()`

Verified with `-PerrorProne` compiles of the api, core, and search
modules, the `PageConfig` and `LabKeyCollectors` unit tests on a local
server, `AbstractExportTest`, and manual checks of the folder type,
search, and export script pages.
labkey-adam added a commit to LabKey/commonAssays that referenced this pull request Nov 21, 2026
## Rationale
This PR makes `JspBase.unsafe()` accept only compile-time constants, so
JSPs can no longer write dynamic strings to the page without encoding
them. Error Prone enforces the new `@CompileTimeConstant` annotation,
and this PR converts the callers that passed dynamic strings in the most
common patterns. About 75 non-constant callers remain for follow-up
work, nearly all in platform; they fail only in builds run with
`-PerrorProne`.

## Related Pull Requests
- LabKey/platform#8370
- LabKey/testAutomation#3314
- LabKey/customModules#295
- LabKey/ehrModules#1250
- LabKey/premiumModules#877
- LabKey/LabDevKitModules#332
- LabKey/internalModules#177
- LabKey/clientModules#158
- LabKey/MacCossLabModules#695
- LabKey/targetedms#1310
- LabKey/wnprc-modules#1095

## Changes
- `JspBase.unsafe()` requires a compile-time constant, and its
`CharSequence` overload is removed
- JSPs that built markup from strings now use `HtmlString`, `h()`, link
and button builders, or JavaScript-safe encoding (`q()`, JSON) inside
script blocks
- The export-script view writes plain text directly instead of going
through a JSP
- `PageConfig.makeId()` rejects invalid prefixes
- `LabKeyCollectors.joining()` keeps delimiters next to empty elements
and when combining parallel results
- Minor cleanups in `ReturnUrlForm` and the devtools module
- Flow compensation, analysis-import, and run-import pages encode
workspace subset names and the graph-size preference, and build their
selects and image markup with builders instead of passing strings to
`unsafe()` or hand-written tags
- The ms2 search-defaults editors encode their configuration XML, and
the remaining flow, luminex, and ms2 pages encode plain-text values

Verified with `-PerrorProne` compiles of the api, core, and search
modules, the `PageConfig` and `LabKeyCollectors` unit tests on a local
server, `AbstractExportTest`, and manual checks of the folder type,
search, and export script pages.
labkey-adam added a commit to LabKey/ehrModules that referenced this pull request Nov 21, 2026
## Rationale
This PR makes `JspBase.unsafe()` accept only compile-time constants, so
JSPs can no longer write dynamic strings to the page without encoding
them. Error Prone enforces the new `@CompileTimeConstant` annotation,
and this PR converts the callers that passed dynamic strings in the most
common patterns. About 75 non-constant callers remain for follow-up
work, nearly all in platform; they fail only in builds run with
`-PerrorProne`.

## Related Pull Requests
- LabKey/platform#8370
- LabKey/testAutomation#3314
- LabKey/commonAssays#1115
- LabKey/customModules#295
- LabKey/premiumModules#877
- LabKey/LabDevKitModules#332
- LabKey/internalModules#177
- LabKey/clientModules#158
- LabKey/MacCossLabModules#695
- LabKey/targetedms#1310
- LabKey/wnprc-modules#1095

## Changes
- `JspBase.unsafe()` requires a compile-time constant, and its
`CharSequence` overload is removed
- JSPs that built markup from strings now use `HtmlString`, `h()`, link
and button builders, or JavaScript-safe encoding (`q()`, JSON) inside
script blocks
- The export-script view writes plain text directly instead of going
through a JSP
- `PageConfig.makeId()` rejects invalid prefixes
- `LabKeyCollectors.joining()` keeps delimiters next to empty elements
and when combining parallel results
- Minor cleanups in `ReturnUrlForm` and the devtools module

Verified with `-PerrorProne` compiles of the api, core, and search
modules, the `PageConfig` and `LabKeyCollectors` unit tests on a local
server, `AbstractExportTest`, and manual checks of the folder type,
search, and export script pages.
labkey-adam added a commit to LabKey/MacCossLabModules that referenced this pull request Nov 21, 2026
## Rationale
This PR makes `JspBase.unsafe()` accept only compile-time constants, so
JSPs can no longer write dynamic strings to the page without encoding
them. Error Prone enforces the new `@CompileTimeConstant` annotation,
and this PR converts the callers that passed dynamic strings in the most
common patterns. About 75 non-constant callers remain for follow-up
work, nearly all in platform; they fail only in builds run with
`-PerrorProne`.

## Related Pull Requests
- LabKey/platform#8370
- LabKey/testAutomation#3314
- LabKey/commonAssays#1115
- LabKey/customModules#295
- LabKey/ehrModules#1250
- LabKey/premiumModules#877
- LabKey/LabDevKitModules#332
- LabKey/internalModules#177
- LabKey/clientModules#158
- LabKey/targetedms#1310
- LabKey/wnprc-modules#1095

## Changes
- The LINCS download tracking check works with the analytics tracking
script now being returned as HTML
- The Skyline tool store builds its Download and Documentation button
labels with `HtmlStringBuilder` instead of passing concatenated markup
to `unsafe()`

Not compiled locally because this module isn't in my build; checked with
IntelliJ inspections.
labkey-adam added a commit to LabKey/LabDevKitModules that referenced this pull request Nov 21, 2026
## Rationale
This PR makes `JspBase.unsafe()` accept only compile-time constants, so
JSPs can no longer write dynamic strings to the page without encoding
them. Error Prone enforces the new `@CompileTimeConstant` annotation,
and this PR converts the callers that passed dynamic strings in the most
common patterns. About 75 non-constant callers remain for follow-up
work, nearly all in platform; they fail only in builds run with
`-PerrorProne`.

## Related Pull Requests
- LabKey/platform#8370
- LabKey/testAutomation#3314
- LabKey/commonAssays#1115
- LabKey/customModules#295
- LabKey/ehrModules#1250
- LabKey/premiumModules#877
- LabKey/internalModules#177
- LabKey/clientModules#158
- LabKey/MacCossLabModules#695
- LabKey/targetedms#1310
- LabKey/wnprc-modules#1095

## Changes
- The laboratory data browser passes its filter types to the page as
JSON instead of hand-built, HTML-encoded script text

Not compiled or tested locally because the laboratory module isn't in my
build.
labkey-adam added a commit to LabKey/testAutomation that referenced this pull request Nov 21, 2026
## Rationale
This PR makes `JspBase.unsafe()` accept only compile-time constants, so
JSPs can no longer write dynamic strings to the page without encoding
them. Error Prone enforces the new `@CompileTimeConstant` annotation,
and this PR converts the callers that passed dynamic strings in the most
common patterns. About 75 non-constant callers remain for follow-up
work, nearly all in platform; they fail only in builds run with
`-PerrorProne`.

## Related Pull Requests
- LabKey/platform#8370
- LabKey/commonAssays#1115
- LabKey/customModules#295
- LabKey/ehrModules#1250
- LabKey/premiumModules#877
- LabKey/LabDevKitModules#332
- LabKey/internalModules#177
- LabKey/clientModules#158
- LabKey/MacCossLabModules#695
- LabKey/targetedms#1310
- LabKey/wnprc-modules#1095

## Changes
- `JspBase.unsafe()` requires a compile-time constant, and its
`CharSequence` overload is removed
- JSPs that built markup from strings now use `HtmlString`, `h()`, link
and button builders, or JavaScript-safe encoding (`q()`, JSON) inside
script blocks
- The export-script view writes plain text directly instead of going
through a JSP
- `PageConfig.makeId()` rejects invalid prefixes
- `LabKeyCollectors.joining()` keeps delimiters next to empty elements
and when combining parallel results
- Minor cleanups in `ReturnUrlForm` and the devtools module
- The dumbster mail page builds its header list with
`HtmlStringBuilder`, and it and the crawler injection page mark their
deliberately raw HTML with an explicit `HtmlString.unsafe()`

Verified with `-PerrorProne` compiles of the api, core, and search
modules, the `PageConfig` and `LabKeyCollectors` unit tests on a local
server, `AbstractExportTest`, and manual checks of the folder type,
search, and export script pages.
labkey-adam added a commit that referenced this pull request Nov 28, 2026
## Rationale
This PR removes the remaining non-constant `JspBase.unsafe()` calls in
platform, the follow-up to #8370,
so builds with `-PerrorProne` report no `CompileTimeConstant` warnings
from JSPs. Along the way it fixes several places where unencoded values
reached the page, including group names rendered as HTML in membership
tooltips and a request-supplied participant view script.

## Related Pull Requests
- LabKey/limsModules#2641

## Changes
- JSPs encode dynamic values with `h()`, write static markup directly,
or use `q()` in script blocks instead of passing built strings to
`unsafe()`
- Renderers that built HTML strings (custom properties, issue detail
info, pipeline delete confirmation, search indexer stats) now return
`HtmlString`
- `Visit.SequenceHandling` is safe to render directly
- The plain-text file digest email is built in Java instead of a JSP
- Membership tooltips encode their HTML for the attribute, and the
participant view preview uses only the saved script
- Fixed double-encoded labels on the dataset display order page and a
malformed row tag in issue details

Verified with a `-PerrorProne` compile of all platform modules and JSPs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants