Use Garry Tan's exact Claude Code setup: 23 opinionated tools that serve as CEO, Designer, Eng Manager, Release Manager, Doc Engineer, and QA
TypeScript
Secrets check catches Google keys in encoded text, reads later declarators and reports provider keys once (GST-4104) (#4871)
Garry Tand785fc4acf1a
diff --git a/changelog.d/secrets-check-fixes-four-edge-cases.md b/changelog.d/secrets-check-fixes-four-edge-cases.mdnew file mode 100644index 000000000..83bbcb235--- /dev/null+++ b/changelog.d/secrets-check-fixes-four-edge-cases.md@@ -0,0 +1,4 @@+---+important: security+---+**The secrets check catches more Google API keys in encoded text, reads each JavaScript and TypeScript declaration under its own name, reports a provider key once, and stops matching look-alike values against your environment's secrets.** A Google API key inside a long block of base64 text is now reported when its characters show it can't be part of that block. In a line that declares several names, a key is checked under the name it is assigned to, so a hash after a secret-named variable no longer reads as that secret, and a key assigned to a secret-named variable that follows names declared without a value is now caught. A provider key in a `const` (such as a public Firebase key) now reports only under its provider's rule, so allowlisting that rule clears it. A value that differs from one of your environment's secrets by one character no longer matches that secret's base64 form, while the secret's own base64 form still reports. (GST-4104)diff --git a/lib/redact-engine.ts b/lib/redact-engine.tsindex 22838520d..10e268e15 100644--- a/lib/redact-engine.ts+++ b/lib/redact-engine.ts@@ -403,6 +403,13 @@ function scanInternal(input: string, opts: ScanOptions, spans?: Map<Finding, Oriconst findings: Finding[] = [];// Dedup by (id, original-offset) so overlapping global matches don't double-count.const seen = new Set<string>();+ // GST-4104: the spans of secret findings from rules other than env.kv*, so a+ // declaration rule (env.kv.js, env.kv.go) whose whole literal is exactly one+ // of them stays quiet: a provider key in `const apiKey = "<key>"` reports as+ // its provider rule alone, and allowlisting that rule clears it, while a+ // literal that holds more (`"<key>" + "<other>"`) keeps the declaration+ // finding. Every provider rule comes before the declaration rules in PATTERNS.+ const covered = new Set<string>();for (const pat of PATTERNS) {const re = new RegExp(pat.regex.source, withFlags(pat.regex.flags));@@ -433,10 +440,17 @@ function scanInternal(input: string, opts: ScanOptions, spans?: Map<Finding, Oriif (pat.id === "pii.email" && emailAllowed(span, opts, normalized, normOffset))continue;+ if (DECLARATION_RULES.has(pat.id) && covered.has(`${normOffset}:${span.length}`)) {+ const quote = normalized[normOffset - 1];+ const rest = normalized.slice(normOffset + span.length, normOffset + span.length + 80);+ if ((quote === '"' || quote === "'" || quote === "\x60") && rest[0] === quote && !/^.[ \t]*\+/.test(rest)) continue;+ }+const origOffset = map[Math.min(normOffset, map.length - 1)] ?? 0;const key = `${pat.id}:${origOffset}`;if (seen.has(key)) continue;seen.add(key);+ if (pat.category === "secret" && !pat.id.startsWith("env.kv")) covered.add(`${normOffset}:${span.length}`);starts ??= lineStarts(input);const { line, col } = lineColAt(starts, input, origOffset);@@ -485,10 +499,24 @@ function scanInternal(input: string, opts: ScanOptions, spans?: Map<Finding, Ori// and the allowlist and placeholder rules see both forms.const value = normalizeOriginal(raw).normalized;if (allow.has(raw) || allow.has(value) || value.length < MIN_ENV_VALUE_LENGTH || isPlaceholderSpan(value)) continue;- for (const form of new Set([value, ...base64Forms(value), ...base64Forms(raw)])) {+ for (const { form, encoded, before, after } of [{ form: value, encoded: false }, ...base64Encodings(value), ...base64Encodings(raw)]) {+ // GST-4104: a base64 form leaves out the characters it shares with+ // neighbouring bytes, so the characters beside a match must carry the+ // value's bits there too; a value that differs only in those bits+ // (`build124` for `build123`) is not this secret. Either alphabet's+ // symbol reads as its index, since a form without symbols is the same+ // text in both.+ const fits = (c: string | undefined, edge?: Base64Edge) => {+ const index = c === undefined ? -1 : Math.max(BASE64_STANDARD.indexOf(c), BASE64_URL.indexOf(c));+ return !edge || index < 0 || (index & edge.mask) === edge.bits;+ };let from = 0;let normOffset: number;while ((normOffset = normalized.indexOf(form, from)) !== -1) {+ if (!fits(normalized[normOffset - 1], before) || !fits(normalized[normOffset + form.length], after)) {+ from = normOffset + 1;+ continue;+ }from = normOffset + form.length;const origOffset = map[Math.min(normOffset, map.length - 1)] ?? 0;// Keyed on the span, not the offset alone: when one credential's value is@@ -503,7 +531,7 @@ function scanInternal(input: string, opts: ScanOptions, spans?: Map<Finding, Oritier: "HIGH",severity: "HIGH",category: "secret",- description: `Value of the ${name} environment variable${form === value ? "" : ", base64-encoded"}`,+ description: `Value of the ${name} environment variable${encoded ? ", base64-encoded" : ""}`,line,col,// A live credential: the name already says what leaked; show no bytes.@@ -535,6 +563,7 @@ const PUBLIC_ENV_NAME = /(^|_)PUBLIC(_|$)/i;/** gstack's own credential-named variables whose values are not secrets (bin/gstack-brain-lock.sh sets the lock token). */export const NON_SECRET_ENV_NAMES: ReadonlySet<string> = new Set(["GSTACK_BRAIN_LOCK_TOKEN"]);const MIN_ENV_VALUE_LENGTH = 8;+const DECLARATION_RULES = new Set(["env.kv.js", "env.kv.go"]);/*** The (name, value) pairs of `env` worth scanning for by value: credential-named@@ -559,19 +588,35 @@ const MIN_ENV_VALUE_LENGTH = 8;* bytes and drops the characters that also carry bits of a neighbouring byte:* 0, 2 or 3 at the front, and the last one when the value does not end on a* 3-byte boundary. Forms shorter than the minimum value length are dropped.+ * GST-4104: each form keeps the value's bits in the character dropped at each+ * end (the low 4 or 2 bits of the one before it, the high 2 or 4 bits of the+ * one after it), which scan checks against the text.*/const BASE64_LEAD = [0, 2, 3];-export function base64Forms(value: string): string[] {+const BASE64_LEAD_BITS = [0, 4, 2];+const BASE64_TAIL_BITS = [0, 2, 4];+const BASE64_STANDARD = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";+const BASE64_URL = BASE64_STANDARD.slice(0, 62) + "-_";+interface Base64Edge { mask: number; bits: number }+function base64Encodings(value: string): Array<{ form: string; encoded: true; before?: Base64Edge; after?: Base64Edge }> {const bytes = Buffer.from(value, "utf8");- const forms = new Set<string>();+ const out: Array<{ form: string; encoded: true; before?: Base64Edge; after?: Base64Edge }> = [];for (const [shift, lead] of BASE64_LEAD.entries()) {const encoded = Buffer.concat([Buffer.alloc(shift), bytes]).toString("base64").replace(/=+$/, "");- const core = encoded.slice(lead, encoded.length - ((shift + bytes.length) % 3 === 0 ? 0 : 1));+ const leadBits = BASE64_LEAD_BITS[shift]!;+ const tailBits = BASE64_TAIL_BITS[(shift + bytes.length) % 3]!;+ const core = encoded.slice(lead, encoded.length - (tailBits ? 1 : 0));if (core.length < MIN_ENV_VALUE_LENGTH) continue;- forms.add(core);- forms.add(core.replace(/\+/g, "-").replace(/\//g, "_"));+ const edge = (c: string, mask: number) => ({ mask, bits: BASE64_STANDARD.indexOf(c) & mask });+ const before = leadBits ? edge(encoded[lead - 1]!, (1 << leadBits) - 1) : undefined;+ const after = tailBits ? edge(encoded[encoded.length - 1]!, ((1 << tailBits) - 1) << (6 - tailBits)) : undefined;+ out.push({ form: core, encoded: true, before, after });+ out.push({ form: core.replace(/\+/g, "-").replace(/\//g, "_"), encoded: true, before, after });}- return [...forms];+ return out;+}+export function base64Forms(value: string): string[] {+ return [...new Set(base64Encodings(value).map(({ form }) => form))];}export function credentialEnvValues(env: Record<string, string | undefined>): Array<{ name: string; value: string }> {diff --git a/lib/redact-patterns.ts b/lib/redact-patterns.tsindex dc78ae0ef..ba06396f4 100644--- a/lib/redact-patterns.ts+++ b/lib/redact-patterns.ts@@ -251,8 +251,10 @@ export function looksLikeRunStamp(span: string): boolean {* `AQ.`) cannot occur by chance and always reports. A match is chance when it* starts at least 64 characters into a run of 200 or more characters of one* alphabet (standard `+` and `/` for `AIza`, url-safe `-` and `_` for- * `sk-`), the 64 or more characters before it hold an uppercase letter, a- * lowercase letter and a digit with no `=` (padding only ends a run), and at+ * `sk-`) that the match itself belongs to (GST-4104: an `AIza` key holding+ * `-` or `_` is never chance in standard base64), the 64 or more+ * characters before it hold an uppercase letter, a lowercase letter and a+ * digit with no `=` (padding only ends a run), and at* most one in 16 of them is a `+`, `/`, `-` or `_`, so a path or a long* name (`MY_LONG_SERVICE_..._KEY_V2=`, `/v1/Projects/Abc123/...`) never* qualifies. A known secret's exact value, base64 forms included, is found by@@ -267,6 +269,7 @@ function chanceMatchInBase64(match: RegExpExecArray): boolean {const { start, end } = spanBounds(match);const text = match.input;const alphabet = text.startsWith("sk-", start) ? BASE64_URL : BASE64_STANDARD;+ for (let i = start; i < end; i++) if (!alphabet.test(text[i]!)) return false;let before = 0;while (before < BASE64_RUN_MIN && start - before > 0 && alphabet.test(text[start - before - 1]!)) before++;if (before < BASE64_DEPTH_MIN) return false;@@ -1334,6 +1337,32 @@ function declaredLiteralIsSecret(span: string, match: RegExpExecArray): booleanreturn literal.split(/\s+/).some(isSecretShapedValue);}+/**+ * GST-4104: the name env.kv.js binds, read from the text before the+ * declaration's `=`: the last declarator after a comma outside brackets,+ * quotes and block comments, then the last word before its type's `:`. The type reads up to the+ * `=`, so `let token: string, buildHash =` names `buildHash` (the value is+ * not the token's), while `Brand<string, "key">` stays one type.+ */+function declaredName(head: string): string | undefined {+ let from = 0;+ for (let i = 0, depth = 0; i < head.length; i++) {+ const c = head[i]!;+ if (c === '"' || c === "'" || c === "\x60") {+ const close = head.indexOf(c, i + 1);+ if (close < 0) break;+ i = close;+ } else if (c === "/" && head[i + 1] === "*") {+ const close = head.indexOf("*/", i + 2);+ if (close < 0) break;+ i = close + 1;+ } else if ("<([{".includes(c)) depth++;+ else if (">)]}".includes(c)) depth--;+ else if (c === "," && depth === 0) from = i + 1;+ }+ return /([$\w]+)[?!]?[ \t]*$/.exec(head.slice(from).split(":", 1)[0]!)?.[1]?.replace(/\$/g, "");+}+/*** GBRA-108: in a .json, .json5, .jsonc or .jsonl file, a field named exactly `"key"` whose value is a short* lowercase path of words (`"key": "sources/vector-index"`,@@ -1992,8 +2021,10 @@ export const PATTERNS: RedactPattern[] = [// "<key>";`) gave no finding. This rule reads one to four of `declare`,// `public`, `private`, `protected`, `static`, `readonly`, `override`,// `accessor`, `const`, `let` and `var` (after an optional `export`),- // an optional `#` private name, a secret-named name with an optional- // `?`/`!` and type (which stops at `;`, so the value belongs to the same+ // up to four earlier declarators without a value (`let a: string, token+ // = "<key>"`; GST-4104; each type ends on a non-space so spaces before a+ // comma have one reading), an optional `#` private name, a secret-named+ // name with an optional `?`/`!` and type (which stops at `;`, so the value belongs to the same// declaration), then `=` and a quoted or template literal (an empty// first piece of a `+` chain and leading spaces are read past), at a line// start (diff markers as env.kv) or after `//` or `/*`. A name with no@@ -2004,10 +2035,10 @@ export const PATTERNS: RedactPattern[] = [// exemptions. It is its own pattern so env.kv's matches are unchanged,// and validate keeps it to .js, .jsx, .ts, .tsx, .mjs, .cjs, .mts and .cts// files; a scan without a path is env.kv.rust's.- regex: /(?:^(?:[ +-]?\+|[ +-]?-(?! [^ \t]))?|(?<=(?:^|[ \t])(?:\/{2,3}|\/\*{1,2})))[ \t]*(?:export[ \t]+)?(?:(?:declare|public|private|protected|static|readonly|override|accessor|const|let|var)[ \t]+){1,4}#?[$\w]*(?:KEY|TOKEN|SECRET|PASSWORD|PASSWD|CREDENTIALS?|DSN|AUTH|COOKIE|SESSION|PRIVATE)[?!]?(?:[ \t]*:[^=;\n]{1,120}?)?[ \t]*=[ \t]*["'\x60]((?:["'\x60][ \t]*\+[ \t]*["'\x60]|[ \t]+)?[^\s'"\x60\\]{8,}|[^\s'"\x60\\]{1,7}(?=["'\x60]?[ \t]*\+))/i,+ regex: /(?:^(?:[ +-]?\+|[ +-]?-(?! [^ \t]))?|(?<=(?:^|[ \t])(?:\/{2,3}|\/\*{1,2})))[ \t]*(?:export[ \t]+)?(?:(?:declare|public|private|protected|static|readonly|override|accessor|const|let|var)[ \t]+){1,4}(?:[$\w]+[?!]?(?:[ \t]*:[^=;,\n]{0,119}[^=;,\s])?[ \t]*,[ \t]*){0,4}#?[$\w]*(?:KEY|TOKEN|SECRET|PASSWORD|PASSWD|CREDENTIALS?|DSN|AUTH|COOKIE|SESSION|PRIVATE)[?!]?(?:[ \t]*:[^=;\n]{1,120}?)?[ \t]*=[ \t]*["'\x60]((?:["'\x60][ \t]*\+[ \t]*["'\x60]|[ \t]+)?[^\s'"\x60\\]{8,}|[^\s'"\x60\\]{1,7}(?=["'\x60]?[ \t]*\+))/i,validate: (span, match, opts) => {if (!opts?.sourcePath || !JS_SOURCE.test(opts.sourcePath)) return false;- const name = /([$\w]+)[?!]?[ \t]*(?::[^=;\n]*)?=/.exec(match[0])?.[1]?.replace(/\$/g, "");+ const name = declaredName(match[0].slice(0, match[0].indexOf("=")));return !!name && isCredentialShapedEnvName(`${name}=`) && declaredLiteralIsSecret(span, match);},},diff --git a/test/redact-scanner-edge-cases.test.ts b/test/redact-scanner-edge-cases.test.tsnew file mode 100644index 000000000..29182ea52--- /dev/null+++ b/test/redact-scanner-edge-cases.test.ts@@ -0,0 +1,143 @@+/**+ * GST-4104: four edge cases left open on #4869's secrets-scan redesign.+ *+ * - An `AIza…` key holding `_` or `-` cannot be part of a standard+ * base64 run, so it is never dismissed as a chance match inside one.+ * - env.kv.js reads the declarator its `=` belongs to: a typed earlier+ * declarator no longer lends its name to a later one, and a secret-named+ * later declarator now reports.+ * - A provider key bound by a JS/TS or Go declaration reports as its+ * provider rule alone, so allowlisting that rule clears it.+ * - A known secret's base64 form is matched with its boundary characters'+ * bits, so a value that differs only in those bits is not reported.+ */+// Value: protects=AIza keys with url-safe characters in base64 runs, later declarators, provider-rule allowlists and exact base64 matching of env values; fails_when=an AIza key with _ or - is dismissed as chance, a typed earlier declarator's name flags a later value, a provider key also reports env.kv.js or env.kv.go, or a value one bit away matches a secret's base64 form; why_new=GST-4104 had no cases; seam=none; no_claim=scanner-level only+import { describe, expect, test } from "bun:test";+import { scan } from "../lib/redact-engine";+import { applyAllowlist } from "../lib/pregate/allowlist";++const ids = (text: string, sourcePath?: string, processEnv: Record<string, string> = {}) =>+ scan(text, { repoVisibility: "private", processEnv, ...(sourcePath ? { sourcePath } : {}) }).findings.map((f) => f.id);+const j = (...parts: string[]) => parts.join("");+const S = j("Qx9vL2mZ", "p8Rt4Kw7", "Yn3Bh2Jd");+const HEX = j("9f8e7d6c5b4a3928", "1706f5e4d3c2b1a0");+const GHP = j("ghp_", "a1B2c3D4e5F6g7H8i9J0", "k1L2m3N4o5P6q7R8");+const AIZA = j("AIza", "SyA1b2C3d4E5f6G7h8I9j0K1l2M3n4O5p6Q");+const filler = (n: number, seed: number) => Buffer.from(Array.from({ length: n }, (_, i) => (i * 37 + seed * 11 + 5) % 256));++describe("google.api_key: a key with url-safe characters is never chance inside standard base64", () => {+ const BLOB = filler(240, 3).toString("base64");+ const inside = (key: string, at: number) => "data:image/png;base64," + BLOB.slice(0, at) + "/" + key + "/" + BLOB.slice(at);++ test("an AIza key holding _ or - after 64+ mixed-case standard base64 characters reports", () => {+ for (const key of [j("AIza", "SyA1b2C3d4E5f6G7h8I9j0K1l2M3n4O5_6Q"), j("AIza", "SyA1b2C3d4-5f6G7h8I9j0K1l2M3n4O5p6Q"), j("AIza", "Sy_1b2C3d4E5f6G7h8I9j0K1l2M3n4O-p6Q")])+ for (const at of [64, 100, 160]) expect({ key, at, hit: ids(inside(key, at)).includes("google.api_key") }).toEqual({ key, at, hit: true });+ });++ test("an AIza match made only of standard base64 characters deep in the run stays chance", () => {+ for (const at of [64, 100, 160]) expect({ at, hit: ids(inside(AIZA, at)).includes("google.api_key") }).toEqual({ at, hit: false });+ });+});++describe("env.kv.js: the name is the declarator the = belongs to", () => {+ test("a typed earlier declarator does not name a later value", () => {+ for (const code of ['let token: string, buildHash = "' + HEX + '";', 'let apiKey: string | undefined, cacheId = "' + S + '";', 'var secret: Map<string, number>, build = "' + HEX + '";'])+ expect({ code, hit: ids(code, "src/build.ts").includes("env.kv.js") }).toEqual({ code, hit: false });+ });++ test("a secret-named later declarator reports, and a type with a comma inside brackets still reports", () => {+ for (const code of ['let a: string, token = "' + S + '";', 'let a, b: number, apiKey = "' + HEX + '";', 'const apiToken: Brand<string, "token"> = "' + S + '";', 'let token: string = "' + S + '", other = 1;'])+ expect({ code, hit: ids(code, "src/client.ts").includes("env.kv.js") }).toEqual({ code, hit: true });+ });+});++describe("declaration rules leave a provider key to its provider rule", () => {+ test("a provider key in a JS/TS or Go declaration reports only the provider rule, so allowlisting it clears the line", () => {+ for (const [code, file, id] of [+ ['const apiKey = "' + AIZA + '";', "src/firebase.ts", "google.api_key"],+ ["export const firebaseApiKey: string = '" + AIZA + "';", "src/firebase.mts", "google.api_key"],+ ['const token = "' + GHP + '";', "src/client.js", "github.pat"],+ ['apiKey := "' + AIZA + '"', "cmd/firebase.go", "google.api_key"],+ ] as const) {+ const found = ids(code, file);+ expect({ code, found }).toEqual({ code, found: [id] });+ expect({ code, left: found.filter((f) => f !== id) }).toEqual({ code, left: [] });+ }+ });++ test("a secret-shaped value with no provider rule, or more than the provider key, still reports the declaration rule", () => {+ expect(ids('const token = "' + S + '";', "src/client.ts")).toEqual(["env.kv.js"]);+ expect(ids('token := "' + HEX + '"', "cmd/client.go")).toEqual(["env.kv.go"]);+ expect(ids('const token = "' + AIZA + ":" + S + '";', "src/client.ts").sort()).toEqual(["env.kv.js", "google.api_key"]);+ });+});++describe("env.value: a base64 form matches only the secret's exact bits", () => {+ const env = { BUILD_TOKEN: "build123" };+ const stream = (value: string, shift: number, tail: number) => Buffer.concat([filler(30 + shift, shift), Buffer.from(value), filler(tail, 7)]).toString("base64");+ const url = (text: string) => text.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");+ const envHits = (text: string) => scan("blob: " + text + "\n", { processEnv: env }).findings.filter((f) => f.id === "env.value").map((f) => f.severity);++ test("a value that differs only in a boundary character's bits does not report at any alignment", () => {+ for (const other of ["build124", "ruild123", j('"', "uild123"), "build12;"]) for (const shift of [0, 1, 2]) for (const tail of [0, 31]) for (const u of [false, true]) {+ const text = u ? url(stream(other, shift, tail)) : stream(other, shift, tail);+ expect({ other, shift, tail, u, hits: envHits(text) }).toEqual({ other, shift, tail, u, hits: [] });+ }+ });++ test("a base64 or base64url symbol beside a form is read for its bits in either alphabet", () => {+ const value = "build123secretvalue";+ const near = { MY_API_TOKEN: value };+ const forms = (shift: number) => Buffer.concat([Buffer.alloc(shift), Buffer.from(value)]).toString("base64").replace(/=+$/, "");+ const core = forms(1).slice(2, -1);+ expect(forms(1)[1]).toBe("G");+ for (const lead of ["+", "/", "-", "_", "Q"]) {+ const hits = scan("xx " + lead + core + " yy", { processEnv: near }).findings.filter((f) => f.id === "env.value");+ expect({ lead, hits: hits.length }).toEqual({ lead, hits: 0 });+ }+ expect(scan("xx G" + core + " yy", { processEnv: near }).findings.filter((f) => f.id === "env.value").length).toBe(1);+ });++ test("the exact secret's base64 and base64url forms still report HIGH at every alignment, mid-stream and at its end", () => {+ for (const shift of [0, 1, 2]) for (const tail of [0, 31]) for (const u of [false, true]) {+ const text = u ? url(stream("build123", shift, tail)) : stream("build123", shift, tail);+ expect({ shift, tail, u, hits: envHits(text) }).toEqual({ shift, tail, u, hits: ["HIGH"] });+ }+ });+});++describe("round-2 review cases (GST-4104)", () => {+ const allowGoogle = (code: string, file: string) => {+ const found = scan(code, { repoVisibility: "private", processEnv: {}, sourcePath: file }).findings.map((f) => ({ id: f.id, category: f.category, severity: f.severity, file, line: f.line, col: f.col, lineText: code }));+ return applyAllowlist(found, [{ finding: "google.api_key", paths: ["src/**"], reason: "public Firebase key" }]).kept.map((f) => f.id);+ };++ test("a provider key alone in a declaration clears under its provider's allowlist entry", () => {+ expect(allowGoogle('const apiKey = "' + AIZA + '";', "src/firebase.ts")).toEqual([]);+ });++ test("a provider key joined to another secret keeps the declaration finding after the provider is allowlisted", () => {+ for (const code of ['const token = "' + AIZA + '" + "' + S + '";', "const token = '" + AIZA + "'+'" + S + "';"])+ expect({ code, kept: allowGoogle(code, "src/client.ts") }).toEqual({ code, kept: ["env.kv.js"] });+ });++ test("a block comment inside a type does not move the name to another declarator", () => {+ for (const code of ['let token: string /* a, b */ = "' + S + '";', 'const apiKey: Brand<string /* x, y */> = "' + S + '";'])+ expect({ code, hit: ids(code, "src/client.ts").includes("env.kv.js") }).toEqual({ code, hit: true });+ });++ test("a near-miss declaration line with many spaced earlier declarators scans quickly", () => {+ const line = "let " + ("aKEY: " + " ".repeat(24) + ", ").repeat(4) + "apiKEY: " + " ".repeat(100) + ";";+ const started = performance.now();+ scan(line + "\n", { repoVisibility: "private", processEnv: {}, sourcePath: "notes.md" });+ expect(performance.now() - started).toBeLessThan(250);+ });++ test("a rejected base64 candidate does not hide an overlapping exact encoding", () => {+ const value = "Zq8".repeat(5);+ const encoded = Buffer.concat([Buffer.alloc(1), Buffer.from(value)]).toString("base64").replace(/=+$/, "");+ const core = encoded.slice(2, -1);+ const hits = scan("blob Q" + core.slice(0, 4) + core + " end", { processEnv: { MY_API_TOKEN: value } }).findings.filter((f) => f.id === "env.value");+ expect(hits.map((f) => f.severity)).toEqual(["HIGH"]);+ });+});diff --git a/test/redact-secret-shaped-values.test.ts b/test/redact-secret-shaped-values.test.tsindex a61b761a1..c12ffb30a 100644--- a/test/redact-secret-shaped-values.test.ts+++ b/test/redact-secret-shaped-values.test.ts@@ -54,7 +54,7 @@ describe("env.kv.js: a secret-shaped literal bound by a JS/TS declaration report['let apiKey = "' + HEX + '";', "src/client.tsx"],['var secret = "' + S + '";', "lib/legacy.cjs"],['export const API_KEY = "' + S + '";', "src/config.mjs"],- ['export let clientSecret = "' + GHP + '";', "src/config.mts"],+ ['export let clientSecret = "' + S.toLowerCase() + '";', "src/config.mts"],['const apiKey: string = "' + S + '";', "src/config.ts"],['const API_KEY = "' + S.toUpperCase() + '";', "src/config.ts"],["const authToken = " + BT + S + BT + ";", "src/config.jsx"],