Skip to content

fix(ui): escape rule and device data rendered into HTML - #10

Merged
Mo3he merged 2 commits into
mainfrom
fix/ui-escaping
Oct 6, 2026
Merged

Mo3he merged 2 commits into
mainfrom
fix/ui-escaping

Conversation

@Mo3he

@Mo3he Mo3he commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Fixes the 3 open CodeQL js/xss-through-dom alerts and the wider issue behind them.

Problem: an imported rule (backup, shared template) keeps its own id, and per-field values such as port or scenario_id are not type-checked server-side. Those values were inserted into HTML unescaped, so a crafted rule file could run script in the admin's browser:

  • in the rules list (rule id inside onclick="editRule('...')"), on page load;
  • in the rule editor (~70 numeric/ID fields, plus scenario IDs and PTZ channels from local/remote devices).

Fix:

  • Every data-derived value now goes through escHtml(); fixed labels are unchanged.
  • JS handler arguments use new escJsArg() (JSON-quoted, then HTML-escaped).
  • escHtml() also escapes '.
  • settings.js: removed a stray escHtml on a textContent assignment (showed &).
  • Cache-busters bumped for the changed scripts.

Tested on camera 155 (P3288-LV, OS 12.11):

  • Imported a booby-trapped rule (payload in id, trigger port, action seconds): rules list and editor render it as text, no script ran, nothing injected.
  • All 56 trigger/condition/action forms render with zero JS errors, incl. 21 remote-device variants.
  • Edit+save of existing rules leaves them unchanged; values with " ' & < > \\ round-trip byte-identical.
  • Camera restored to signed 1.9.16 with rules/settings identical to the pre-test backup.

Mo3he added 2 commits October 6, 2026 16:41
Imported rules keep their own id and per-field values are not type-checked
server-side, so a crafted backup/template could inject markup into the rule
list (onclick handlers) and the rule editor. Escape every data-derived value,
pass JS handler arguments via escJsArg (JSON-quoted), and make escHtml also
escape single quotes.
escHtml does not protect a JS string inside an on* attribute: the browser
decodes &#39; back to ' before running the handler.
@Mo3he
Mo3he merged commit 3fbbc48 into main Oct 6, 2026
19 checks passed
@Mo3he
Mo3he deleted the fix/ui-escaping branch October 6, 2026 15:06
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