Skip to content

Commit d2480db

Browse files
bcordisclaude
andcommitted
fix: resolve CodeQL high-severity XSS and sanitization findings
message-wizard.es6.js: Replace innerHTML-based HTML stripping with DOMParser which safely parses without script execution. cwm-transcript.es6.js: Loop regex tag stripping until stable to handle malformed/nested tags like <scr<b>ipt> that bypass single-pass removal. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 454f159 commit d2480db

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

build/media_source/js/cwm-transcript.es6.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,15 @@
8585
const start = parseVttTime(tsParts[0]);
8686
const end = parseVttTime(endRaw);
8787

88-
// Text is everything after the timestamp line, strip VTT tags
89-
const text = lines.slice(tsIndex + 1).join(' ')
90-
.replace(/<[^>]+>/g, '')
91-
.trim();
88+
// Text is everything after the timestamp line, strip VTT tags.
89+
// Loop until stable to handle malformed/nested tags like <scr<b>ipt>.
90+
let text = lines.slice(tsIndex + 1).join(' ');
91+
let prev;
92+
do {
93+
prev = text;
94+
text = text.replace(/<[^>]+>/g, '');
95+
} while (text !== prev);
96+
text = text.trim();
9297

9398
if (text) {
9499
cues.push({ start, end, text });

build/media_source/js/message-wizard.es6.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,9 @@ document.addEventListener('DOMContentLoaded', () => {
181181
introText = getValue('jform_studyintro');
182182
}
183183

184-
// Strip HTML for preview
185-
const tempDiv = document.createElement('div');
186-
tempDiv.innerHTML = introText;
187-
const introPreview = (tempDiv.textContent || '').substring(0, 200);
184+
// Strip HTML for preview (DOMParser is safe — no script execution)
185+
const parsed = new DOMParser().parseFromString(introText, 'text/html');
186+
const introPreview = (parsed.body.textContent || '').substring(0, 200);
188187

189188
const escHtml = (str) => {
190189
const d = document.createElement('div');

0 commit comments

Comments
 (0)