Skip to content

Fix XSS: stop reinterpreting DOM-derived text as HTML in debug badge#16

Merged
ArmandXiao merged 2 commits into
mainfrom
copilot/fix-code-scanning-alerts
Jul 22, 2026
Merged

Fix XSS: stop reinterpreting DOM-derived text as HTML in debug badge#16
ArmandXiao merged 2 commits into
mainfrom
copilot/fix-code-scanning-alerts

Conversation

Copilot AI commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

CodeQL alert #13 (js/xss-through-dom): sec.getAttribute("data-section") was interpolated into an HTML string and written to badge.innerHTML, allowing a controlled data-section attribute to inject arbitrary HTML/script.

Change

Replace the innerHTML string-building approach with safe DOM APIs throughout the section badge construction in methoddriven4.html:

// Before — DOM text flows unsanitized into innerHTML
let html = `${id}  ${Math.round(actual)}px`;
// ...
html += ` <span class="${cls}">est=${est} Δ${sign}${delta}</span>`;
badge.innerHTML = html;

// After — DOM APIs; text is never parsed as markup
badge.textContent = txt;          // plain-text portion
const span = document.createElement("span");
span.className = cls;
span.textContent = `est=${est} Δ${sign}${delta}`;
badge.appendChild(document.createTextNode(" "));
badge.appendChild(span);

Copilot AI changed the title [WIP] Fix code scanning alert #13 Fix XSS: stop reinterpreting DOM-derived text as HTML in debug badge Jul 20, 2026
Copilot AI requested a review from huangyangyu July 20, 2026 16:39
@ArmandXiao
ArmandXiao marked this pull request as ready for review July 22, 2026 06:00
@ArmandXiao
ArmandXiao merged commit 298ca64 into main Jul 22, 2026
4 checks passed
@ArmandXiao
ArmandXiao deleted the copilot/fix-code-scanning-alerts branch July 22, 2026 06:00
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.

3 participants