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(providers): redact wrapped base64 in shared generations
Emre Sokullu973345cf8e14
diff --git a/src/chrome/src/trace/webbrain-share-outbox.js b/src/chrome/src/trace/webbrain-share-outbox.jsindex fe616ef7c..975ba697d 100644--- a/src/chrome/src/trace/webbrain-share-outbox.js+++ b/src/chrome/src/trace/webbrain-share-outbox.js@@ -51,12 +51,12 @@ function scrubText(value, limit = MAX_MESSAGE_CHARS) {if (text.includes('"base64"')) {text = text.replace(/"base64"\s*:\s*"[A-Za-z0-9+/=\r\n]*"/g, '"base64":"[omitted]"');}- // Bare base64 blobs without a data: wrapper (e.g. read_downloaded_file- // serializes small binaries as {"base64":"..."} into string tool content).- // A 200+ run of base64 alphabet characters never occurs in prose, hashes,- // or URLs (delimiters break the run), so redact it from research copies.+ // Bare base64 blobs may wrap at MIME line boundaries. Count encoded+ // characters, including padding, so wrapping cannot bypass the threshold+ // and newlines alone cannot turn short text into a binary payload.if (/[A-Za-z0-9+/=\r\n]{200,}/.test(text)) {- text = text.replace(/[A-Za-z0-9+/]{200}[A-Za-z0-9+/=\r\n]*/g, '[embedded base64 data omitted]');+ text = text.replace(/[A-Za-z0-9+/=]+(?:[\r\n]+[A-Za-z0-9+/=]+)*/g, payload =>+ payload.replace(/[\r\n]/g, '').length >= 200 ? '[embedded base64 data omitted]' : payload);}return bounded(text, limit);}diff --git a/src/firefox/src/trace/webbrain-share-outbox.js b/src/firefox/src/trace/webbrain-share-outbox.jsindex fe616ef7c..975ba697d 100644--- a/src/firefox/src/trace/webbrain-share-outbox.js+++ b/src/firefox/src/trace/webbrain-share-outbox.js@@ -51,12 +51,12 @@ function scrubText(value, limit = MAX_MESSAGE_CHARS) {if (text.includes('"base64"')) {text = text.replace(/"base64"\s*:\s*"[A-Za-z0-9+/=\r\n]*"/g, '"base64":"[omitted]"');}- // Bare base64 blobs without a data: wrapper (e.g. read_downloaded_file- // serializes small binaries as {"base64":"..."} into string tool content).- // A 200+ run of base64 alphabet characters never occurs in prose, hashes,- // or URLs (delimiters break the run), so redact it from research copies.+ // Bare base64 blobs may wrap at MIME line boundaries. Count encoded+ // characters, including padding, so wrapping cannot bypass the threshold+ // and newlines alone cannot turn short text into a binary payload.if (/[A-Za-z0-9+/=\r\n]{200,}/.test(text)) {- text = text.replace(/[A-Za-z0-9+/]{200}[A-Za-z0-9+/=\r\n]*/g, '[embedded base64 data omitted]');+ text = text.replace(/[A-Za-z0-9+/=]+(?:[\r\n]+[A-Za-z0-9+/=]+)*/g, payload =>+ payload.replace(/[\r\n]/g, '').length >= 200 ? '[embedded base64 data omitted]' : payload);}return bounded(text, limit);}diff --git a/test/run.js b/test/run.jsindex 3df18654d..91ca6fd88 100644--- a/test/run.js+++ b/test/run.js@@ -12687,6 +12687,37 @@ test('Share-for-research scrubs serialized base64 fields at every payload length}});+test('Share-for-research scrubs wrapped bare base64 without counting line breaks toward the threshold', () => {+ for (const [label, outbox] of [['chrome', SHARE_OUTBOX_CH], ['firefox', SHARE_OUTBOX_FX]]) {+ for (const sizeBytes of [147, 148, 149, 150, 300]) {+ const base64 = Buffer.alloc(sizeBytes, 255).toString('base64');+ for (const newline of ['\n', '\r\n', '\r', '']) {+ const wrapped = base64.match(/.{1,76}/g).join(newline);+ const content = `file bytes: ${wrapped} trailing note`;+ const expected = base64.length >= 200 ? 'file bytes: [embedded base64 data omitted] trailing note' : content;+ const item = outbox.buildShareGenerationItem({+ finalContent: content,+ messages: [+ { role: 'tool', content },+ { role: 'tool', content: [content, { type: 'text', text: content }] },+ ],+ });+ const context = `${label}: ${sizeBytes} bytes, newline ${JSON.stringify(newline)}`;+ assert.equal(item.request[0].content, expected, context);+ assert.deepEqual(item.request[1].content, [expected, { type: 'text', text: expected }], context);+ assert.equal(item.response.content, expected, context);+ }+ }+ const shortLines = 'abc\r\n'.repeat(50);+ const item = outbox.buildShareGenerationItem({+ finalContent: shortLines,+ messages: [{ role: 'user', content: shortLines }],+ });+ assert.equal(item.request[0].content, shortLines, `${label}: short text lines were removed`);+ assert.equal(item.response.content, shortLines, `${label}: short response lines were removed`);+ }+});+test('Share-for-research caps count wrapper messages and serialized overhead', () => {const messages = [{ role: 'system', content: 'SYS' }];for (let i = 0; i < 250; i++) messages.push({ role: 'user', content: `cap${i}-` + 'word '.repeat(150) });