Skip to content

security: fix CodeQL js/xss-through-dom findings [CTO-4840/4841/4842/4843]#302

Open
tech-sushant wants to merge 1 commit into
mainfrom
security/codeql-xss-through-dom-fixes
Open

security: fix CodeQL js/xss-through-dom findings [CTO-4840/4841/4842/4843]#302
tech-sushant wants to merge 1 commit into
mainfrom
security/codeql-xss-through-dom-fixes

Conversation

@tech-sushant
Copy link
Copy Markdown

@tech-sushant tech-sushant commented May 19, 2026

Summary

Closes 4 CodeQL XSS findings raised today (2026-05-19), all of rule `js/xss-through-dom`:

Ticket File Line CodeQL
CTO-4840 `templates/global_layout.html` 256 #79
CTO-4841 `templates/global_layout.html` 234 #78
CTO-4842 `templates/EnigmaOps/allUserAccessList.html` 141 #77
CTO-4843 `static/files/js/front.js` 141 #76

What changed

`templates/global_layout.html` (CTO-4840, CTO-4841)

Two `` patterns. Replaced with a helper that only navigates if the value is a same-origin relative path (starts with `/` but not `//`). Blocks `javascript:`/`data:` URIs and off-origin redirects.

`templates/EnigmaOps/allUserAccessList.html` (CTO-4842)

`title_line.html(title_html)` was being fed strings concatenated from the JS `access_type` variable. Rebuilt the title with jQuery element-creation APIs (`.text()` instead of `.html()`) so `access_type` is treated as text. Used `{{username|escapejs}}` to safely embed the Django value in the JS literal.

`static/files/js/front.js` (CTO-4843)

`$("#colour").change()` concatenated `$(this).val()` into a CSS path and assigned to a ``. Added a regex allowlist (`^[a-zA-Z0-9_-]+$`) on the theme name before any assignment — blocks tampered values pointing to off-origin stylesheets or `javascript:` URIs.

Why this approach

Each is a small, surgical, OSS-friendly fix — no monkey-patches, no environment flags, no surprises for downstream forks. CodeQL alerts close because the data no longer flows from text into an HTML/navigation sink.

Test plan

🤖 Generated with Claude Code

…4843]

Four CodeQL alerts for the same rule (js/xss-through-dom) flagged on
2026-05-19. Each location takes DOM-derived text and routes it into a
sink that interprets it as HTML or as a navigation target. None of
these are remote-exploitable in normal flow — the source values come
from server-rendered Django templates — but a tampered <option value>
or a malicious group name flowing through the URL builder can
escalate to script execution. Cheap fixes, low risk.

templates/global_layout.html  (CTO-4840, CTO-4841)
  Two <button onclick="javascript:location.href=document.getElementById(...).value">
  patterns. Replaced with a helper navigateToSelectedGroup(selectId)
  that only navigates if the value is a same-origin relative path
  (starts with `/` but not `//`). Blocks `javascript:`/`data:` URIs
  and off-origin redirects.

templates/EnigmaOps/allUserAccessList.html  (CTO-4842)
  title_line.html(title_html) was being fed strings concatenated from
  the JS variable `access_type`. Rebuilt the same title with jQuery
  element construction APIs (.text() instead of .html()) so
  access_type and the username are treated as text, not HTML. Used
  {{username|escapejs}} to safely embed the Django value in the JS
  literal.

static/files/js/front.js  (CTO-4843)
  $("#colour").change() concatenated $(this).val() into a CSS path
  that was then assigned to a <link href>. A tampered <option value>
  could swap the stylesheet for an off-origin URL. Added a regex
  allowlist (`^[a-zA-Z0-9_-]+$`) on the theme name before assignment.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
function navigateToSelectedGroup(selectId) {
var url = document.getElementById(selectId).value;
if (typeof url === 'string' && url.length > 1 && url.charAt(0) === '/' && url.charAt(1) !== '/') {
window.location.assign(url);
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