mirror of
https://github.com/JuliusBrussee/caveman.git
synced 2026-08-11 13:21:09 +02:00
fix(docs): escape user input in demo terminal (XSS)
Folds in #438 — the docs demo terminal interpolated user input via innerHTML (real reflected/DOM XSS); build nodes with textContent instead. (PR title 'CLI input handler' was a misnomer.) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
f68111acc3
commit
46de578a7e
+11
-1
@@ -417,7 +417,17 @@ cliInput.addEventListener('keydown', (e) => {
|
||||
const val = cliInput.value.trim();
|
||||
const row = document.createElement('div');
|
||||
row.className = 'term-line';
|
||||
row.innerHTML = `<span class="term-accent">❯</span> ${val}`;
|
||||
|
||||
// SECURITY FIX: Create DOM elements safely to prevent XSS
|
||||
const prompt = document.createElement('span');
|
||||
prompt.className = 'term-accent';
|
||||
prompt.textContent = '❯';
|
||||
|
||||
const commandText = document.createElement('span');
|
||||
commandText.textContent = ` ${val}`; // textContent automatically escapes HTML
|
||||
|
||||
row.appendChild(prompt);
|
||||
row.appendChild(commandText);
|
||||
cliInput.parentElement.before(row);
|
||||
|
||||
const res = document.createElement('div');
|
||||
|
||||
Reference in New Issue
Block a user