Skip to content

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

Draft
huangyangyu with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-code-scanning-alerts
Draft

Fix XSS: stop reinterpreting DOM-derived text as HTML in debug badge#16
huangyangyu with Copilot wants to merge 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
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