The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
fix(browser-extension): scrub emails in linear time (#1003)
kyle-elliott-asymptote88479497caff
diff --git a/browser-extension/src/shared/normalize.ts b/browser-extension/src/shared/normalize.tsindex f7f3a191..b3f457ac 100644--- a/browser-extension/src/shared/normalize.ts+++ b/browser-extension/src/shared/normalize.ts@@ -59,7 +59,9 @@ function capBytes(text: string, max = MAX_FIELD_BYTES, size = utf8Bytes): [strin* collector also redacts). Masks emails and long token-like strings. */function scrub(text: string): string {return text- .replace(/[\w.+-]+@[\w-]+\.[\w.-]+/g, '[email]')+ // The lookbehind starts a match only where a run of these characters begins; without it, a+ // long run with no '@' (a base64 blob, say) is rescanned from every position, quadratically.+ .replace(/(?<![\w.+-])[\w.+-]+@[\w-]+\.[\w.-]+/g, '[email]').replace(/\b(sk|pk|ghp|xox[baprs]|AKIA)[A-Za-z0-9_-]{12,}\b/g, '[token]');}diff --git a/browser-extension/test/unit/normalize.test.ts b/browser-extension/test/unit/normalize.test.tsindex ebb4b9dc..6cc0ddd2 100644--- a/browser-extension/test/unit/normalize.test.ts+++ b/browser-extension/test/unit/normalize.test.ts@@ -204,6 +204,15 @@ describe('normalizeTurn — retention modes', () => {expect(p['beacon.prompt.text']).toBe('email me at [email] please');expect(p['beacon.content.retention']).toBe('redacted');});++ // A long run of word characters with no '@', such as a base64 blob, made the email pattern+ // rescan from every position: about 2s for 64 KB, growing with the square of the length.+ it('redacted retention scrubs a long token-like run in linear time', () => {+ const turn = baseTurn({ promptText: 'x'.repeat(1 << 20) });+ const started = performance.now();+ normalize(turn, 'redacted');+ expect(performance.now() - started).toBeLessThan(1000);+ });});describe('normalizeTurn — tool calls', () => {