Skip to content

web: escape page title and consoles link in the UI index - #20078

Open
Thanatos9404 wants to merge 2 commits into
prometheus:mainfrom
Thanatos9404:web-escape-index-placeholders
Open

Thanatos9404 wants to merge 2 commits into
prometheus:mainfrom
Thanatos9404:web-escape-index-placeholders

Conversation

@Thanatos9404

Copy link
Copy Markdown

@juliusv, a small fix in how the UI's index.html is served.

serveReactApp writes the flag values into index.html with plain byte replacement. The consoles link lands in a single-quoted JavaScript string in an inline script, and the external URL path is decoded at that point, so --web.external-url=http://host/it%27s/ with a consoles directory renders const GLOBAL_CONSOLES_LINK='/it's/consoles/index.html';. That script fails to parse, the globals are never defined, and the UI comes up blank. A --web.page-title such as Staging </title><b>QA</b> ends the title element early and the rest is parsed as markup.

The substitution now lives in a small method that escapes the consoles link with template.JSEscapeString and the title with html.EscapeString. Values without special characters come out exactly as before. One visible change: a title written with HTML entities such as &amp; now shows them literally.

A new table test runs the index.html templates of both UIs through the method and fails without the escaping; go test ./web/... and golangci-lint pass.

Which issue(s) does the PR fix:

None, there is no issue for this.

Release notes for end users (ALL commits must be considered).

Reviewers should verify clarity and quality.

[BUGFIX] UI: Escape the page title and the consoles link in the served index.html, so a quote in the `--web.external-url` path or markup in `--web.page-title` no longer breaks the page.

Move the placeholder replacement for the React app's index.html out of
the serveReactApp closure into renderReactIndex, so it can be tested
without the built UI assets. No behaviour change.

Signed-off-by: Yashvardhan Thanvi <[email protected]>
The page title and the consoles link were written into the UI's
index.html unescaped. The consoles link sits in a quoted JavaScript
string in an inline script, and the external URL path is decoded before
it gets there, so --web.external-url=http://host/it%27s/ together with
a consoles directory made the script fail to parse and left the UI
blank. A page title containing markup such as </title> ended the title
element early.

Escape the consoles link with template.JSEscapeString and the title
with html.EscapeString. Values without special characters are written
exactly as before.

Signed-off-by: Yashvardhan Thanvi <[email protected]>
@Thanatos9404
Thanatos9404 requested a review from a team as a code owner October 19, 2026 16:35
@Thanatos9404
Thanatos9404 requested a review from dashpole October 19, 2026 16:35
@dashpole
dashpole removed their request for review October 19, 2026 20:07
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.

1 participant