Skip to content

Fix DOM-XSS in theme dropdowns via innerHTML concat#188

Open
stultus wants to merge 1 commit into
PeARSearch:mainfrom
stultus:fix/theme-innerhtml-xss
Open

Fix DOM-XSS in theme dropdowns via innerHTML concat#188
stultus wants to merge 1 commit into
PeARSearch:mainfrom
stultus:fix/theme-innerhtml-xss

Conversation

@stultus
Copy link
Copy Markdown
Member

@stultus stultus commented Apr 15, 2026

  • Theme names from the database were concatenated into an HTML string and assigned to innerHTML, enabling DOM-based XSS via a malicious theme name
  • Replaces the concat pattern with DOM-API construction (document.createElement('option') + option.value = theme) in all four affected templates: index.html, suggest.html, write_and_index.html, web_commentary.html
  • Adds a regression-guard test that greps the templates for the vulnerable patterns and the corrected createElement call

Closes #163

Theme names from the database were concatenated into an HTML string
and assigned to innerHTML, so a theme name containing quotes or a
<script> tag could break out of the value attribute and execute as
DOM-based XSS.

Replace the string-concat pattern with DOM-API construction
(document.createElement('option') + option.value = theme) in all four
templates that render the theme datalist: index.html, suggest.html,
write_and_index.html, web_commentary.html. Setting .value directly
leaves the browser to handle attribute escaping and never goes through
an HTML parser.

Add tests/test_theme_xss.py as a regression guard: it greps each of
the four templates for the vulnerable patterns (+ '<option', and
.innerHTML = str) and for the corrected createElement('option') call.
Any future re-introduction of the unsafe pattern will fail CI.
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.

innerHTML with user-controlled data in theme dropdowns

2 participants