Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Keep scanning inside a rejected encoded-URL assignment value
garrytanfdf772fb6574
diff --git a/src/core/secret-scan.ts b/src/core/secret-scan.tsindex ea74b64eb1..0ea88cfa3d 100644--- a/src/core/secret-scan.ts+++ b/src/core/secret-scan.ts@@ -915,14 +915,20 @@ function scanInternal(text: string, opts: ScanOpts): RawHit[] {if (m[0].length === 0) p.re.lastIndex++;// The entropy gate judges the WHOLE matched value (the rule fired on// the assignment's value), before any overlap split.- if (p.entropyGated && (!HIGH_ENTROPY_REQUIRES_DIGIT_RE.test(value) || !HIGH_ENTROPY_REQUIRES_NON_DIGIT_RE.test(value))) continue;+ // A rejected assignment value resumes the scan at the value's start: an+ // encoded URL value (`token%3Dhttps%3A%2F%2F…`) can span a later+ // `password=` on the same line, which must still be found (#8265).+ if (p.entropyGated && (!HIGH_ENTROPY_REQUIRES_DIGIT_RE.test(value) || !HIGH_ENTROPY_REQUIRES_NON_DIGIT_RE.test(value))) { p.re.lastIndex = start; continue; }if (p.entropyGated) {- if (correctedEntropy(value, work) < HIGH_ENTROPY_MIN_BITS_PER_CHAR) continue;+ if (correctedEntropy(value, work) < HIGH_ENTROPY_MIN_BITS_PER_CHAR) { p.re.lastIndex = start; continue; }if (work) work.gatePassed++;}if (p.validate) {if (work) work.validateCalls++;- if (!p.validate(value, subject === line ? m[1] : line.slice(m.index, start))) continue;+ if (!p.validate(value, subject === line ? m[1] : line.slice(m.index, start))) {+ if (p.entropyGated) p.re.lastIndex = start;+ continue;+ }}if (!taken) {taken = new Uint8Array(line.length);diff --git a/test/secret-scan-encoded-assignment-8265.test.ts b/test/secret-scan-encoded-assignment-8265.test.tsindex 10b61a38b1..3ae1788a88 100644--- a/test/secret-scan-encoded-assignment-8265.test.ts+++ b/test/secret-scan-encoded-assignment-8265.test.ts@@ -66,6 +66,12 @@ describe('#8265 URL-encoded separators', () => {expect(redactFindings(`client_secret%3D${v}%26x%3D1`, OPTS).text).toBe(`client_secret%3D${MARK}%26x%3D1`);});+ test('a secret key later in a URL-encoded URL value the scan rejects is still claimed', () => {+ const v = secret();+ const line = `token%3Dhttps%3A%2F%2Fexample.org%2Fcb?password=${v}`;+ expect(redactFindings(line, OPTS).text).toBe(`token%3Dhttps%3A%2F%2Fexample.org%2Fcb?password=${MARK}`);+ });+test('a URL-encoded URL that carries userinfo is still claimed', () => {const v = secret();expect(found(`password=postgres%3A%2F%2Fu%3A${v}%40db.example%2Fapp`)).toContain('high_entropy_assignment');