Open-source AI browser agent for Chrome and Firefox (monorepo) ðŸ§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
fix: reject non-CDATA markup in XML param values to resolve CodeQL HTML injection
Barack Sokullu38f396a39104
diff --git a/src/chrome/src/agent/tool-call-parser.js b/src/chrome/src/agent/tool-call-parser.jsindex 2e763e325..891de98a7 100644--- a/src/chrome/src/agent/tool-call-parser.js+++ b/src/chrome/src/agent/tool-call-parser.js@@ -363,15 +363,14 @@ export function parseToolCallsFromText(text, allowedNames) {const parseXmlParamValue = (value) => {const raw = String(value || '');// MiniCPM5 wraps values containing <, &, or newlines in CDATA. Extract- // the literal content first so the tag strip below does not eat it.+ // the literal content first so markup below does not corrupt it.const cdataMatch = /^\s*<!\[CDATA\[([\s\S]*?)\]\]>\s*$/.exec(raw);if (cdataMatch) return cdataMatch[1];- const cleaned = raw- .replace(/<[^>]*>/g, '')- // Strip any leftover "<" so a malformed tag without ">" (e.g. "<script")- // cannot survive sanitization and cause HTML injection downstream.- .replace(/</g, '')- .trim();+ // Non-CDATA values must not contain markup: the spec requires CDATA for+ // "<", "&", or newlines. Reject markup outright instead of stripping tags,+ // which leaves "<script" without ">" and risks HTML injection downstream.+ if (raw.includes('<') || raw.includes('>')) return '';+ const cleaned = raw.trim();if (!cleaned) return '';try {if (/^(?:"|'.*'|\{|\[|-?\d|true\b|false\b|null\b)/i.test(cleaned)) {diff --git a/src/firefox/src/agent/tool-call-parser.js b/src/firefox/src/agent/tool-call-parser.jsindex 2e763e325..891de98a7 100644--- a/src/firefox/src/agent/tool-call-parser.js+++ b/src/firefox/src/agent/tool-call-parser.js@@ -363,15 +363,14 @@ export function parseToolCallsFromText(text, allowedNames) {const parseXmlParamValue = (value) => {const raw = String(value || '');// MiniCPM5 wraps values containing <, &, or newlines in CDATA. Extract- // the literal content first so the tag strip below does not eat it.+ // the literal content first so markup below does not corrupt it.const cdataMatch = /^\s*<!\[CDATA\[([\s\S]*?)\]\]>\s*$/.exec(raw);if (cdataMatch) return cdataMatch[1];- const cleaned = raw- .replace(/<[^>]*>/g, '')- // Strip any leftover "<" so a malformed tag without ">" (e.g. "<script")- // cannot survive sanitization and cause HTML injection downstream.- .replace(/</g, '')- .trim();+ // Non-CDATA values must not contain markup: the spec requires CDATA for+ // "<", "&", or newlines. Reject markup outright instead of stripping tags,+ // which leaves "<script" without ">" and risks HTML injection downstream.+ if (raw.includes('<') || raw.includes('>')) return '';+ const cleaned = raw.trim();if (!cleaned) return '';try {if (/^(?:"|'.*'|\{|\[|-?\d|true\b|false\b|null\b)/i.test(cleaned)) {diff --git a/test/run.js b/test/run.jsindex d0686339e..b80acef2f 100644--- a/test/run.js+++ b/test/run.js@@ -100538,8 +100538,8 @@ test('text tool-call parser is production code with format and allowlist coveragconst parserSource = fs.readFileSync(path.join(ROOT, 'src/chrome/src/agent/tool-call-parser.js'), 'utf8');assert.match(parserSource, /orderedCalls/,'mixed XML call formats must preserve source order when dispatching');- assert.match(parserSource, /\.replace\(\/<\/g/,- 'param sanitization must strip leftover angle brackets so CodeQL sees no HTML injection');+ assert.doesNotMatch(parserSource, /replace\(\/<\[\^>\]/,+ 'param values must reject markup outright instead of incomplete tag-stripping');const allowed = new Set(['click', 'click_ax', 'navigate', 'read_page', 'scroll']);const cases = [{@@ -100751,10 +100751,10 @@ test('text tool-call parser is production code with format and allowlist coverag],},{- label: 'MiniCPM5 param value strips incomplete script tag',+ label: 'MiniCPM5 param value rejects markup outside CDATA',raw: '<function name="click_ax"><param name="ref_id">ref_7<script</param></function>',expected: [- { name: 'click_ax', args: { ref_id: 'ref_7script' } },+ { name: 'click_ax', args: { ref_id: '' } },],},{