Skip to content

refactor(editor): render option lists through an escaping helper - #336

Merged
TheWitness merged 4 commits into
developfrom
refactor/editor-option-escaping
Nov 11, 2026
Merged

TheWitness merged 4 commits into
developfrom
refactor/editor-option-escaping

Conversation

@somethingwithproof

@somethingwithproof somethingwithproof commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Fixes #334

Render the editor's dynamic <option> lists through wm_editor_attributes() and wm_editor_option(), so attribute values and labels are always escaped. Attribute names come from a fixed set and are validated.

  • Scope: the icon, background, graph-template, background-sizing and key-style lists, and get_fontlist(). Static template HTML is unchanged.
  • Values use plugin_weathermap_escape_attr(), so a name containing &amp; round-trips exactly. html_escape() does not double-encode, so it doesn't.
  • Output is the same for normal values. Key-style labels are now escaped, a stray > is gone from the AICON placeholder, and the missing space before selected is restored.
  • Tests: unit tests for the helper; an E2E test that renders hostile filenames through the editor code and parses the output with DOMDocument; and a security test that flags unescaped attribute concatenation on the editor page. That test flags 8 places on the editor page before fix: address actionable code-scanning findings #331, 4 after fix: address actionable code-scanning findings #331, and 0 here.
  • Verified: the full Pest suite passes (400), and all browser tests pass apart from ClickableHoverTest, which already fails on develop and is fixed in ci: run the jsdom browser tests with locked dependencies #333.

Merge order: #341 is stacked on this PR, so merge this one first.

Add wm_editor_attributes() and wm_editor_option() so every attribute value
and option label on the editor page is escaped by construction. Attribute
names must match a plain HTML name; true renders a boolean attribute and
false or null omits it.

Values use plugin_weathermap_escape_attr(), which double-encodes, so names
such as "A&amp;B.png" round-trip instead of collapsing to "A&B.png".

Convert the icon, background, graph template, background sizing and key
style lists, and get_fontlist(). The key style labels were previously
printed unescaped, and the "Special Icon (AICON)" placeholder lost a
stray ">".

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
…ge lists

Fail when the editor page concatenates or interpolates an unescaped value
into an HTML attribute, or prints an <option> without wm_editor_option().

Render the icon and background lists from real image files with hostile
names through the editor page's own code, parse the result with
DOMDocument, and check that no attributes or elements are injected and
that every value and label round-trips.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
The option lists now pass __() text to the escaping helper instead of
__esc(), so the template's source references change. Regenerating also
adds strings the template was already missing.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Write each extracted section to a temporary file and include it in the
caller's scope, as the page runs it, instead of passing it to eval().

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
@sonarqubecloud

sonarqubecloud Bot commented Nov 9, 2026

Copy link
Copy Markdown

@alcatron

alcatron commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Checked c9a3f11 locally: 401 PHP tests passed. The browser checks had only the existing ClickableHoverTest failure, which #333 fixes.

I also tested this with #341 and the editor split in #347. After updating the image-options test loader for the moved functions, the combined browser suite passed. No additional problem found with the escaping changes in these checks. A quick real-browser check of the dropdowns alongside #341 and #347 would be useful; no separate full walkthrough is needed for this PR.

@somethingwithproof

Copy link
Copy Markdown
Member Author

Checked the dropdowns in Safari 27.2 against Cacti 1.2.32 alongside #341 and #347: the icon list's 99 options are plain text with the expected values and preview paths, and the jQuery UI selectmenus open within the window and update their field when an entry is chosen. No JavaScript errors.

@alcatron alcatron 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.

Rechecked this with the updated #341 and #347. The combined batch passed 648 PHP tests and all 33 browser test files without local test fixes. Thanks for checking the dropdowns in Safari too. Looks good to me.

@TheWitness
TheWitness merged commit 23ab420 into develop Nov 11, 2026
9 checks passed
@TheWitness
TheWitness deleted the refactor/editor-option-escaping branch November 11, 2026 01:40
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.

Editor option markup is built by string concatenation

4 participants