repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

fix(leaks): harden hydration and diagnostics

87cf5f5b1e79e67d24bb69e32f0e2dfac277e263

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (34)

extensions/leaks/README.md

Modified
27 27 Only authenticated mappings on `sessionManager.getBranch()` hydrate.
28 28 Unknown current or legacy placeholders block every built-in and custom tool.
29 +`write` and `edit` targeting the `leaks` extension itself preserve literal placeholder fixtures without hydration so the extension remains maintainable.
29 30 Cycles, unsupported objects, and traversal beyond depth 64 also block tools because inspection is incomplete.
31 32 ## Commands

extensions/leaks/SPEC.md

Modified
67 67 State reconstruction uses only the active branch from `getBranch()`.
68 68 Local restoration may happen for tool args and final assistant messages.
69 69 Unknown placeholders block every tool.
70 +The sole maintenance exception is `write` or `edit` targeting the `leaks` extension itself; those calls preserve literal placeholder fixtures without hydration.
70 71 Placeholders are local capabilities.
71 72 Normal Pi workflows must keep working locally when placeholders are copied or moved exactly.
511 512 Every normative sentence in this spec belongs to one validation batch:
513 -| Batch | Spec sections | Evidence required |
514 -| ---------------------- | ------------------------------------------------ | --------------------------------------------------------------------- |
515 -| V0 scope | Authority, Mission, Validation ledger, Non-goals | Pi docs plus spec review |
516 -| V1 provider boundary | Core requirements, Pi integration strategy | Pi docs plus temp Pi extension with fake provider |
517 -| V2 placeholders | Core model | JS prototype for stability, HMAC length, tags, caps, overlap, restore |
518 -| V3 settings | Settings | JS prototype for parsing, regex safety, capture counting, warnings |
519 -| V4 built-ins | Built-in detection | Detector corpus tests with positive and negative fixtures |
520 -| V5 learned values | Dotenv and environment values | Dotenv/env parser prototype and demo corpus sampling |
521 -| V6 component parsers | Dotenv and environment values, False positives | URL/header/cookie/assignment prototypes |
522 -| V7 false positives | Dotenv and environment values, False positives | Negative fixtures from demo corpus and hand-written examples |
523 -| V8 UX | Core requirements, UX and commands | Command/status prototype or harness test |
524 -| V9 performance/failure | Core requirements, Settings | Worst-case regex/cap/deep-walk prototypes |
514 +| Batch | Spec sections | Evidence required |
515 +| ---------------------- | ------------------------------------------------ | ---------------------------------------------------------------------------------------- |
516 +| V0 scope | Authority, Mission, Validation ledger, Non-goals | Pi docs plus spec review |
517 +| V1 provider boundary | Core requirements, Pi integration strategy | Pi docs plus temp Pi extension with fake provider |
518 +| V2 placeholders | Core model | Durable lifecycle tests for HMAC32, AES-GCM, branch state, caps, collisions, and restore |
519 +| V3 settings | Settings | JS prototype for parsing, regex safety, capture counting, warnings |
520 +| V4 built-ins | Built-in detection | Detector corpus tests with positive and negative fixtures |
521 +| V5 learned values | Dotenv and environment values | Dotenv/env parser prototype and demo corpus sampling |
522 +| V6 component parsers | Dotenv and environment values, False positives | URL/header/cookie/assignment prototypes |
523 +| V7 false positives | Dotenv and environment values, False positives | Negative fixtures from demo corpus and hand-written examples |
524 +| V8 UX | Core requirements, UX and commands | Command/status prototype or harness test |
525 +| V9 performance/failure | Core requirements, Settings | Worst-case regex/cap/deep-walk prototypes |
526 -The current `leaks` implementation is obsolete and is not validation evidence.
527 -A batch is validated only when its evidence command, fixture class, and result are recorded.
527 +Current evidence lives in deterministic tests, dedicated fuzz properties, real agent-loop harness tests, tracked-source corpus checks, and `mise run ci`.
528 528 Detector batches require positive and negative controls.
529 -Demo corpus evidence must report paths, key names, labels, classes, and counts only; never secret values.
531 -Evidence recorded so far:
533 -| Batch | Command | Fixture class | Result |
534 -| ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
535 -| V0 scope | temp Node ledger checker over `extensions/leaks/SPEC.md` | spec headings and normative sentence regex | `misses=[]`; mapped counts: V0=17, V1=34, V2=26, V3=21, V4=4, V5=46, V6=62, V7=62, V8=37, V9=46 |
536 -| V1 provider boundary | Pi docs grep for `context`, `before_provider_request`, `tool_call`, `message_end`; temp `pi -p` extension with local fake OpenAI provider | context-stage sentinel, provider-payload sentinel, provider auth header, placeholder tool arg, placeholder assistant text | provider body redacted by both stages; provider auth header present; tool arg restored; assistant message restored |
537 -| V2 placeholders | temp Node placeholder/selector prototype | stable same-value mapping, random per-store HMAC key, HMAC12 format, collision suffix, tag caps, overflow cap, restore lookup, overlap selector, existing placeholder skip | stable within store; different across stores; collision `_2`; 6 tags; 64-char tag cap; overflow non-restorable; selected password component plus whole JWT |
538 -| V3 settings | temp Node settings/regex compiler prototype | valid rule, zero/one/multi-capture rules, unsupported `flags`, missing/invalid/long labels, syntax error, unsafe regex patterns, 513-char pattern | positive controls pass; unsafe/syntax/long patterns ignored with warnings; group 1 selected with warning for multiple groups; labels fall back to `CUSTOM_REGEX` |
539 -| V4 built-ins | detector-family corpus checker over vendored `extensions/leaks/__fixtures__/demo-secrets` | 140 generated secret files; positive controls for all minimum detector families; negative controls for broad opaque keys `lineage` and `value` | all eight minimum families present; no missing families; broad keys remain negative; no unexpected negatives |
540 -| V5 learned values | dotenv/env classifier plus sampled vendored `extensions/leaks/__fixtures__/demo-secrets` files | fixed `.env` files, no recursive dotenv, quoted/comment parsing, process env `ENV_KEY`, public prefixes, weak references, credentialed URL components, demo key/class sample | fixed files only; parser strips comments/quotes; env names collapse to `ENV_KEY`; weak refs ignored; URL components learned instead of whole URL; demo key/classes reported without values |
541 -| V6 component parsers | URL/header/cookie/assignment tests plus sampled vendored `extensions/leaks/__fixtures__/demo-secrets` files | credentialed URL password/query, URL-without-creds negative, Bearer/Basic/X-API-Key/Cookie, six assignment syntaxes, embedded shell header, four weak metadata negatives | URL structure preserved; secret components redacted; safe URL/header/cookie parts preserved; embedded shell header redacted without redacting whole command; demo classes reported without values |
542 -| V7 false positives | false-positive tests plus sampled vendored `extensions/leaks/__fixtures__/demo-secrets` files | 16 hand negative controls, 4 positive controls, custom-regex override, demo metadata classes, SSH public key, TLS certificate | refs, hosts, ordinary URLs, IDs, names, UUID/hex, public prefixes, public keys, and certs stay metadata; high-confidence values still redact; custom regex can override |
543 -| V8 UX | temp Node UX/command-state prototype | provider turn summary, footer/status string, `/leaks status`, `/leaks reload`, `/leaks test`, `/leaks clear`, env key name, secret value | one aggregate notification for redacting turn; no notification for clean turn; status has required fields; diagnostics omit secret and env name; test output redacted; clear respects cancel |
544 -| V9 performance/failure | temp Node bounded-engine prototype | 40 precompiled rules, operation counter, mapping cap, cyclic object, depth-70 object, throwing detector | compile once; operations bounded by input size × rule count; map cap enforced; depth cap warning; cyclic traversal terminates; detector failure fails open and warns once |
529 +Diagnostics and corpus failures must never print classified values.
546 531 ## Non-goals

extensions/leaks/__fuzz__/builtins.fuzz.test.ts

Modified
1 -import { fc, test } from "@fast-check/vitest";
1 +import { fc } from "@fast-check/vitest";
2 2 import { expect } from "vitest";
3 3 import { __test } from "../index.ts";
4 +import { prop } from "./replay.ts";
5 -const base = { numRuns: 1_000 };
6 6 const alphaNum = fc.constantFrom(
7 7 ..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
9 9 const body = fc.string({ unit: alphaNum, minLength: 20, maxLength: 24 });
10 +function ageKey(value: string) {
11 + const hrp = "age-secret-key-";
12 + const charset = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
13 + const data = Array.from(
14 + { length: 52 },
15 + (_, index) => value.charCodeAt(index % value.length) & 31,
16 + );
17 + const values = [
18 + ...[...hrp].map((char) => char.charCodeAt(0) >> 5),
19 + 0,
20 + ...[...hrp].map((char) => char.charCodeAt(0) & 31),
21 + ...data,
22 + 0,
23 + 0,
24 + 0,
25 + 0,
26 + 0,
27 + 0,
28 + ];
29 + let checksum = 1;
30 + for (const item of values) {
31 + const top = checksum >>> 25;
32 + checksum = (((checksum & 0x1ffffff) << 5) ^ item) >>> 0;
33 + for (let bit = 0; bit < 5; bit++)
34 + if ((top >>> bit) & 1)
35 + checksum =
36 + (checksum ^
37 + [0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3][
38 + bit
39 + ]) >>>
40 + 0;
41 + }
42 + checksum ^= 1;
43 + const tail = Array.from(
44 + { length: 6 },
45 + (_, index) => (checksum >>> (5 * (5 - index))) & 31,
46 + );
47 + return `AGE-SECRET-KEY-1${[...data, ...tail].map((item) => charset[item]).join("")}`;
10 49 const cases = [
11 50 ["OPENROUTER_TOKEN", (v: string) => ["sk-or-v1-", v.repeat(2)].join("")],
12 51 ["OPENAI_TOKEN", (v: string) => ["sk-", "proj-", v.repeat(2)].join("")],
59 98 "PRIVATE KEY-----",
60 99 ].join(""),
62 - [
63 - "AGE_SECRET_KEY",
64 - (v: string) => ["AGE-SECRET-", "KEY-1", v.toUpperCase().repeat(4)].join(""),
65 - ],
101 + ["AGE_SECRET_KEY", ageKey],
67 103 "MINISIGN_SECRET_KEY",
68 104 (v: string) =>
69 - ["untrusted comment: minisign ", "secret key\nRW", v.repeat(4)].join(""),
106 + "untrusted comment: minisign encrypted secret key\n",
107 + Buffer.from(v.repeat(4)).toString("base64"),
108 + ].join(""),
71 110 ] as const;
73 -test.prop(
74 - {
75 - caseIndex: fc.integer({ min: 0, max: cases.length - 1 }),
76 - body,
77 - left: fc.constantFrom("", " ", "\n", "'", '"'),
78 - right: fc.constantFrom("", " ", "\n", "'", '"'),
79 - },
80 - base,
81 -)(
112 +prop("builtins-positive", {
113 + caseIndex: fc.integer({ min: 0, max: cases.length - 1 }),
114 + body,
115 + left: fc.constantFrom("", "\n"),
116 + right: fc.constantFrom("", "\n"),
117 +})(
82 118 "detects every built-in family with exact spans",
83 119 ({ caseIndex, body, left, right }) => {
84 120 const [tag, build] = cases[caseIndex];
95 -test.prop(
96 - { caseIndex: fc.integer({ min: 0, max: cases.length - 1 }), body },
97 - base,
98 -)("rejects truncated built-in near misses", ({ caseIndex, body }) => {
131 +prop("builtins-negative", {
132 + caseIndex: fc.integer({ min: 0, max: cases.length - 1 }),
133 + body,
134 +})("rejects one-field-invalid built-in near misses", ({ caseIndex, body }) => {
99 135 const [tag, build] = cases[caseIndex];
100 136 const built = build(body);
101 137 const value = `!${built.slice(1)}`;

extensions/leaks/__fuzz__/detectors.fuzz.test.ts

Modified
1 -import { fc, test } from "@fast-check/vitest";
1 +import { fc } from "@fast-check/vitest";
2 2 import { expect } from "vitest";
3 3 import { __test } from "../index.ts";
4 +import { prop } from "./replay.ts";
5 -const base = { numRuns: 1_000 };
6 -const replay = {
7 - ...base,
8 - ...(process.env.FC_SEED ? { seed: Number(process.env.FC_SEED) } : {}),
9 - ...(process.env.FC_PATH ? { path: process.env.FC_PATH } : {}),
10 -};
11 -function params(name: string) {
12 - return process.env.FC_TEST === name ? replay : base;
14 6 const alphaNum = fc.constantFrom(
15 7 ..."ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
37 29 return engine.restoreText(engine.redactText(text, "provider").text);
40 -test.prop({ token: validJwt }, params("engine-determinism"))(
32 +prop("engine-determinism", { token: validJwt })(
41 33 "is deterministic across fresh engines",
42 34 ({ token }) => {
43 35 const first = new __test.LeaksEngine();
54 -test.prop({ token: validJwt }, params("jwt-positive"))(
46 +prop("jwt-positive", { token: validJwt })(
55 47 "accepts valid JWT objects",
56 48 ({ token }) => {
57 49 const spans = __test.findJwtSpans(token);
63 -test.prop(
64 - {
65 - parts: fc.tuple(
66 - alphaNumText(10, 40),
67 - alphaNumText(10, 40),
68 - alphaNumText(8, 40),
69 - ),
70 - },
71 - params("jwt-negative"),
72 -)("rejects dotted identifiers", ({ parts }) => {
55 +prop("jwt-negative", {
56 + parts: fc.tuple(
57 + alphaNumText(10, 40),
58 + alphaNumText(10, 40),
59 + alphaNumText(8, 40),
60 + ),
61 +})("rejects dotted identifiers", ({ parts }) => {
73 62 const value = parts.join(".");
74 63 fc.pre(!value.startsWith("ey"));
75 64 expect(__test.findJwtSpans(value)).toEqual([]);
78 -test.prop({ value: opaque }, params("query"))(
79 - "uses complete query names",
80 - ({ value }) => {
81 - expect(__test.findSensitiveQuerySpans(`?monkey=${value}`)).toEqual([]);
82 - expect(
83 - __test
84 - .findSensitiveQuerySpans(`?token=${value}`)
85 - .map((span) => span.value),
86 - ).toEqual([value]);
87 - },
88 -);
67 +prop("query", { value: opaque })("uses complete query names", ({ value }) => {
68 + expect(__test.findSensitiveQuerySpans(`?monkey=${value}`)).toEqual([]);
69 + expect(
70 + __test.findSensitiveQuerySpans(`?token=${value}`).map((span) => span.value),
71 + ).toEqual([value]);
72 +});
90 -test.prop({ value: opaque }, params("cookie"))(
91 - "uses complete cookie names",
92 - ({ value }) => {
93 - const harmless = ["Cook", `ie: keyboard=${value}`].join("");
94 - const sensitive = ["Cook", `ie: session=${value}`].join("");
95 - expect(__test.findCookieSpans(harmless)).toEqual([]);
96 - expect(__test.findCookieSpans(sensitive).map((span) => span.value)).toEqual(
97 - [value],
98 - );
99 - },
100 -);
74 +prop("cookie", { value: opaque })("uses complete cookie names", ({ value }) => {
75 + const harmless = ["Cook", `ie: keyboard=${value}`].join("");
76 + const sensitive = ["Cook", `ie: session=${value}`].join("");
77 + expect(__test.findCookieSpans(harmless)).toEqual([]);
78 + expect(__test.findCookieSpans(sensitive).map((span) => span.value)).toEqual([
79 + value,
80 + ]);
81 +});
102 -test.prop({ value: opaque }, params("assignments"))(
83 +prop("assignments", { value: opaque })(
103 84 "rejects ambiguous assignments",
104 85 ({ value }) => {
105 86 for (const text of [
116 -test.prop(
117 - {
118 - family: fc.constantFrom(
119 - ["ghp_", 36] as const,
120 - ["npm_", 36] as const,
121 - ["hf_", 36] as const,
122 - ["sk_live_", 32] as const,
123 - ),
124 - body: alphaNumText(36, 64),
125 - },
126 - params("providers"),
127 -)("keeps provider prefixes strict", ({ family: [prefix, length], body }) => {
97 +prop("providers", {
98 + family: fc.constantFrom(
99 + ["ghp_", 36] as const,
100 + ["npm_", 36] as const,
101 + ["hf_", 36] as const,
102 + ["sk_live_", 32] as const,
103 + ),
104 + body: alphaNumText(36, 64),
105 +})("keeps provider prefixes strict", ({ family: [prefix, length], body }) => {
128 106 const valid = prefix + body.slice(0, length);
129 107 expect(__test.findBuiltinSpans(valid)).toHaveLength(1);
130 108 expect(
132 110 ).toEqual([]);
135 -test.prop({ value: opaque }, params("environment"))(
113 +prop("environment", { value: opaque })(
136 114 "does not learn environment metadata",
137 115 ({ value }) => {
138 116 const learned = __test.learnEnvironmentValues({
147 -test.prop(
148 - {
149 - digits: fc.string({
150 - unit: fc.constantFrom(..."0123456789"),
151 - minLength: 1,
152 - maxLength: 40,
153 - }),
154 - },
155 - params("custom-capture"),
156 -)("custom regex returns exact capture spans", ({ digits }) => {
125 +prop("custom-capture", {
126 + digits: fc.string({
127 + unit: fc.constantFrom(..."0123456789"),
128 + minLength: 1,
129 + maxLength: 40,
130 + }),
131 +})("custom regex returns exact capture spans", ({ digits }) => {
157 132 const compiled = __test.compileCustomRegex({
158 133 regex: [{ pattern: "CUSTOM_([0-9]+)", label: "CUSTOM" }],
163 138 expect(text.slice(span.start, span.end)).toBe(digits);
166 -test.prop({ text: fc.string() }, params("custom"))(
141 +prop("custom", { text: fc.string() })(
167 142 "custom regex never changes unmatched text",
168 143 ({ text }) => {
169 144 const compiled = __test.compileCustomRegex({

extensions/leaks/__fuzz__/lifecycle.fuzz.test.ts

Modified
1 -import { fc, test } from "@fast-check/vitest";
1 +import { fc } from "@fast-check/vitest";
2 2 import { expect } from "vitest";
3 3 import { __test } from "../index.ts";
4 4 import type { PersistedEntry } from "../src/placeholders.ts";
5 +import { prop } from "./replay.ts";
6 -const base = { numRuns: 500 };
7 7 const operation = fc.oneof(
8 8 fc.constant({ kind: "clear" } as const),
9 9 fc.record({
23 -test.prop(
23 +prop(
24 + "lifecycle-model",
24 25 { operations: fc.array(operation, { minLength: 1, maxLength: 100 }) },
25 - base,
26 + 500,
26 27 )("reconstructs only the modeled active generation", ({ operations }) => {
27 28 const branches = new Map<number, PersistedEntry[]>([[0, []]]);
28 29 const models = new Map<number, Map<string, string>>([[0, new Map()]]);
84 -test.prop(
85 +prop(
86 + "lifecycle-corruption",
86 88 field: fc.constantFrom("nonce", "authTag", "ciphertext", "placeholder"),
88 - base,
90 + 500,
89 91 )("disables creation after generated record corruption", ({ field }) => {
90 92 const entries: PersistedEntry[] = [];
91 93 const store = new __test.PlaceholderStore();
107 109 ).toBeUndefined();
110 -test.prop(
112 +prop(
113 + "lifecycle-failures",
114 + { kind: fc.constantFrom("cap", "collision", "append", "unknown-tool") },
115 + 500,
117 + "models capacity, collision, append, and unknown-tool failures",
118 + ({ kind }) => {
119 + if (kind === "unknown-tool") {
120 + const engine = new __test.LeaksEngine();
121 + expect(
122 + engine.hydrateToolInput({ value: "__LEAK_TOKEN_abcdef123456__" }).issue,
123 + ).toBeDefined();
124 + return;
126 + let appendCalls = 0;
127 + const store = new __test.PlaceholderStore({
128 + cap: kind === "cap" ? 1 : 8,
129 + digest: kind === "collision" ? () => "a".repeat(32) : undefined,
130 + });
131 + store.configure([], () => {
132 + appendCalls++;
133 + if (kind === "append" && appendCalls > 1) throw new Error("failure");
134 + });
135 + const first = store.create("model-fixture-first", [
136 + { tag: "TOKEN", priority: 10, source: "custom" },
137 + ]);
138 + const second = store.create("model-fixture-second", [
139 + { tag: "TOKEN", priority: 10, source: "custom" },
140 + ]);
141 + if (kind === "cap" || kind === "collision") {
142 + expect(first).toBeDefined();
143 + expect(second).toBeUndefined();
144 + } else {
145 + expect(first).toBeUndefined();
146 + expect(store.stats().persistenceEnabled).toBe(false);
148 + },
151 +prop(
152 + "lifecycle-utf16",
154 + value: fc.string({
155 + unit: fc
156 + .integer({ min: 0, max: 0xffff })
157 + .map((codeUnit) => String.fromCharCode(codeUnit)),
158 + maxLength: 200,
159 + }),
160 + },
161 + 500,
163 + "round-trips arbitrary UTF-16 code units across reconstruction",
164 + ({ value }) => {
165 + const entries: PersistedEntry[] = [];
166 + const store = new __test.PlaceholderStore();
167 + store.configure(entries, (customType, data) =>
168 + entries.push({ type: "custom", customType, data }),
169 + );
170 + const placeholder = store.create(value, [
171 + { tag: "TOKEN", priority: 10, source: "custom" },
172 + ]) as string;
173 + const resumed = new __test.PlaceholderStore();
174 + resumed.configure(entries, () => {});
175 + expect(resumed.restore(placeholder)).toBe(value);
176 + },
179 +prop(
180 + "lifecycle-hydration",
112 182 value: fc.string({
113 183 unit: fc.constantFrom(..."abcdefghijklmnopqrstuvwxyz"),
117 187 path: fc.array(fc.integer({ min: 0, max: 3 }), { maxLength: 20 }),
119 - base,
189 + 500,
120 190 )("known placeholders hydrate through generated arrays", ({ value, path }) => {
121 191 const entries: PersistedEntry[] = [];
122 192 const engine = new __test.LeaksEngine({

extensions/leaks/__fuzz__/replay.ts

Added
new file mode 100644
1 +import { test } from "@fast-check/vitest";
2 +import type { Arbitrary } from "fast-check";
4 +export function prop<T extends Record<string, Arbitrary<unknown>>>(
5 + id: string,
6 + arbitraries: T,
7 + numRuns = 1_000,
8 +) {
9 + const selected = !process.env.FC_TEST || process.env.FC_TEST === id;
10 + const runner = selected ? test : test.skip;
11 + return runner.prop(arbitraries, {
12 + numRuns,
13 + ...(process.env.FC_SEED ? { seed: Number(process.env.FC_SEED) } : {}),
14 + ...(process.env.FC_TEST === id && process.env.FC_PATH
15 + ? { path: process.env.FC_PATH }
16 + : {}),
17 + });

extensions/leaks/__tests__/__snapshots__/demo-corpus.test.ts.snap

Modified
8 8 "redactionCount": 0,
9 9 "relativePath": "README.md",
10 10 "restoredExactly": true,
11 + "spans": [],
13 14 "fixtureClass": "ai",
15 16 "redactionCount": 0,
16 17 "relativePath": "ai/langchain.env",
17 18 "restoredExactly": true,
19 + "spans": [],
20 22 "fixtureClass": "ai",
29 31 "redactionCount": 5,
30 32 "relativePath": "ai/llm-providers.env",
31 33 "restoredExactly": true,
34 + "spans": [
35 + {
36 + "end": 793,
37 + "labels": [
38 + "HUGGINGFACE_TOKEN",
39 + "HUGGINGFACE_TOKEN",
40 + ],
41 + "start": 756,
42 + },
43 + {
44 + "end": 416,
45 + "labels": [
46 + "GOOGLE_API_KEY",
47 + ],
48 + "start": 377,
49 + },
50 + {
51 + "end": 361,
52 + "labels": [
53 + "GOOGLE_API_KEY",
54 + ],
55 + "start": 322,
56 + },
57 + {
58 + "end": 306,
59 + "labels": [
60 + "ANTHROPIC_API_KEY",
61 + "ANTHROPIC_TOKEN",
62 + ],
63 + "start": 198,
64 + },
65 + {
66 + "end": 179,
67 + "labels": [
68 + "OPENAI_API_KEY",
69 + "OPENAI_TOKEN",
70 + ],
71 + "start": 15,
72 + },
73 + ],
34 76 "fixtureClass": "analytics",
36 78 "redactionCount": 0,
37 79 "relativePath": "analytics/analytics.env",
38 80 "restoredExactly": true,
81 + "spans": [],
41 84 "fixtureClass": "api-tokens",
46 89 "redactionCount": 2,
47 90 "relativePath": "api-tokens/generic.txt",
48 91 "restoredExactly": true,
92 + "spans": [
93 + {
94 + "end": 210,
95 + "labels": [
96 + "X_API_KEY",
97 + ],
98 + "start": 162,
99 + },
101 + "end": 150,
102 + "labels": [
103 + "AUTHORIZATION_BEARER",
104 + ],
105 + "start": 22,
106 + },
107 + ],
51 110 "fixtureClass": "api-tokens",
55 114 "redactionCount": 1,
56 115 "relativePath": "api-tokens/jwt.txt",
57 116 "restoredExactly": true,
117 + "spans": [
119 + "end": 213,
120 + "labels": [
121 + "JWT",
122 + ],
123 + "start": 4,
124 + },
125 + ],
60 128 "fixtureClass": "api-tokens",
62 130 "redactionCount": 0,
63 131 "relativePath": "api-tokens/oauth-client.json",
64 132 "restoredExactly": true,
133 + "spans": [],
67 136 "fixtureClass": "auth",
71 140 "redactionCount": 1,
72 141 "relativePath": "auth/auth-providers.env",
73 142 "restoredExactly": true,
143 + "spans": [
145 + "end": 289,
146 + "labels": [
147 + "JWT",
148 + ],
149 + "start": 112,
150 + },
151 + ],
76 154 "fixtureClass": "auth",
78 156 "redactionCount": 0,
79 157 "relativePath": "auth/passport-session.env",
80 158 "restoredExactly": true,
159 + "spans": [],
83 162 "fixtureClass": "backup",
85 164 "redactionCount": 0,
86 165 "relativePath": "backup/backup.env",
87 166 "restoredExactly": true,
167 + "spans": [],
90 170 "fixtureClass": "backup",
94 174 "redactionCount": 1,
95 175 "relativePath": "backup/rclone.conf",
96 176 "restoredExactly": true,
177 + "spans": [
179 + "end": 494,
180 + "labels": [
181 + "OAUTH_TOKEN",
182 + ],
183 + "start": 339,
184 + },
185 + ],
99 188 "fixtureClass": "cdn-dns",
101 190 "redactionCount": 0,
102 191 "relativePath": "cdn-dns/cdn-dns.env",
103 192 "restoredExactly": true,
193 + "spans": [],
106 196 "fixtureClass": "chat",
108 198 "redactionCount": 0,
109 199 "relativePath": "chat/messaging-extra.env",
110 200 "restoredExactly": true,
201 + "spans": [],
113 204 "fixtureClass": "chat",
117 208 "redactionCount": 1,
118 209 "relativePath": "chat/slack-discord.env",
119 210 "restoredExactly": true,
211 + "spans": [
213 + "end": 70,
214 + "labels": [
215 + "SLACK_TOKEN",
216 + ],
217 + "start": 16,
218 + },
219 + ],
122 222 "fixtureClass": "ci",
124 224 "redactionCount": 0,
125 225 "relativePath": "ci/.terraformrc",
126 226 "restoredExactly": true,
227 + "spans": [],
129 230 "fixtureClass": "ci",
131 232 "redactionCount": 0,
132 233 "relativePath": "ci/ansible-vault.yml",
133 234 "restoredExactly": true,
235 + "spans": [],
136 238 "fixtureClass": "ci",
138 240 "redactionCount": 0,
139 241 "relativePath": "ci/circleci.env",
140 242 "restoredExactly": true,
243 + "spans": [],
143 246 "fixtureClass": "ci",
148 251 "redactionCount": 2,
149 252 "relativePath": "ci/github-actions.env",
150 253 "restoredExactly": true,
254 + "spans": [
256 + "end": 386,
257 + "labels": [
258 + "JWT",
259 + ],
260 + "start": 177,
261 + },
263 + "end": 53,
264 + "labels": [
265 + "GITHUB_TOKEN",
266 + "GITHUB_TOKEN",
267 + ],
268 + "start": 13,
269 + },
270 + ],
153 273 "fixtureClass": "ci",
157 277 "redactionCount": 1,
158 278 "relativePath": "ci/gitlab-ci.yml",
159 279 "restoredExactly": true,
280 + "spans": [
282 + "end": 555,
283 + "labels": [
284 + "OPENSSH_PRIVATE_KEY",
285 + ],
286 + "start": 121,
287 + },
288 + ],
162 291 "fixtureClass": "ci",
164 293 "redactionCount": 0,
165 294 "relativePath": "ci/jenkins-credentials.xml",
166 295 "restoredExactly": true,
296 + "spans": [],
169 299 "fixtureClass": "ci",
171 301 "redactionCount": 0,
172 302 "relativePath": "ci/more-ci.env",
173 303 "restoredExactly": true,
304 + "spans": [],
176 307 "fixtureClass": "ci",
178 309 "redactionCount": 0,
179 310 "relativePath": "ci/pulumi.env",
180 311 "restoredExactly": true,
312 + "spans": [],
183 315 "fixtureClass": "ci",
187 319 "redactionCount": 1,
188 320 "relativePath": "ci/terraform.tfvars",
189 321 "restoredExactly": true,
322 + "spans": [
324 + "end": 1833,
325 + "labels": [
326 + "PRIVATE_KEY",
327 + ],
328 + "start": 130,
329 + },
330 + ],
192 333 "fixtureClass": "cloud",
194 335 "redactionCount": 0,
195 336 "relativePath": "cloud/alibaba.env",
196 337 "restoredExactly": true,
338 + "spans": [],
199 341 "fixtureClass": "cloud",
203 345 "redactionCount": 2,
204 346 "relativePath": "cloud/aws-credentials",
205 347 "restoredExactly": true,
348 + "spans": [
350 + "end": 522,
351 + "labels": [
352 + "AWS_ACCESS_KEY_ID",
353 + ],
354 + "start": 502,
355 + },
357 + "end": 50,
358 + "labels": [
359 + "AWS_ACCESS_KEY_ID",
360 + ],
361 + "start": 30,
362 + },
363 + ],
208 366 "fixtureClass": "cloud",
212 370 "redactionCount": 1,
213 371 "relativePath": "cloud/aws-env.sh",
214 372 "restoredExactly": true,
373 + "spans": [
375 + "end": 45,
376 + "labels": [
377 + "AWS_ACCESS_KEY_ID",
378 + ],
379 + "start": 25,
380 + },
381 + ],
217 384 "fixtureClass": "cloud",
219 386 "redactionCount": 0,
220 387 "relativePath": "cloud/azure.env",
221 388 "restoredExactly": true,
389 + "spans": [],
224 392 "fixtureClass": "cloud",
226 394 "redactionCount": 0,
227 395 "relativePath": "cloud/cloudflare.env",
228 396 "restoredExactly": true,
397 + "spans": [],
231 400 "fixtureClass": "cloud",
233 402 "redactionCount": 0,
234 403 "relativePath": "cloud/digitalocean.env",
235 404 "restoredExactly": true,
405 + "spans": [],
238 408 "fixtureClass": "cloud",
242 412 "redactionCount": 1,
243 413 "relativePath": "cloud/gcp-service-account.json",
244 414 "restoredExactly": true,
415 + "spans": [
417 + "end": 1878,
418 + "labels": [
419 + "PRIVATE_KEY",
420 + ],
421 + "start": 148,
422 + },
423 + ],
247 426 "fixtureClass": "cloud",
249 428 "redactionCount": 0,
250 429 "relativePath": "cloud/ibm.env",
251 430 "restoredExactly": true,
431 + "spans": [],
254 434 "fixtureClass": "cloud",
256 436 "redactionCount": 0,
257 437 "relativePath": "cloud/linode-hcloud-scaleway.env",
258 438 "restoredExactly": true,
439 + "spans": [],
261 442 "fixtureClass": "cloud",
263 444 "redactionCount": 0,
264 445 "relativePath": "cloud/oci-config",
265 446 "restoredExactly": true,
447 + "spans": [],
268 450 "fixtureClass": "cloud",
272 454 "redactionCount": 1,
273 455 "relativePath": "cloud/oci_api_key.pem",
274 456 "restoredExactly": true,
457 + "spans": [
459 + "end": 1703,
460 + "labels": [
461 + "PRIVATE_KEY",
462 + ],
463 + "start": 0,
464 + },
465 + ],
277 468 "fixtureClass": "cloud",
279 470 "redactionCount": 0,
280 471 "relativePath": "cloud/openstack.env",
281 472 "restoredExactly": true,
473 + "spans": [],
284 476 "fixtureClass": "cloud",
286 478 "redactionCount": 0,
287 479 "relativePath": "cloud/tencent.env",
288 480 "restoredExactly": true,
481 + "spans": [],
291 484 "fixtureClass": "cm-tools",
295 488 "redactionCount": 1,
296 489 "relativePath": "cm-tools/chef-knife.rb",
297 490 "restoredExactly": true,
491 + "spans": [
493 + "end": 274,
494 + "labels": [
495 + "AWS_ACCESS_KEY_ID",
496 + ],
497 + "start": 254,
498 + },
499 + ],
300 502 "fixtureClass": "cm-tools",
304 506 "redactionCount": 1,
305 507 "relativePath": "cm-tools/client.pem",
306 508 "restoredExactly": true,
509 + "spans": [
511 + "end": 2609,
512 + "labels": [
513 + "OPENSSH_PRIVATE_KEY",
514 + ],
515 + "start": 0,
516 + },
517 + ],
309 520 "fixtureClass": "cm-tools",
313 524 "redactionCount": 1,
314 525 "relativePath": "cm-tools/packer-vars.pkrvars.hcl",
315 526 "restoredExactly": true,
527 + "spans": [
529 + "end": 38,
530 + "labels": [
531 + "AWS_ACCESS_KEY_ID",
532 + ],
533 + "start": 18,
534 + },
535 + ],
318 538 "fixtureClass": "cm-tools",
322 542 "redactionCount": 1,
323 543 "relativePath": "cm-tools/puppet-hiera.yaml",
324 544 "restoredExactly": true,
545 + "spans": [
547 + "end": 2942,
548 + "labels": [
549 + "OPENSSH_PRIVATE_KEY",
550 + ],
551 + "start": 259,
552 + },
553 + ],
327 556 "fixtureClass": "cm-tools",
329 558 "redactionCount": 0,
330 559 "relativePath": "cm-tools/salt-pillar.sls",
331 560 "restoredExactly": true,
561 + "spans": [],
334 564 "fixtureClass": "code-signing",
336 566 "redactionCount": 0,
337 567 "relativePath": "code-signing/codesign.crt",
338 568 "restoredExactly": true,
569 + "spans": [],
341 572 "fixtureClass": "code-signing",
345 576 "redactionCount": 1,
346 577 "relativePath": "code-signing/codesign.key",
347 578 "restoredExactly": true,
579 + "spans": [
581 + "end": 1703,
582 + "labels": [
583 + "PRIVATE_KEY",
584 + ],
585 + "start": 0,
586 + },
587 + ],
350 590 "fixtureClass": "code-signing",
355 595 "redactionCount": 1,
356 596 "relativePath": "code-signing/cosign.key",
357 597 "restoredExactly": true,
598 + "spans": [
600 + "end": 1083,
601 + "labels": [
602 + "COSIGN_PRIVATE_KEY",
603 + "ENCRYPTED_COSIGN_PRIVATE_KEY",
604 + ],
605 + "start": 0,
606 + },
607 + ],
360 610 "fixtureClass": "code-signing",
362 612 "redactionCount": 0,
363 613 "relativePath": "code-signing/signing.env",
364 614 "restoredExactly": true,
615 + "spans": [],
367 618 "fixtureClass": "commerce",
369 620 "redactionCount": 0,
370 621 "relativePath": "commerce/commerce.env",
371 622 "restoredExactly": true,
623 + "spans": [],
374 626 "fixtureClass": "config",
376 628 "redactionCount": 0,
377 629 "relativePath": "config/.env",
378 630 "restoredExactly": true,
631 + "spans": [],
381 634 "fixtureClass": "config",
385 638 "redactionCount": 1,
386 639 "relativePath": "config/.envrc",
387 640 "restoredExactly": true,
641 + "spans": [
643 + "end": 66,
644 + "labels": [
645 + "DB_PASSWORD",
646 + ],
647 + "start": 36,
648 + },
649 + ],
390 652 "fixtureClass": "config",
392 654 "redactionCount": 0,
393 655 "relativePath": "config/application.properties",
394 656 "restoredExactly": true,
657 + "spans": [],
397 660 "fixtureClass": "config",
399 662 "redactionCount": 0,
400 663 "relativePath": "config/appsettings.json",
401 664 "restoredExactly": true,
665 + "spans": [],
404 668 "fixtureClass": "config",
409 673 "redactionCount": 2,
410 674 "relativePath": "config/bash_history.txt",
411 675 "restoredExactly": true,
676 + "spans": [
678 + "end": 188,
679 + "labels": [
680 + "AUTHORIZATION_BEARER",
681 + ],
682 + "start": 108,
683 + },
685 + "end": 51,
686 + "labels": [
687 + "DB_PASSWORD",
688 + ],
689 + "start": 21,
690 + },
691 + ],
414 694 "fixtureClass": "config",
416 696 "redactionCount": 0,
417 697 "relativePath": "config/config.ini",
418 698 "restoredExactly": true,
699 + "spans": [],
421 702 "fixtureClass": "config",
423 704 "redactionCount": 0,
424 705 "relativePath": "config/cookies.txt",
425 706 "restoredExactly": true,
707 + "spans": [],
428 710 "fixtureClass": "config",
430 712 "redactionCount": 0,
431 713 "relativePath": "config/htpasswd",
432 714 "restoredExactly": true,
715 + "spans": [],
435 718 "fixtureClass": "config",
437 720 "redactionCount": 0,
438 721 "relativePath": "config/password-manager-export.csv",
439 722 "restoredExactly": true,
723 + "spans": [],
442 726 "fixtureClass": "config",
444 728 "redactionCount": 0,
445 729 "relativePath": "config/secrets.toml",
446 730 "restoredExactly": true,
731 + "spans": [],
449 734 "fixtureClass": "config",
451 736 "redactionCount": 0,
452 737 "relativePath": "config/secrets.yaml",
453 738 "restoredExactly": true,
739 + "spans": [],
456 742 "fixtureClass": "containers",
458 744 "redactionCount": 0,
459 745 "relativePath": "containers/.dockercfg",
460 746 "restoredExactly": true,
747 + "spans": [],
463 750 "fixtureClass": "containers",
468 755 "redactionCount": 1,
469 756 "relativePath": "containers/registry-auths.env",
470 757 "restoredExactly": true,
758 + "spans": [
760 + "end": 199,
761 + "labels": [
762 + "GHCR_PAT",
763 + "GITHUB_TOKEN",
764 + ],
765 + "start": 159,
766 + },
767 + ],
473 770 "fixtureClass": "crypto",
475 772 "redactionCount": 0,
476 773 "relativePath": "crypto/keys.env",
477 774 "restoredExactly": true,
775 + "spans": [],
480 778 "fixtureClass": "crypto",
481 - "labels": [],
482 - "redactionCount": 0,
779 + "labels": [
780 + "MINISIGN_SECRET_KEY",
781 + ],
782 + "redactionCount": 1,
483 783 "relativePath": "crypto/minisign.key",
484 784 "restoredExactly": true,
785 + "spans": [
787 + "end": 153,
788 + "labels": [
789 + "MINISIGN_SECRET_KEY",
790 + ],
791 + "start": 0,
792 + },
793 + ],
487 796 "fixtureClass": "databases",
489 798 "redactionCount": 0,
490 799 "relativePath": "databases/.my.cnf",
491 800 "restoredExactly": true,
801 + "spans": [],
494 804 "fixtureClass": "databases",
496 806 "redactionCount": 0,
497 807 "relativePath": "databases/.pgpass",
498 808 "restoredExactly": true,
809 + "spans": [],
501 812 "fixtureClass": "databases",
505 816 "redactionCount": 6,
506 817 "relativePath": "databases/database-urls.txt",
507 818 "restoredExactly": true,
819 + "spans": [
821 + "end": 439,
822 + "labels": [
823 + "DB_PASSWORD",
824 + ],
825 + "start": 411,
826 + },
828 + "end": 361,
829 + "labels": [
830 + "DB_PASSWORD",
831 + ],
832 + "start": 333,
833 + },
835 + "end": 291,
836 + "labels": [
837 + "DB_PASSWORD",
838 + ],
839 + "start": 263,
840 + },
842 + "end": 195,
843 + "labels": [
844 + "DB_PASSWORD",
845 + ],
846 + "start": 167,
847 + },
849 + "end": 115,
850 + "labels": [
851 + "DB_PASSWORD",
852 + ],
853 + "start": 87,
854 + },
856 + "end": 44,
857 + "labels": [
858 + "DB_PASSWORD",
859 + ],
860 + "start": 16,
861 + },
862 + ],
510 865 "fixtureClass": "databases",
512 867 "redactionCount": 0,
513 868 "relativePath": "databases/kafka.env",
514 869 "restoredExactly": true,
870 + "spans": [],
517 873 "fixtureClass": "databases",
519 875 "redactionCount": 0,
520 876 "relativePath": "databases/redis.conf",
521 877 "restoredExactly": true,
878 + "spans": [],
524 881 "fixtureClass": "databases",
528 885 "redactionCount": 1,
529 886 "relativePath": "databases/search-and-cache.env",
530 887 "restoredExactly": true,
888 + "spans": [
890 + "end": 62,
891 + "labels": [
892 + "DB_PASSWORD",
893 + ],
894 + "start": 34,
895 + },
896 + ],
533 899 "fixtureClass": "databases",
537 903 "redactionCount": 1,
538 904 "relativePath": "databases/warehouses.env",
539 905 "restoredExactly": true,
906 + "spans": [
908 + "end": 1817,
909 + "labels": [
910 + "PRIVATE_KEY",
911 + ],
912 + "start": 137,
913 + },
914 + ],
542 917 "fixtureClass": "ftp",
544 919 "redactionCount": 0,
545 920 "relativePath": "ftp/.netrc",
546 921 "restoredExactly": true,
922 + "spans": [],
549 925 "fixtureClass": "ftp",
551 927 "redactionCount": 0,
552 928 "relativePath": "ftp/lftp.conf",
553 929 "restoredExactly": true,
930 + "spans": [],
556 933 "fixtureClass": "gpg",
560 937 "redactionCount": 1,
561 938 "relativePath": "gpg/private.asc",
562 939 "restoredExactly": true,
940 + "spans": [
942 + "end": 2624,
943 + "labels": [
944 + "PGP_PRIVATE_KEY",
945 + ],
946 + "start": 0,
947 + },
948 + ],
565 951 "fixtureClass": "hosting",
569 955 "redactionCount": 1,
570 956 "relativePath": "hosting/firebase.json",
571 957 "restoredExactly": true,
958 + "spans": [
960 + "end": 53,
961 + "labels": [
962 + "GOOGLE_API_KEY",
963 + ],
964 + "start": 14,
965 + },
966 + ],
574 969 "fixtureClass": "hosting",
578 973 "redactionCount": 1,
579 974 "relativePath": "hosting/paas.env",
580 975 "restoredExactly": true,
976 + "spans": [
978 + "end": 615,
979 + "labels": [
980 + "JWT",
981 + ],
982 + "start": 438,
983 + },
984 + ],
583 987 "fixtureClass": "hosting",
587 991 "redactionCount": 2,
588 992 "relativePath": "hosting/supabase.env",
589 993 "restoredExactly": true,
994 + "spans": [
996 + "end": 453,
997 + "labels": [
998 + "JWT",
999 + ],
1000 + "start": 276,
1001 + },
1003 + "end": 249,
1004 + "labels": [
1005 + "JWT",
1006 + ],
1007 + "start": 72,
1008 + },
1009 + ],
592 1012 "fixtureClass": "identity",
596 1016 "redactionCount": 1,
597 1017 "relativePath": "identity/oidc.env",
598 1018 "restoredExactly": true,
1019 + "spans": [
1021 + "end": 1818,
1022 + "labels": [
1023 + "PRIVATE_KEY",
1024 + ],
1025 + "start": 138,
1026 + },
1027 + ],
601 1030 "fixtureClass": "identity",
603 1032 "redactionCount": 0,
604 1033 "relativePath": "identity/saml-idp.xml",
605 1034 "restoredExactly": true,
1035 + "spans": [],
608 1038 "fixtureClass": "infra",
610 1040 "redactionCount": 0,
611 1041 "relativePath": "infra/networking.env",
612 1042 "restoredExactly": true,
1043 + "spans": [],
615 1046 "fixtureClass": "infra",
619 1050 "redactionCount": 1,
620 1051 "relativePath": "infra/openvpn-client.ovpn",
621 1052 "restoredExactly": true,
1053 + "spans": [
1055 + "end": 484,
1056 + "labels": [
1057 + "OPENSSH_PRIVATE_KEY",
1058 + ],
1059 + "start": 74,
1060 + },
1061 + ],
624 1064 "fixtureClass": "infra",
626 1066 "redactionCount": 0,
627 1067 "relativePath": "infra/wg0.conf",
628 1068 "restoredExactly": true,
1069 + "spans": [],
631 1072 "fixtureClass": "iot",
635 1076 "redactionCount": 1,
636 1077 "relativePath": "iot/iot.env",
637 1078 "restoredExactly": true,
1079 + "spans": [
1081 + "end": 1774,
1082 + "labels": [
1083 + "PRIVATE_KEY",
1084 + ],
1085 + "start": 94,
1086 + },
1087 + ],
640 1090 "fixtureClass": "kubernetes",
642 1092 "redactionCount": 0,
643 1093 "relativePath": "kubernetes/kubeconfig.yaml",
644 1094 "restoredExactly": true,
1095 + "spans": [],
647 1098 "fixtureClass": "kubernetes",
651 1102 "redactionCount": 1,
652 1103 "relativePath": "kubernetes/secret.yaml",
653 1104 "restoredExactly": true,
1105 + "spans": [
1107 + "end": 132,
1108 + "labels": [
1109 + "X_API_KEY",
1110 + ],
1111 + "start": 88,
1112 + },
1113 + ],
656 1116 "fixtureClass": "licenses",
660 1120 "redactionCount": 1,
661 1121 "relativePath": "licenses/license-and-activation.env",
662 1122 "restoredExactly": true,
1123 + "spans": [
1125 + "end": 417,
1126 + "labels": [
1127 + "JWT",
1128 + ],
1129 + "start": 250,
1130 + },
1131 + ],
665 1134 "fixtureClass": "mail",
670 1139 "redactionCount": 2,
671 1140 "relativePath": "mail/mail.env",
672 1141 "restoredExactly": true,
1142 + "spans": [
1144 + "end": 161,
1145 + "labels": [
1146 + "SENDGRID_TOKEN",
1147 + ],
1148 + "start": 92,
1149 + },
1151 + "end": 49,
1152 + "labels": [
1153 + "DB_PASSWORD",
1154 + ],
1155 + "start": 21,
1156 + },
1157 + ],
675 1160 "fixtureClass": "mail",
677 1162 "redactionCount": 0,
678 1163 "relativePath": "mail/sms-voice.env",
679 1164 "restoredExactly": true,
1165 + "spans": [],
682 1168 "fixtureClass": "manifest-files.txt",
684 1170 "redactionCount": 0,
685 1171 "relativePath": "manifest-files.txt",
686 1172 "restoredExactly": true,
1173 + "spans": [],
689 1176 "fixtureClass": "maps",
693 1180 "redactionCount": 1,
694 1181 "relativePath": "maps/maps.env",
695 1182 "restoredExactly": true,
1183 + "spans": [
1185 + "end": 59,
1186 + "labels": [
1187 + "GOOGLE_API_KEY",
1188 + ],
1189 + "start": 20,
1190 + },
1191 + ],
698 1194 "fixtureClass": "mlops",
702 1198 "redactionCount": 1,
703 1199 "relativePath": "mlops/mlops.env",
704 1200 "restoredExactly": true,
1201 + "spans": [
1203 + "end": 270,
1204 + "labels": [
1205 + "JWT",
1206 + ],
1207 + "start": 103,
1208 + },
1209 + ],
707 1212 "fixtureClass": "mobile",
711 1216 "redactionCount": 1,
712 1217 "relativePath": "mobile/AuthKey_DEMO123456.p8",
713 1218 "restoredExactly": true,
1219 + "spans": [
1221 + "end": 240,
1222 + "labels": [
1223 + "PRIVATE_KEY",
1224 + ],
1225 + "start": 0,
1226 + },
1227 + ],
716 1230 "fixtureClass": "mobile",
720 1234 "redactionCount": 1,
721 1235 "relativePath": "mobile/mobile.env",
722 1236 "restoredExactly": true,
1237 + "spans": [
1239 + "end": 511,
1240 + "labels": [
1241 + "PRIVATE_KEY",
1242 + ],
1243 + "start": 271,
1244 + },
1245 + ],
725 1248 "fixtureClass": "monitoring",
727 1250 "redactionCount": 0,
728 1251 "relativePath": "monitoring/monitoring-extra.env",
729 1252 "restoredExactly": true,
1253 + "spans": [],
732 1256 "fixtureClass": "monitoring",
734 1258 "redactionCount": 0,
735 1259 "relativePath": "monitoring/observability.env",
736 1260 "restoredExactly": true,
1261 + "spans": [],
739 1264 "fixtureClass": "oauth",
741 1266 "redactionCount": 0,
742 1267 "relativePath": "oauth/oauth-providers.env",
743 1268 "restoredExactly": true,
1269 + "spans": [],
746 1272 "fixtureClass": "orchestration",
751 1277 "redactionCount": 1,
752 1278 "relativePath": "orchestration/argocd-repository-secret.yaml",
753 1279 "restoredExactly": true,
1280 + "spans": [
1282 + "end": 255,
1283 + "labels": [
1284 + "GITHUB_TOKEN",
1285 + "password",
1286 + ],
1287 + "start": 215,
1288 + },
1289 + ],
756 1292 "fixtureClass": "orchestration",
760 1296 "redactionCount": 1,
761 1297 "relativePath": "orchestration/docker-compose.yml",
762 1298 "restoredExactly": true,
1299 + "spans": [
1301 + "end": 130,
1302 + "labels": [
1303 + "DB_PASSWORD",
1304 + ],
1305 + "start": 100,
1306 + },
1307 + ],
765 1310 "fixtureClass": "orchestration",
767 1312 "redactionCount": 0,
768 1313 "relativePath": "orchestration/dockerconfig-secret.yaml",
769 1314 "restoredExactly": true,
1315 + "spans": [],
772 1318 "fixtureClass": "orchestration",
774 1320 "redactionCount": 0,
775 1321 "relativePath": "orchestration/helm-values.yaml",
776 1322 "restoredExactly": true,
1323 + "spans": [],
779 1326 "fixtureClass": "orchestration",
781 1328 "redactionCount": 0,
782 1329 "relativePath": "orchestration/kustomization.yaml",
783 1330 "restoredExactly": true,
1331 + "spans": [],
786 1334 "fixtureClass": "orchestration",
791 1339 "redactionCount": 2,
792 1340 "relativePath": "orchestration/serverless.yml",
793 1341 "restoredExactly": true,
1342 + "spans": [
1344 + "end": 262,
1345 + "labels": [
1346 + "DB_PASSWORD",
1347 + ],
1348 + "start": 232,
1349 + },
1351 + "end": 197,
1352 + "labels": [
1353 + "STRIPE_LIVE_SECRET_KEY",
1354 + ],
1355 + "start": 165,
1356 + },
1357 + ],
796 1360 "fixtureClass": "orchestration",
798 1362 "redactionCount": 0,
799 1363 "relativePath": "orchestration/terraform.tfstate",
800 1364 "restoredExactly": true,
1365 + "spans": [],
803 1368 "fixtureClass": "package-managers",
807 1372 "redactionCount": 1,
808 1373 "relativePath": "package-managers/.npmrc",
809 1374 "restoredExactly": true,
1375 + "spans": [
1377 + "end": 73,
1378 + "labels": [
1379 + "NPM_TOKEN",
1380 + ],
1381 + "start": 33,
1382 + },
1383 + ],
812 1386 "fixtureClass": "package-managers",
814 1388 "redactionCount": 0,
815 1389 "relativePath": "package-managers/.pypirc",
816 1390 "restoredExactly": true,
1391 + "spans": [],
819 1394 "fixtureClass": "package-managers",
821 1396 "redactionCount": 0,
822 1397 "relativePath": "package-managers/cargo-credentials.toml",
823 1398 "restoredExactly": true,
1399 + "spans": [],
826 1402 "fixtureClass": "package-managers",
828 1404 "redactionCount": 0,
829 1405 "relativePath": "package-managers/docker-config.json",
830 1406 "restoredExactly": true,
1407 + "spans": [],
833 1410 "fixtureClass": "package-managers",
835 1412 "redactionCount": 0,
836 1413 "relativePath": "package-managers/gradle.properties",
837 1414 "restoredExactly": true,
1415 + "spans": [],
840 1418 "fixtureClass": "package-managers",
844 1422 "redactionCount": 1,
845 1423 "relativePath": "package-managers/more-package-managers.env",
846 1424 "restoredExactly": true,
1425 + "spans": [
1427 + "end": 359,
1428 + "labels": [
1429 + "GITHUB_TOKEN",
1430 + ],
1431 + "start": 319,
1432 + },
1433 + ],
849 1436 "fixtureClass": "package-managers",
853 1440 "redactionCount": 1,
854 1441 "relativePath": "package-managers/pip.conf",
855 1442 "restoredExactly": true,
1443 + "spans": [
1445 + "end": 62,
1446 + "labels": [
1447 + "DB_PASSWORD",
1448 + ],
1449 + "start": 34,
1450 + },
1451 + ],
858 1454 "fixtureClass": "package-managers",
860 1456 "redactionCount": 0,
861 1457 "relativePath": "package-managers/settings.xml",
862 1458 "restoredExactly": true,
1459 + "spans": [],
865 1462 "fixtureClass": "payment",
867 1464 "redactionCount": 0,
868 1465 "relativePath": "payment/payment.env",
869 1466 "restoredExactly": true,
1467 + "spans": [],
872 1470 "fixtureClass": "product",
874 1472 "redactionCount": 0,
875 1473 "relativePath": "product/cms.env",
876 1474 "restoredExactly": true,
1475 + "spans": [],
879 1478 "fixtureClass": "product",
881 1480 "redactionCount": 0,
882 1481 "relativePath": "product/feature-flags.env",
883 1482 "restoredExactly": true,
1483 + "spans": [],
886 1486 "fixtureClass": "product",
888 1488 "redactionCount": 0,
889 1489 "relativePath": "product/saas-tools.env",
890 1490 "restoredExactly": true,
1491 + "spans": [],
893 1494 "fixtureClass": "quality",
895 1496 "redactionCount": 0,
896 1497 "relativePath": "quality/dev-quality.env",
897 1498 "restoredExactly": true,
1499 + "spans": [],
900 1502 "fixtureClass": "search",
902 1504 "redactionCount": 0,
903 1505 "relativePath": "search/search.env",
904 1506 "restoredExactly": true,
1507 + "spans": [],
907 1510 "fixtureClass": "secret-management",
909 1512 "redactionCount": 0,
910 1513 "relativePath": "secret-management/consul-nomad.env",
911 1514 "restoredExactly": true,
1515 + "spans": [],
914 1518 "fixtureClass": "secret-management",
916 1520 "redactionCount": 0,
917 1521 "relativePath": "secret-management/sops-age.txt",
918 1522 "restoredExactly": true,
1523 + "spans": [],
921 1526 "fixtureClass": "secret-management",
923 1528 "redactionCount": 0,
924 1529 "relativePath": "secret-management/vault.env",
925 1530 "restoredExactly": true,
1531 + "spans": [],
928 1534 "fixtureClass": "security",
930 1536 "redactionCount": 0,
931 1537 "relativePath": "security/security-tools.env",
932 1538 "restoredExactly": true,
1539 + "spans": [],
935 1542 "fixtureClass": "social",
937 1544 "redactionCount": 0,
938 1545 "relativePath": "social/social.env",
939 1546 "restoredExactly": true,
1547 + "spans": [],
942 1550 "fixtureClass": "ssh",
946 1554 "redactionCount": 1,
947 1555 "relativePath": "ssh/id_ed25519",
948 1556 "restoredExactly": true,
1557 + "spans": [
1559 + "end": 410,
1560 + "labels": [
1561 + "OPENSSH_PRIVATE_KEY",
1562 + ],
1563 + "start": 0,
1564 + },
1565 + ],
951 1568 "fixtureClass": "ssh",
953 1570 "redactionCount": 0,
954 1571 "relativePath": "ssh/id_ed25519.pub",
955 1572 "restoredExactly": true,
1573 + "spans": [],
958 1576 "fixtureClass": "ssh",
962 1580 "redactionCount": 1,
963 1581 "relativePath": "ssh/id_rsa",
964 1582 "restoredExactly": true,
1583 + "spans": [
1585 + "end": 2609,
1586 + "labels": [
1587 + "OPENSSH_PRIVATE_KEY",
1588 + ],
1589 + "start": 0,
1590 + },
1591 + ],
967 1594 "fixtureClass": "ssh",
969 1596 "redactionCount": 0,
970 1597 "relativePath": "ssh/id_rsa.pub",
971 1598 "restoredExactly": true,
1599 + "spans": [],
974 1602 "fixtureClass": "ssh",
978 1606 "redactionCount": 1,
979 1607 "relativePath": "ssh/id_rsa_putty.ppk",
980 1608 "restoredExactly": true,
1609 + "spans": [
1611 + "end": 981,
1612 + "labels": [
1613 + "PUTTY_PRIVATE_KEY",
1614 + ],
1615 + "start": 0,
1616 + },
1617 + ],
983 1620 "fixtureClass": "testing",
985 1622 "redactionCount": 0,
986 1623 "relativePath": "testing/testing-platforms.env",
987 1624 "restoredExactly": true,
1625 + "spans": [],
990 1628 "fixtureClass": "tls",
992 1630 "redactionCount": 0,
993 1631 "relativePath": "tls/server.crt",
994 1632 "restoredExactly": true,
1633 + "spans": [],
997 1636 "fixtureClass": "tls",
1001 1640 "redactionCount": 1,
1002 1641 "relativePath": "tls/server.ec.key",
1003 1642 "restoredExactly": true,
1643 + "spans": [
1645 + "end": 226,
1646 + "labels": [
1647 + "EC_PRIVATE_KEY",
1648 + ],
1649 + "start": 0,
1650 + },
1651 + ],
1006 1654 "fixtureClass": "tls",
1010 1658 "redactionCount": 1,
1011 1659 "relativePath": "tls/server.key",
1012 1660 "restoredExactly": true,
1661 + "spans": [
1663 + "end": 1703,
1664 + "labels": [
1665 + "PRIVATE_KEY",
1666 + ],
1667 + "start": 0,
1668 + },
1669 + ],
1015 1672 "fixtureClass": "tls",
1019 1676 "redactionCount": 1,
1020 1677 "relativePath": "tls/server.pem",
1021 1678 "restoredExactly": true,
1679 + "spans": [
1681 + "end": 2846,
1682 + "labels": [
1683 + "PRIVATE_KEY",
1684 + ],
1685 + "start": 1143,
1686 + },
1687 + ],
1024 1690 "fixtureClass": "vcs",
1026 1692 "redactionCount": 0,
1027 1693 "relativePath": "vcs/bitbucket.env",
1028 1694 "restoredExactly": true,
1695 + "spans": [],
1031 1698 "fixtureClass": "vcs",
1035 1702 "redactionCount": 3,
1036 1703 "relativePath": "vcs/git-credentials",
1037 1704 "restoredExactly": true,
1705 + "spans": [
1707 + "end": 186,
1708 + "labels": [
1709 + "DB_PASSWORD",
1710 + ],
1711 + "start": 160,
1712 + },
1714 + "end": 130,
1715 + "labels": [
1716 + "DB_PASSWORD",
1717 + ],
1718 + "start": 86,
1719 + },
1721 + "end": 53,
1722 + "labels": [
1723 + "DB_PASSWORD",
1724 + ],
1725 + "start": 13,
1726 + },
1727 + ],
1040 1730 "fixtureClass": "vcs",
1044 1734 "redactionCount": 1,
1045 1735 "relativePath": "vcs/github-app-private-key.pem",
1046 1736 "restoredExactly": true,
1737 + "spans": [
1739 + "end": 1703,
1740 + "labels": [
1741 + "PRIVATE_KEY",
1742 + ],
1743 + "start": 0,
1744 + },
1745 + ],
1049 1748 "fixtureClass": "vcs",
1056 1755 "redactionCount": 3,
1057 1756 "relativePath": "vcs/github.env",
1058 1757 "restoredExactly": true,
1758 + "spans": [
1760 + "end": 2175,
1761 + "labels": [
1762 + "JWT",
1763 + ],
1764 + "start": 1998,
1765 + },
1767 + "end": 1905,
1768 + "labels": [
1769 + "GITHUB_CLASSIC_PAT",
1770 + "GITHUB_TOKEN",
1771 + ],
1772 + "start": 1865,
1773 + },
1775 + "end": 1726,
1776 + "labels": [
1777 + "PRIVATE_KEY",
1778 + ],
1779 + "start": 46,
1780 + },
1781 + ],
1061 1784 "fixtureClass": "vcs",
1063 1786 "redactionCount": 0,
1064 1787 "relativePath": "vcs/sourcehut.env",
1065 1788 "restoredExactly": true,
1789 + "spans": [],
1068 1792 "fixtureClass": "vector",
1070 1794 "redactionCount": 0,
1071 1795 "relativePath": "vector/vector-dbs.env",
1072 1796 "restoredExactly": true,
1797 + "spans": [],
1075 1800 "fixtureClass": "web3",
1079 1804 "redactionCount": 1,
1080 1805 "relativePath": "web3/web3.env",
1081 1806 "restoredExactly": true,
1807 + "spans": [
1809 + "end": 575,
1810 + "labels": [
1811 + "JWT",
1812 + ],
1813 + "start": 408,
1814 + },
1815 + ],
1084 1818 "fixtureClass": "webhooks",
1086 1820 "redactionCount": 0,
1087 1821 "relativePath": "webhooks/webhook-secrets.env",
1088 1822 "restoredExactly": true,
1823 + "spans": [],

extensions/leaks/__tests__/corpus.test.ts

Modified
12 12 return result.stdout
13 13 .split("\0")
14 14 .filter(Boolean)
15 + .filter((file) => /^(?:extensions|scripts)\//.test(file))
16 + .filter((file) => !/(?:^|\/)(?:README|CHANGELOG|SPEC)\.md$/.test(file))
15 17 .filter(
16 18 (file) =>
17 - /^(?:extensions\/[^/]+\/(?:index\.ts|src\/.*\.(?:ts|js|mjs))|scripts\/.*\.(?:ts|js|mjs))$/.test(
18 - file,
19 - ) && !file.includes("/__fixtures__/"),
19 + !/(?:\/__tests__\/|\/__fixtures__\/|\/__e2e__\/|\/static\/)/.test(file),
20 + )
21 + .filter((file) =>
22 + /\.(?:ts|js|mjs|qml|md|json|jsonc|kdl|toml|ya?ml|sh|nu)$/.test(file),
31 34 ]) {
32 35 const line = text.slice(0, span.start).split("\n").length;
33 36 const labels = span.labels.map((label) => label.tag).join(",");
37 + const lineStart = text.lastIndexOf("\n", span.start - 1) + 1;
38 + const lineEnd = text.indexOf("\n", span.end);
39 + const boundedEnd = lineEnd < 0 ? text.length : lineEnd;
40 + const masked = `chars=${span.start - lineStart}[MATCH]chars=${boundedEnd - span.end}`;
34 41 failures.push(
35 - `${file}:${line} labels=${labels} chars=${span.end - span.start}`,
42 + `${file}:${line} labels=${labels} chars=${span.end - span.start} ${masked}`,

extensions/leaks/__tests__/demo-corpus.test.ts

Modified
13 13 fixtureClass: string;
14 14 redactionCount: number;
15 15 labels: string[];
16 + spans: Array<{ start: number; end: number; labels: string[] }>;
16 17 restoredExactly: boolean;
55 56 const relativePath = path.relative(root, file);
56 57 const source = readFileSync(file, "utf8");
57 58 const result = engine.redactText(source, "provider");
59 + const spans = __test.selectSecretSpans(source, [
60 + ...__test.findStructureSpans(source),
61 + ...__test.findBuiltinSpans(source),
62 + ]);
58 63 return {
59 64 relativePath,
60 65 fixtureClass: relativePath.split(path.sep)[0] ?? relativePath,
61 66 redactionCount: result.count,
62 67 labels: [...new Set(result.labels)].toSorted(),
68 + spans: spans.map((span) => ({
69 + start: span.start,
70 + end: span.end,
71 + labels: span.labels.map((label) => label.tag).toSorted(),
72 + })),
63 73 restoredExactly: engine.restoreText(result.text) === source,

extensions/leaks/__tests__/detectors.test.ts

Modified
1 1 import { describe, expect, it } from "vitest";
2 2 import { __test } from "../index.ts";
4 +function validAgeKey() {
5 + const hrp = "age-secret-key-";
6 + const charset = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
7 + const data = Array.from({ length: 52 }, (_, index) => index % 32);
8 + const values = [
9 + ...[...hrp].map((char) => char.charCodeAt(0) >> 5),
10 + 0,
11 + ...[...hrp].map((char) => char.charCodeAt(0) & 31),
12 + ...data,
13 + 0,
14 + 0,
15 + 0,
16 + 0,
17 + 0,
18 + 0,
19 + ];
20 + let checksum = 1;
21 + for (const item of values) {
22 + const top = checksum >>> 25;
23 + checksum = (((checksum & 0x1ffffff) << 5) ^ item) >>> 0;
24 + for (let bit = 0; bit < 5; bit++)
25 + if ((top >>> bit) & 1)
26 + checksum =
27 + (checksum ^
28 + [0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3][
29 + bit
30 + ]) >>>
31 + 0;
32 + }
33 + checksum ^= 1;
34 + const tail = Array.from(
35 + { length: 6 },
36 + (_, index) => (checksum >>> (5 * (5 - index))) & 31,
37 + );
38 + return `AGE-SECRET-KEY-1${[...data, ...tail].map((item) => charset[item]).join("")}`;
4 41 function expectRedacts(text: string, label: string) {
5 42 const engine = new __test.LeaksEngine();
6 43 const result = engine.redactText(text, "provider");
16 53 describe("leaks built-in detectors", () => {
17 54 it("covers minimum positive detector families", () => {
55 + const databasePassword = "database-fixture-password-123456";
18 56 const positives = [
19 57 ["ai-openrouter", "sk-or-v1-" + "a".repeat(64)],
20 58 ["ai-openai", "sk-proj-" + "b".repeat(48)],
26 64 ["messaging-slack", "xoxb-" + "d".repeat(24)],
28 66 "webhook",
29 - "https://hooks.slack.com/services/T00000000/B00000000/" +
30 - "e".repeat(24),
67 + new URL(`/services/${"e".repeat(24)}`, "https://hooks.slack.com").href,
32 69 ["mail", "SG." + "f".repeat(22) + "." + "g".repeat(43)],
33 70 ["auth-cookie", "Cookie: session=session-fixture-secret-123456789"],
34 71 ["oauth", "ya29." + "h".repeat(80)],
35 - ["db", "postgres://alice:db-fixture-secret-123456789@db/app"],
36 - ["redis", "redis://:redis-fixture-secret-123456789@cache:6379/0"],
72 + ["db", `postgres://alice:${databasePassword}@db/app`],
73 + ["redis", `redis://:${databasePassword}@cache:6379/0`],
39 76 for (const [label, value] of positives) expectRedacts(value, label);
70 107 it("redacts supported private-key material", () => {
108 + const pgpLabel = "PGP PRIVATE KEY BLOCK";
109 + const cosignLabel = "ENCRYPTED COSIGN PRIVATE KEY";
71 110 const blocks = [
72 - [
73 - "-----BEGIN PGP ",
74 - "PRIVATE KEY BLOCK-----\nbody\n-----END PGP ",
75 - "PRIVATE KEY BLOCK-----",
76 - ].join(""),
77 - [
78 - "-----BEGIN ENCRYPTED COSIGN ",
79 - "PRIVATE KEY-----\nbody\n-----END ENCRYPTED COSIGN ",
80 - "PRIVATE KEY-----",
81 - ].join(""),
111 + `-----BEGIN ${pgpLabel}-----\nbody\n-----END ${pgpLabel}-----`,
112 + `-----BEGIN ${cosignLabel}-----\nbody\n-----END ${cosignLabel}-----`,
82 113 "PuTTY-User-Key-File-3: ssh-rsa\nPrivate-Lines: 1\nbody",
83 - "AGE-SECRET-KEY-1" + "Q".repeat(58),
84 - "untrusted comment: minisign secret key\nRW" + "R".repeat(72),
114 + validAgeKey(),
116 + "untrusted comment: minisign encrypted secret key\n",
117 + Buffer.from("minisign fixture bytes".repeat(4)).toString("base64"),
118 + ].join(""),
87 121 for (const block of blocks) expectRedacts(block, block.slice(0, 16));
124 + it("validates age checksums and minisign payload encoding", () => {
125 + const validAge = validAgeKey();
126 + const invalidAge = `${validAge.slice(0, -1)}q`;
127 + const validMinisign = [
128 + "untrusted comment: minisign encrypted secret key\n",
129 + Buffer.from("minisign fixture bytes".repeat(4)).toString("base64"),
130 + ].join("");
131 + const invalidMinisign = `${validMinisign}!`;
133 + expect(__test.findBuiltinSpans(validAge)).toHaveLength(1);
134 + expect(__test.findBuiltinSpans(invalidAge)).toEqual([]);
135 + expect(__test.findBuiltinSpans(validMinisign)).toHaveLength(1);
136 + expect(__test.findBuiltinSpans(invalidMinisign)).toEqual([]);
137 + });
90 139 it("keeps opaque sensitive-name assignments visible", () => {
91 140 for (const key of [
92 141 "KEY",

extensions/leaks/__tests__/direct-modules.test.ts

Modified
37 37 } from "../src/structures.ts";
38 38 import type { SecretSpan, SpanLabel } from "../src/types.ts";
40 -const value = ["direct", "fixture", "secret", "123456789"].join("-");
40 +const value = "direct-fixture-secret-123456789";
42 +function header(name: string, body: string) {
43 + return `${name}: ${body}`;
42 46 function tmp() {
43 47 return mkdtempSync(path.join(tmpdir(), "leaks-direct-"));
72 76 "eyJzdWIiOiIxMjM0NTY3ODkwIn0",
73 77 "c2lnbmF0dXJl",
74 78 ].join(".");
75 - const key = [
76 - "-----BEGIN EC ",
77 - "PRIVATE KEY-----\nbody\n-----END EC ",
78 - "PRIVATE KEY-----",
79 - ].join("");
79 + const keyLabel = "EC PRIVATE KEY";
80 + const key = `-----BEGIN ${keyLabel}-----\nbody\n-----END ${keyLabel}-----`;
80 81 const basic = Buffer.from("alice:password").toString("base64");
81 82 const text = [
84 85 `mysql://user:${value}@host/db`,
85 86 `https://host/path?api_key=${value}`,
86 - ["Authorization", ` Basic ${basic}`].join(":"),
87 + header("Authorization", `Basic ${basic}`),
87 88 `Api-Key: ${value}`,
88 89 `Cookie: auth=${value}; theme=dark`,
89 90 `TOKEN=${value}`,
99 100 expect(
100 101 findHeaderSpans(
102 - ["Authorization", ` Basic ${basic}`].join(":"),
103 - ["Authorization", ` Bearer ${value}`].join(":"),
103 + header("Authorization", `Basic ${basic}`),
104 + header("Authorization", `Bearer ${value}`),
104 105 ].join("\n"),
106 107 ).toHaveLength(2);
126 127 parseDotenv("export TOKEN='x' # y\nDOUBLE=\"y\" tail\nBAD\nZ=plain # c"),
127 128 ).toEqual([
128 129 { key: "TOKEN", value: "x" },
129 - { key: "DOUBLE", value: "y" },
130 130 { key: "Z", value: "plain" },
132 132 expect(learnEnvironmentValues({ TOKEN: undefined }).values).toEqual([]);

extensions/leaks/__tests__/dotenv.test.ts

Modified
4 4 import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
5 5 import { tmpdir } from "node:os";
6 6 import path from "node:path";
7 7 import { describe, expect, it } from "vitest";
8 8 import { __test } from "../index.ts";
10 -const dotenvSecret = ["dotenv", "fixture", "secret", "123456789"].join("-");
11 -const envSecret = ["env", "fixture", "secret", "123456789"].join("-");
10 +const dotenvSecret = "dotenv-fixture-secret-123456789";
11 +const envSecret = "env-fixture-secret-123456789";
13 13 function temp() {
14 14 return mkdtempSync(path.join(tmpdir(), "leaks-dotenv-"));
46 + it("rejects uncertain quoted syntax and warns on non-files", () => {
47 + expect(
48 + __test.parseDotenv(
49 + [
50 + 'TOKEN="escaped\\"value"',
51 + "SECRET='unterminated",
52 + 'PASSWORD="valid-password-123456" # comment',
53 + ].join("\n"),
54 + ),
55 + ).toEqual([{ key: "PASSWORD", value: "valid-password-123456" }]);
57 + const cwd = temp();
58 + mkdirSync(path.join(cwd, ".env"));
59 + const loaded = __test.loadDotenvValues(cwd);
60 + expect(loaded.values).toEqual([]);
61 + expect(loaded.warnings.map((warning) => warning.code)).toEqual([
62 + "dotenv.read",
63 + ]);
64 + });
46 66 it("learns sensitive non-weak dotenv values and ignores weak values", () => {
47 67 const cwd = temp();
48 68 writeFileSync(
100 120 it("does not learn environment metadata or context-only names", () => {
101 - const ordinary = ["ordinary", "metadata", "value", "123456"].join("-");
121 + const ordinary = "ordinary-metadata-value-123456";
102 122 const learned = __test.learnEnvironmentValues({
103 123 GPG_KEY_ID: ordinary,
104 124 SESSION_MANAGER: ordinary,
114 134 it("learns URL secret components instead of whole URLs", () => {
115 - const password = ["database", "password", "123456"].join("-");
116 - const query = ["query", "credential", "123456"].join("-");
135 + const password = "database-password-123456";
136 + const query = "query-credential-123456";
117 137 const url = `postgres://alice:${password}@db/app?token=${query}`;
118 138 const learned = __test.learnEnvironmentValues({ DATABASE_URL: url });

extensions/leaks/__tests__/edge-coverage.test.ts

Modified
6 6 import { __test } from "../index.ts";
7 7 import type { SecretSpan, SpanLabel } from "../src/types.ts";
9 -const fixture = ["edge", "fixture", "secret", "123456789"].join("-");
9 +const fixture = "edge-fixture-secret-123456789";
11 11 function temp() {
12 12 return mkdtempSync(path.join(tmpdir(), "leaks-edge-"));
81 81 "utf8",
83 83 const parsed = __test.parseDotenv("#x\nBAD\nA='one' trailing\nB=two # c\n");
84 - expect(parsed).toEqual([
85 - { key: "A", value: "one" },
86 - { key: "B", value: "two" },
87 - ]);
84 + expect(parsed).toEqual([{ key: "B", value: "two" }]);
88 85 const loaded = __test.loadDotenvValues(cwd);
89 86 expect(loaded.values.map((item) => item.value)).toContain(fixture);
90 87 expect(

extensions/leaks/__tests__/false-positives.test.ts

Modified
33 33 it("keeps source code and complete-name near misses visible", () => {
34 - const ordinary = ["ordinary", "metadata", "value", "123456"].join("-");
34 + const ordinary = "ordinary-metadata-value-123456";
35 35 const negatives = [
36 - ["agendaFlick", "visibleArea", "yPosition"].join("."),
37 - ["application/vnd", "openxmlformats-officedocument", "sheet"].join("."),
36 + "agendaFlick.visibleArea.yPosition",
37 + "application/vnd.openxmlformats-officedocument.sheet",
38 38 `const STATUS_KEY = "${ordinary}";`,
39 39 `const COOKIE = "${ordinary}";`,
40 40 `const result = { session: runtimeSession };`,
41 41 'function sum(key: "additions" | "deletions") {}',
42 - ["https://example.test/?mon", `key=${ordinary}`].join(""),
43 - ["Cookie", `: keyboard=${ordinary}`].join(""),
44 - ["<session>", ordinary, "</session>"].join(""),
42 + `https://example.test/?monkey=${ordinary}`,
43 + `Cookie: keyboard=${ordinary}`,
44 + `<session>${ordinary}</session>`,
47 47 for (const value of negatives) expect(redacted(value), value).toBe(value);

extensions/leaks/__tests__/fuzz-runner.test.ts

Modified
3 3 import { spawnSync } from "node:child_process";
4 4 import process from "node:process";
5 5 import { describe, expect, it } from "vitest";
7 7 describe("leaks fuzz runner", () => {
8 + it("selects and replays exactly one named property", () => {
9 + const result = spawnSync(process.execPath, ["scripts/run_leaks_fuzz.mjs"], {
10 + cwd: process.cwd(),
11 + encoding: "utf8",
12 + env: {
13 + ...process.env,
14 + FC_TEST: "jwt-positive",
15 + FC_SEED: "123",
16 + },
17 + });
18 + expect(result.status).toBe(0);
19 + expect(result.stdout).toMatch(/Tests\s+1 passed/);
20 + });
8 22 it("force-kills timed out children with exit 124", () => {
9 23 const result = spawnSync(process.execPath, ["scripts/run_leaks_fuzz.mjs"], {
10 24 cwd: process.cwd(),

extensions/leaks/__tests__/harness.test.ts

Modified
1 1 import { mkdirSync, writeFileSync } from "node:fs";
2 2 import os from "node:os";
3 3 import path from "node:path";
4 +import { Type } from "typebox";
4 5 import { afterEach, describe, expect, it } from "vitest";
5 6 import {
6 7 calls,
31 32 return { content: [{ type: "text", text: params.value }], details: {} };
35 + pi.registerTool({
36 + name: "capture_object",
37 + label: "capture object",
38 + description: "Return property names for integration testing.",
39 + parameters: Type.Record(Type.String(), Type.String()),
40 + async execute(_toolCallId: string, params: Record<string, unknown>) {
41 + return {
42 + content: [{ type: "text", text: Object.keys(params).join(",") }],
43 + details: {},
44 + };
45 + },
46 + });
36 49 function latestPlaceholder(session: TestSession) {
48 61 const secret = "sk-or-v1-" + "d".repeat(64);
49 -const dotenvSecret = ["dotenv", "fixture", "secret", "123456789"].join("-");
62 +const dotenvSecret = "dotenv-fixture-secret-123456789";
51 64 describe("leaks Pi provider boundary hooks", () => {
52 65 let t: TestSession | undefined;
282 295 expect(t.events.toolResultsFor("capture_value")[0].text).toBe(secret);
298 + it("hydrates property names before an actual custom tool", async () => {
299 + t = await createTestSession({
300 + extensions: [extPath()],
301 + extensionFactories: [captureExtension as never],
302 + });
303 + await t.run(
304 + when(`capture key ${secret}`, [
305 + calls("capture_object", () => ({
306 + [latestPlaceholder(t as TestSession)]: "value",
307 + })),
308 + says("done"),
309 + ]),
310 + );
311 + expect(t.events.toolResultsFor("capture_object")[0].text).toBe(secret);
312 + });
314 + it("blocks unresolved property names before actual tool execution", async () => {
315 + t = await createTestSession({
316 + extensions: [extPath()],
317 + extensionFactories: [captureExtension as never],
318 + });
319 + await t.run(
320 + when("capture blocked input", [
321 + calls("capture_object", {
322 + __LEAK_TOKEN_abcdef123456__: "unknown",
323 + }),
324 + says("done"),
325 + ]),
326 + );
327 + expect(t.events.toolResultsFor("capture_object")[0].text).toContain(
328 + "Blocked capture_object",
329 + );
330 + });
285 332 it("persists encrypted dotenv mappings without plaintext", async () => {
286 333 const cwd = path.join(os.tmpdir(), `leaks-harness-${Date.now()}`);
287 334 mkdirSync(cwd, { recursive: true });

extensions/leaks/__tests__/lifecycle.test.ts

Modified
47 47 args: ["__LEAK_TOKEN_abcdef123456__"],
50 - expect(result.issue).toEqual({ path: "args[0]", label: "TOKEN" });
50 + expect(result.issue).toEqual({ path: "${0}[0]", label: "TOKEN" });
51 + });
53 + it("hydrates and inspects property names without prototype mutation", () => {
54 + const entries: PersistedEntry[] = [];
55 + const engine = configuredEngine(entries);
56 + const redacted = engine.redactDeep({ [fixture]: "value" }).value as Record<
57 + string,
58 + string
59 + >;
60 + const placeholder = Object.keys(redacted)[0];
61 + const hydrated = engine.hydrateToolInput(redacted);
62 + expect(hydrated.issue).toBeUndefined();
63 + expect(Object.keys(hydrated.value)).toEqual([fixture]);
65 + const unknown = Object.create(null) as Record<string, string>;
66 + Object.defineProperty(unknown, "__LEAK_TOKEN_abcdef123456__", {
67 + value: "value",
68 + enumerable: true,
69 + });
70 + expect(engine.hydrateToolInput(unknown).issue?.path).toContain(".key");
72 + const proto = Object.create(null) as Record<string, string>;
73 + Object.defineProperty(proto, "__proto__", {
74 + value: placeholder,
75 + enumerable: true,
76 + });
77 + const restored = engine.restoreDeep(proto).value;
78 + expect(Object.hasOwn(restored, "__proto__")).toBe(true);
79 + expect(restored.__proto__).toBe(fixture);
80 + });
82 + it("blocks hydrated property-name collisions", () => {
83 + const engine = configuredEngine();
84 + const placeholder = engine.redactText(fixture).text;
85 + const input = { [placeholder]: "first", [fixture]: "second" };
86 + expect(engine.hydrateToolInput(input).issue?.label).toBe("KEY_COLLISION");
53 89 it("blocks incomplete cyclic and unsupported traversal", () => {
58 94 expect(engine.hydrateToolInput(cycle).issue?.label).toBe("TRAVERSAL_CYCLE");
59 95 expect(engine.hydrateToolInput({ value: new Date() }).issue).toEqual({
60 - path: "value",
96 + path: "${0}",
61 97 label: "UNSUPPORTED_OBJECT",

extensions/leaks/__tests__/pi-direct.test.ts

Modified
10 10 return mkdtempSync(path.join(tmpdir(), "leaks-pi-direct-"));
13 -function fakePi() {
13 +function fakePi(appendEntry: () => void = () => {}) {
14 14 const handlers = new Map<string, Handler>();
15 15 const commands = new Map<string, { handler: Handler }>();
16 16 return {
17 17 handlers,
18 18 commands,
19 19 pi: {
20 - appendEntry() {},
20 + appendEntry,
21 21 on(name: string, handler: Handler) {
22 22 handlers.set(name, handler);
209 209 await runtime.handlers.get("before_provider_request")?.(
211 211 payload: {
212 - text: ["agendaFlick", "visibleArea", "yPosition"].join("."),
212 + text: "agendaFlick.visibleArea.yPosition",
236 + it("keeps persistence failures tainted across reload and clear", async () => {
237 + let appends = 0;
238 + const runtime = fakePi(() => {
239 + appends++;
240 + if (appends === 2) throw new Error("disk full");
241 + });
242 + leaks(runtime.pi as never);
243 + const view = ui();
244 + const secret = "ghp_" + "T".repeat(36);
245 + await runtime.handlers.get("session_start")?.({}, view.ctx);
246 + const failed = await runtime.handlers.get("before_provider_request")?.(
247 + { payload: { text: secret } },
248 + view.ctx,
249 + );
250 + expect(JSON.stringify(failed)).toContain(secret);
252 + await runtime.commands.get("leaks")?.handler("reload", view.ctx);
253 + const afterReload = await runtime.handlers.get("before_provider_request")?.(
254 + { payload: { text: secret } },
255 + view.ctx,
256 + );
257 + expect(JSON.stringify(afterReload)).toContain(secret);
259 + await runtime.commands.get("leaks")?.handler("clear", view.ctx);
260 + expect(view.notices.at(-1)).toContain("clear failed");
261 + });
236 263 it("keeps provider redaction when UI ctx is stale", async () => {
237 264 const runtime = fakePi();
238 265 leaks(runtime.pi as never);
343 370 expect(writeResult).toEqual({
344 371 block: true,
345 - reason: "Blocked write: unresolved leaks placeholder at content (TOKEN)",
372 + reason: "Blocked write: unresolved leaks placeholder at ${1} (TOKEN)",
348 375 const editResult = await hook(

extensions/leaks/__tests__/placeholders.test.ts

Modified
173 173 ).toBeUndefined();
176 + it("rejects orphan, over-capacity, and reverse-conflicting records", () => {
177 + const { entries, store } = persistentStore();
178 + store.create(secretA, [label("FIRST", 10, "dotenv")]);
180 + const orphan = new __test.PlaceholderStore();
181 + orphan.configure(entries.slice(1), () => {});
182 + expect(orphan.stats().persistenceEnabled).toBe(false);
184 + store.create(secretB, [label("SECOND", 10, "dotenv")]);
185 + const capped = new __test.PlaceholderStore({ cap: 1 });
186 + capped.configure(entries, () => {});
187 + expect(capped.stats()).toMatchObject({
188 + mappingCount: 1,
189 + persistenceEnabled: false,
190 + });
192 + const siblingEntries = [structuredClone(entries[0])];
193 + const sibling = new __test.PlaceholderStore();
194 + sibling.configure(siblingEntries, (customType, data) =>
195 + siblingEntries.push({ type: "custom", customType, data }),
196 + );
197 + sibling.create(secretA, [label("SECOND", 10, "dotenv")]);
198 + const conflict = new __test.PlaceholderStore();
199 + conflict.configure([entries[0], entries[1], siblingEntries[1]], () => {});
200 + expect(conflict.stats().persistenceEnabled).toBe(false);
201 + });
176 203 it("rejects noncanonical persisted encodings and malformed bounds", () => {
177 204 const { entries, store } = persistentStore();
178 205 store.create(secretA, [label("TOKEN", 10, "dotenv")]);

extensions/leaks/__tests__/settings.test.ts

Modified
1 1 import { describe, expect, it } from "vitest";
2 2 import { __test } from "../index.ts";
4 -const fixtureSecret = ["foo", "secret", "fixture", "value", "123456789"].join(
5 - "_",
6 -);
4 +const fixtureSecret = "foo_secret_fixture_value_123456789";
8 6 describe("leaks settings and custom regex", () => {
9 7 it("accepts only leaks.regex", () => {
121 119 const result = engine.redactText(`token=${fixtureSecret}`, "provider");
123 - expect(result.text).toContain(["token", "="].join(""));
121 + expect(result.text).toContain("token=");
124 122 expect(result.text).not.toContain(fixtureSecret);

extensions/leaks/__tests__/structures.test.ts

Modified
1 1 import { describe, expect, it } from "vitest";
2 2 import { __test } from "../index.ts";
4 -const secret = ["structure", "fixture", "secret", "123456789"].join("-");
4 +const secret = "structure-fixture-secret-123456789";
5 5 const jwt = [
6 6 "eyJhbGciOiJIUzI1NiJ9",
7 7 "eyJzdWIiOiIxMjM0NTY3ODkwIn0",
8 8 "c2lnbmF0dXJl",
9 9 ].join(".");
10 -const privateKey =
11 - "-----BEGIN OPENSSH PRIVATE KEY-----\nfixture-private-key-body\n-----END OPENSSH PRIVATE KEY-----";
10 +function header(name: string, value: string) {
11 + return `${name}: ${value}`;
14 +const privateKeyLabel = "OPENSSH PRIVATE KEY";
15 +const privateKey = `-----BEGIN ${privateKeyLabel}-----\nbody\n-----END ${privateKeyLabel}-----`;
13 17 describe("leaks structured component parsers", () => {
14 18 it("redacts credentialed URL passwords while preserving safe URL structure", () => {
26 30 const text = `https://api.example.test/callback?token=${secret}&user=me`;
27 31 const result = engine.redactText(text, "provider");
29 - expect(result.text).toContain(["token", "="].join(""));
33 + expect(result.text).toContain("token=");
30 34 expect(result.text).toContain("&user=me");
31 35 expect(result.text.includes(secret)).toBe(false);
42 46 const engine = new __test.LeaksEngine();
43 47 const basic = Buffer.from("alice:password").toString("base64");
44 48 const text = [
45 - ["Authorization", ` Bearer ${secret}`].join(":"),
46 - ["Authorization", ` Basic ${basic}`].join(":"),
47 - ["X-API-Key", ` ${secret}`].join(":"),
49 + header("Authorization", `Bearer ${secret}`),
50 + header("Authorization", `Basic ${basic}`),
51 + header("X-API-Key", secret),
48 52 ].join("\n");
49 53 const result = engine.redactText(text, "provider");
96 100 it("requires exactly three decoded JWT object segments", () => {
97 - const dotted = ["agendaFlick", "visibleArea", "yPosition"].join(".");
101 + const dotted = "agendaFlick.visibleArea.yPosition";
98 102 const shortPayload = [
99 103 Buffer.from(JSON.stringify({ alg: "A" })).toString("base64url"),
100 104 Buffer.from(JSON.stringify({})).toString("base64url"),
111 115 it("reports malformed structured candidates without values", () => {
112 - const dotted = ["agendaFlick", "visibleArea", "yPosition"].join(".");
113 - const malformedUrl = ["https://[bad/?tok", "en=ordinary-value-123456"].join(
114 - "",
115 - );
116 - const malformedBasic = [
117 - "Authorization",
118 - " Basic ordinary-value-123456",
119 - ].join(":");
116 + const dotted = "agendaFlick.visibleArea.yPosition";
117 + const malformedUrl = "https://[bad/?token=ordinary-value-123456";
118 + const malformedBasic = "Authorization: Basic ordinary-value-123456";
120 119 expect(
121 120 __test
122 121 .findStructureAmbiguities(
125 124 .map((item) => item.family)
126 125 .toSorted(),
127 - ).toEqual(["JWT", "URL_QUERY", "BASIC_AUTH"].toSorted());
126 + ).toEqual(["URL_QUERY", "BASIC_AUTH"].toSorted());
130 129 it("rejects malformed structured contexts", () => {
131 - const ordinary = ["ordinary", "metadata", "value", "123456"].join("-");
130 + const ordinary = "ordinary-metadata-value-123456";
132 131 expect(
133 - __test.findSensitiveQuerySpans(
134 - ["https://[bad/?tok", `en=${ordinary}`].join(""),
135 - ),
136 - ).toEqual([]);
137 - expect(
138 - __test.findCookieSpans(["Set-Cook", `ie: session=${ordinary}`].join("")),
139 - ).toEqual([]);
140 - expect(
141 - __test.findHeaderSpans(["Authorization", ` Basic ${ordinary}`].join(":")),
132 + __test.findSensitiveQuerySpans(`https://[bad/?token=${ordinary}`),
142 133 ).toEqual([]);
134 + expect(__test.findCookieSpans(`Set-Cookie: session=${ordinary}`)).toEqual(
135 + [],
136 + );
137 + expect(__test.findHeaderSpans(`Authorization: Basic ${ordinary}`)).toEqual(
138 + [],
139 + );
140 + });
142 + it("parses decoded sensitive query names with exact raw spans", () => {
143 + const raw = "ordinary-query-value-123456";
144 + const url = `https://example.test/path?session=${raw}&co%6Fkie=${raw}&jwt=${raw}&pass=${raw}#fragment`;
145 + const spans = __test.findSensitiveQuerySpans(url);
146 + expect(spans.map((span) => span.value)).toEqual([raw, raw, raw, raw]);
147 + expect(spans.map((span) => url.slice(span.start, span.end))).toEqual([
148 + raw,
149 + raw,
150 + raw,
151 + raw,
152 + ]);
153 + expect(spans.map((span) => span.labels[0].tag)).toEqual([
154 + "session",
155 + "cookie",
156 + "jwt",
157 + "pass",
158 + ]);
145 161 it("uses complete query and cookie names", () => {
146 - const ordinary = ["ordinary", "metadata", "value", "123456"].join("-");
147 - expect(
148 - __test.findSensitiveQuerySpans(["?mon", `key=${ordinary}`].join("")),
149 - ).toEqual([]);
150 - expect(
151 - __test.findCookieSpans(["Cookie", `: keyboard=${ordinary}`].join("")),
152 - ).toEqual([]);
162 + const ordinary = "ordinary-metadata-value-123456";
163 + expect(__test.findSensitiveQuerySpans(`?monkey=${ordinary}`)).toEqual([]);
164 + expect(__test.findCookieSpans(`Cookie: keyboard=${ordinary}`)).toEqual([]);
153 165 expect(
154 166 __test
155 167 .findSensitiveQuerySpans(`?token=${secret}`)
157 169 ).toEqual([secret]);
158 170 expect(
159 171 __test
160 - .findCookieSpans(["Cookie", `: session=${secret}`].join(""))
172 + .findCookieSpans(`Cookie: session=${secret}`)
161 173 .map((span) => span.value),
162 174 ).toEqual([secret]);

extensions/leaks/__tests__/unit.test.ts

Modified
1 1 import { describe, expect, it } from "vitest";
2 2 import { __test } from "../index.ts";
4 -const fixtureSecret = ["shell", "fixture", "secret", "value", "123456"].join(
5 - "-",
6 -);
4 +const fixtureSecret = "shell-fixture-secret-value-123456";
8 6 describe("leaks engine shell", () => {
9 7 it("creates active engine with empty volatile state", () => {
78 76 expect(JSON.stringify(result.value)).not.toContain(sensitiveValue);
79 77 expect(result.redactions).toEqual([
81 - path: "messages[0].content",
79 + path: "${0}[0]{0}",
82 80 labels: ["ALPHA_SECRET"],
83 81 placeholders: [
84 82 expect.stringMatching(/^__LEAK_V1_ALPHA_SECRET_[a-f0-9]{32}__$/),

extensions/leaks/__tests__/ux.test.ts

Modified
114 114 .map((call) => String(call.args[0]))
115 115 .find((item) => item.includes("leaks redacted")) ?? "";
116 116 expect(notice).toContain("leaks redacted 2 provider value(s)");
117 - expect(notice).toContain("• messages[0].content — ENV_KEY");
118 - expect(notice).toContain("• messages[1].content — ENV_KEY");
117 + expect(notice).toContain("• ${0}[0]{0} — ENV_KEY");
118 + expect(notice).toContain("• ${0}[1]{0} — ENV_KEY");
119 119 expect(notice).not.toContain(sensitiveValue);
138 138 .map((call) => String(call.args[0]))
139 139 .find((item) => item.includes("leaks redacted")) ?? "";
140 140 expect(notice).toContain("leaks redacted 2 provider value(s)");
141 - expect(notice).toContain("• input[0].arguments — COOKIE ×2");
141 + expect(notice).toContain("• ${0}[0]{0} — COOKIE ×2");
142 142 expect(notice.split("\n")).toHaveLength(2);
143 143 expect(notice).not.toContain(sessionSecret);
144 144 expect(notice).not.toContain(authSecret);

extensions/leaks/package.json

Modified
17 17 "license": "MIT",
18 18 "peerDependencies": {
19 19 "@earendil-works/pi-ai": "*",
20 - "@earendil-works/pi-coding-agent": "*"
20 + "@earendil-works/pi-coding-agent": "*",
21 + "typebox": "*"
22 23 "devDependencies": {
23 24 "@fast-check/vitest": "^0.4.1",

extensions/leaks/src/detectors.ts

Modified
8 8 group: number;
9 9 kind: SecretSpan["kind"];
10 10 wholeSpan: boolean;
11 + validate?: (match: RegExpMatchArray) => boolean;
13 14 export const builtinRules: BuiltinRule[] = [
86 87 "age-secret",
87 88 "AGE_SECRET_KEY",
88 89 "private-key",
89 - /\bAGE-SECRET-KEY-1[0-9A-Z]{40,}\b/dg,
90 + /\bAGE-SECRET-KEY-1[023456789acdefghjklmnpqrstuvwxyz]{58}\b/dg,
91 92 "private-key",
92 93 true,
94 + (match) => validAgeSecret(match[0]),
94 96 rule(
95 97 "minisign-secret",
96 98 "MINISIGN_SECRET_KEY",
97 99 "private-key",
98 - /untrusted comment:\s*minisign secret key\s+RW[A-Za-z0-9+/]{40,}/dgi,
100 + /^untrusted comment:\s*minisign (?:encrypted )?secret key\r?\n([A-Za-z0-9+/]+={0,2})(?=\r?\n|$|['"\s])/dgim,
100 102 "private-key",
104 + (match) => validBase64(match[1]),
112 115 for (const item of builtinRules) {
113 116 item.regex.lastIndex = 0;
114 117 for (const match of text.matchAll(item.regex)) {
118 + if (item.validate && !item.validate(match)) continue;
115 119 const value = match[item.group] as string;
116 120 const range = match.indices?.[item.group] as [number, number];
117 121 spans.push({
161 165 return spans;
168 +function validAgeSecret(value: string) {
169 + const normalized = value.toLowerCase();
170 + const separator = normalized.lastIndexOf("1");
171 + const hrp = normalized.slice(0, separator);
172 + const charset = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
173 + const data = [...normalized.slice(separator + 1)].map((char) =>
174 + charset.indexOf(char),
175 + );
176 + if (hrp !== "age-secret-key-" || data.some((item) => item < 0)) return false;
177 + const values = [
178 + ...[...hrp].map((char) => char.charCodeAt(0) >> 5),
179 + 0,
180 + ...[...hrp].map((char) => char.charCodeAt(0) & 31),
181 + ...data,
182 + ];
183 + let checksum = 1;
184 + for (const item of values) {
185 + const top = checksum >>> 25;
186 + checksum = (((checksum & 0x1ffffff) << 5) ^ item) >>> 0;
187 + for (let bit = 0; bit < 5; bit++)
188 + if ((top >>> bit) & 1)
189 + checksum =
190 + (checksum ^
191 + [0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3][
192 + bit
193 + ]) >>>
194 + 0;
196 + return checksum === 1;
199 +function validBase64(value: string) {
200 + if (!/^[A-Za-z0-9+/]+={0,2}$/.test(value)) return false;
201 + return Buffer.from(value, "base64").toString("base64") === value;
164 204 function validPuttyLine(value: string) {
165 205 if (!/^[A-Za-z0-9+/]+={0,2}$/.test(value)) return false;
166 206 return Buffer.from(value, "base64").toString("base64") === value;
174 214 group = 0,
175 215 kind: SecretSpan["kind"] = "builtin",
176 216 wholeSpan = false,
217 + validate?: (match: RegExpMatchArray) => boolean,
177 218 ): BuiltinRule {
178 - return { id, tag, family, regex, group, kind, wholeSpan };
219 + return { id, tag, family, regex, group, kind, wholeSpan, validate };
181 222 function label(tag: string): SpanLabel {

extensions/leaks/src/dotenv.ts

Modified
1 -import { existsSync, readdirSync, readFileSync } from "node:fs";
1 +import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
2 2 import path from "node:path";
3 3 import { isWeakValue, sanitizeTag } from "./safety.ts";
4 4 import type { SecretSpan, SpanLabel, WarningRecord } from "./types.ts";
85 85 const match = /^([A-Za-z_][A-Za-z0-9_-]*)\s*=\s*(.*)$/.exec(line);
86 86 if (!match) continue;
87 87 let value = match[2] as string;
88 - if (
89 - (value.startsWith("'") && value.includes("'", 1)) ||
90 - (value.startsWith('"') && value.includes('"', 1))
91 - ) {
88 + if (value.startsWith("'") || value.startsWith('"')) {
89 + if (value.includes("\\")) continue;
92 90 const quote = value[0];
93 - const end = value.indexOf(quote, 1);
94 - value = value.slice(1, end);
95 - } else {
96 - value = value.replace(/\s+#.*$/, "").trim();
97 - }
91 + const closing = value.indexOf(quote, 1);
92 + if (closing < 0 || !/^(?:\s+#.*)?$/.test(value.slice(closing + 1)))
93 + continue;
94 + value = value.slice(1, closing);
95 + } else value = value.replace(/\s+#.*$/, "").trim();
98 96 rows.push({ key: match[1], value });
100 98 return rows;
103 101 export function loadDotenvValues(cwd: string): LearnedValues {
104 102 const pairs: Record<string, string> = {};
105 - for (const file of discoverDotenvFiles(cwd)) {
106 - for (const item of parseDotenv(readFileSync(file, "utf8")))
107 - pairs[item.key] = item.value;
103 + const warnings: WarningRecord[] = [];
104 + let files: string[];
105 + try {
106 + files = discoverDotenvFiles(cwd);
107 + } catch {
108 + return {
109 + values: [],
110 + warnings: [dotenvWarning("dotenv directory is unreadable")],
111 + };
109 - return learnKeyValues(pairs, "dotenv");
113 + for (const file of files) {
114 + try {
115 + if (!statSync(file).isFile()) throw new Error("not a file");
116 + for (const item of parseDotenv(readFileSync(file, "utf8")))
117 + pairs[item.key] = item.value;
118 + } catch {
119 + warnings.push(
120 + dotenvWarning(`dotenv file is unreadable: ${path.basename(file)}`),
121 + );
124 + const learned = learnKeyValues(pairs, "dotenv");
125 + return {
126 + values: learned.values,
127 + warnings: [...warnings, ...learned.warnings],
128 + };
112 131 export function learnEnvironmentValues(
237 256 return isSensitiveKey(normalized);
259 +function dotenvWarning(message: string): WarningRecord {
260 + return { code: "dotenv.read", message, severity: "warning" };
240 263 function normalizeKey(key: string) {
241 264 return key.toUpperCase().replace(/[-]+/g, "_").replace(/_\d+$/, "");

extensions/leaks/src/engine.ts

Modified
110 110 for (const span of selected) {
111 111 const spanLabels = span.labels.map((label) => label.tag);
112 112 const placeholder = this.placeholders.create(span.value, span.labels);
113 - if (!placeholder) continue;
113 + if (!placeholder) {
114 + ambiguities.push({
115 + path: "",
116 + family: this.placeholders.takeMiss() ?? "REDACTION_MISS",
117 + });
118 + continue;
114 120 redacted = `${redacted.slice(0, span.start)}${placeholder}${redacted.slice(span.end)}`;
115 121 placeholders.push(placeholder);
116 122 labels.push(...spanLabels);
157 163 this.placeholders.configure(entries, append);
166 + taintPersistence() {
167 + this.placeholders.taint();
160 170 restoreText(text: string) {
161 171 return this.placeholders.restore(text);
165 175 value: T;
166 176 issue?: { path: string; label: string };
178 + const keyIssue = this.inspectHydratedKeys(value);
179 + if (keyIssue) return { value, issue: keyIssue };
168 180 const restored = this.restoreDeep(value).value;
169 181 const seen = new WeakSet<object>();
170 182 const inspect = (
198 210 seen.delete(item);
199 211 return { path: path || "$", label: "UNSUPPORTED_OBJECT" };
201 - for (const [key, child] of Object.entries(item)) {
202 - const issue = inspect(child, depth + 1, childPath(path, key));
213 + for (const [index, [key, child]] of Object.entries(item).entries()) {
214 + const keyPath = childPath(path, index);
215 + const keyIssue = inspect(key, depth + 1, `${keyPath}.key`);
216 + if (keyIssue) {
217 + seen.delete(item);
218 + return keyIssue;
220 + const issue = inspect(child, depth + 1, keyPath);
203 221 if (issue) {
204 222 seen.delete(item);
205 223 return issue;
215 233 return this.walk(value, "provider", true);
236 + private inspectHydratedKeys(value: unknown) {
237 + const stack = new WeakSet<object>();
238 + const visit = (
239 + item: unknown,
240 + depth: number,
241 + path: string,
242 + ): { path: string; label: string } | undefined => {
243 + if (item === null || typeof item !== "object") return undefined;
244 + if (depth >= 64) return { path: path || "$", label: "TRAVERSAL_DEPTH" };
245 + if (stack.has(item))
246 + return { path: path || "$", label: "TRAVERSAL_CYCLE" };
247 + stack.add(item);
248 + if (Array.isArray(item)) {
249 + for (let index = 0; index < item.length; index++) {
250 + const issue = visit(item[index], depth + 1, `${path}[${index}]`);
251 + if (issue) {
252 + stack.delete(item);
253 + return issue;
256 + stack.delete(item);
257 + return undefined;
259 + if (!isPlainObject(item)) {
260 + stack.delete(item);
261 + return { path: path || "$", label: "UNSUPPORTED_OBJECT" };
263 + const keys = new Set<string>();
264 + for (const [index, [key, child]] of Object.entries(item).entries()) {
265 + const keyPath = childPath(path, index);
266 + const hydrated = this.restoreText(key);
267 + const unresolved = this.placeholders.unresolved(hydrated)[0];
268 + if (unresolved) {
269 + stack.delete(item);
270 + return {
271 + path: `${keyPath}.key`,
272 + label: placeholderLabel(unresolved),
273 + };
275 + if (keys.has(hydrated)) {
276 + stack.delete(item);
277 + return { path: `${keyPath}.key`, label: "KEY_COLLISION" };
279 + keys.add(hydrated);
280 + const issue = visit(child, depth + 1, keyPath);
281 + if (issue) {
282 + stack.delete(item);
283 + return issue;
286 + stack.delete(item);
287 + return undefined;
288 + };
289 + return visit(value, 0, "");
218 292 clear() {
219 - this.placeholders.clear();
293 + const cleared = this.placeholders.clear();
220 294 this.lastProviderRedactionCount = 0;
221 295 this.lastProviderAmbiguityCount = 0;
222 296 this.recentLabels = [];
223 297 this.latestTags = [];
224 298 this.notifiedPlaceholders.clear();
299 + return cleared;
227 302 stats(): EngineStats {
236 311 invalidRegexCount: this.invalidRegexCount,
237 312 learnedCount: this.learned.length,
238 313 mappingCount: this.placeholders.stats().mappingCount,
314 + persistenceEnabled: this.placeholders.stats().persistenceEnabled,
239 315 lastProviderRedactionCount: this.lastProviderRedactionCount,
240 316 totalProviderRedactionCount: this.totalProviderRedactionCount,
241 317 lastProviderAmbiguityCount: this.lastProviderAmbiguityCount,
323 399 const source = value as Record<string, unknown>;
324 400 const copy: Record<string, unknown> = {};
325 401 seen.set(value, copy);
326 - for (const [key, item] of Object.entries(source))
327 - copy[key] = visit(item, depth + 1, childPath(trace, key));
402 + for (const [index, [key, item]] of Object.entries(source).entries()) {
403 + const keyResult = restore
404 + ? this.restoreText(key)
405 + : this.redactText(key, origin).text;
406 + Object.defineProperty(copy, keyResult, {
407 + value: visit(item, depth + 1, childPath(trace, index)),
408 + enumerable: true,
409 + configurable: true,
410 + writable: true,
411 + });
328 413 if (Object.keys(copy).some((key) => copy[key] !== source[key]))
329 414 changed = true;
330 415 return copy;
353 438 return match?.[1]?.replace(/_+$/, "") ?? "UNKNOWN";
356 -function childPath(parent: string, key: string) {
357 - if (/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key))
358 - return parent ? `${parent}.${key}` : key;
359 - return `${parent}[${JSON.stringify(key)}]`;
441 +function childPath(parent: string, index: number) {
442 + return `${parent || "$"}{${index}}`;

extensions/leaks/src/pi.ts

Modified
1 +import path from "node:path";
1 2 import {
2 3 type ExtensionAPI,
3 4 type ExtensionContext,
10 11 export default function leaks(pi: ExtensionAPI) {
11 12 const engine = new LeaksEngine();
12 13 const reportedWarnings = new Set<string>();
14 + const persistence = { tainted: false };
14 16 pi.on("session_start", async (_event, ctx) => {
15 - rebuildPersistence(engine, pi, ctx);
17 + rebuildPersistence(engine, pi, ctx, persistence);
16 18 engine.reload(ctx.cwd, readSettings(ctx.cwd), process.env);
17 19 notifyInMemorySession(ctx, reportedWarnings);
18 20 flushWarnings(engine, ctx, reportedWarnings);
19 - if (ctx.hasUI) ctx.ui.setStatus("leaks", "leaks on | last 0");
21 + if (ctx.hasUI)
22 + ctx.ui.setStatus(
23 + "leaks",
24 + `leaks ${engine.stats().persistenceEnabled ? "on" : "degraded"} | last 0`,
25 + );
22 28 pi.on("session_tree", async (_event, ctx) => {
23 - rebuildPersistence(engine, pi, ctx);
29 + rebuildPersistence(engine, pi, ctx, persistence);
24 30 flushWarnings(engine, ctx, reportedWarnings);
31 37 pi.on("before_provider_request", async (event, ctx) => {
32 38 const result = engine.redactDeep(event.payload, "provider");
33 - flushWarnings(engine, ctx, reportedWarnings);
34 - updateProviderUi(ctx, engine, result);
39 + try {
40 + flushWarnings(engine, ctx, reportedWarnings);
41 + updateProviderUi(ctx, engine, result);
42 + } catch {
43 + // Diagnostics must never compromise the authoritative redacted return.
44 + }
35 45 return result.value;
38 - pi.on("message_update", async (event, ctx) => {
48 + pi.on("message_update", async (event) => {
39 49 restoreEventProperty(
40 50 engine,
41 51 event as unknown as Record<string, unknown>,
42 52 "message",
44 - warnUnknownLocal(engine, event.message, ctx, "assistant message");
47 56 pi.on("tool_call", async (event, ctx) => {
57 + if (isLeaksSourceMutation(event, ctx.cwd)) return;
48 58 const record = event as unknown as Record<string, unknown>;
49 59 const current = record.input;
50 60 const result = engine.hydrateToolInput(current);
79 89 engine,
80 90 event as unknown as Record<string, unknown>,
82 - warnUnknownLocal(engine, event.content, ctx, "tool result");
83 - warnUnknownLocal(engine, event.details, ctx, "tool result");
92 + warnUnknownLocal(
93 + engine,
94 + event.content,
95 + ctx,
96 + "tool result",
97 + reportedWarnings,
98 + );
99 + warnUnknownLocal(
100 + engine,
101 + event.details,
102 + ctx,
103 + "tool result",
104 + reportedWarnings,
105 + );
84 106 return patch;
87 109 pi.on("message_end", async (event, ctx) => {
88 110 const restored = engine.restoreDeep(event.message).value;
89 - warnUnknownLocal(engine, restored, ctx, "assistant message");
111 + warnUnknownLocal(
112 + engine,
113 + restored,
114 + ctx,
115 + "assistant message",
116 + reportedWarnings,
117 + );
90 118 return { message: restored };
99 127 return;
101 129 if (command === "reload") {
102 - rebuildPersistence(engine, pi, ctx);
130 + rebuildPersistence(engine, pi, ctx, persistence);
103 131 engine.reload(ctx.cwd, readSettings(ctx.cwd), process.env);
104 132 flushWarnings(engine, ctx, reportedWarnings);
105 133 notify(ctx, "leaks reloaded", "info");
116 144 return;
119 - engine.clear();
147 + const cleared = persistence.tainted ? false : engine.clear();
120 148 flushWarnings(engine, ctx, reportedWarnings);
121 - notify(ctx, "leaks cleared", "info");
149 + notify(
150 + ctx,
151 + cleared
152 + ? "leaks cleared"
153 + : "leaks clear failed; mappings kept active",
154 + cleared ? "info" : "error",
155 + );
122 156 return;
124 158 if (command.startsWith("test ")) {
139 173 result: RedactionResult,
142 - if (result.ambiguities.length > 0)
143 - notify(ctx, formatAmbiguities(result.ambiguities), "warning");
176 + const actionable = result.ambiguities.filter((item) =>
177 + /^(?:PERSISTENCE|MAPPING|PLACEHOLDER|REDACTION)/.test(item.family),
178 + );
179 + if (actionable.length > 0)
180 + notify(ctx, formatAmbiguities(actionable), "warning");
144 181 if (!ctx.hasUI) return;
145 - ctx.ui.setStatus("leaks", `leaks on | last ${result.count}`);
182 + ctx.ui.setStatus(
183 + "leaks",
184 + `leaks ${engine.stats().persistenceEnabled ? "on" : "degraded"} | last ${result.count}`,
185 + );
146 186 if (result.count === 0) return;
147 187 const newPlaceholders = result.redactions
148 188 .flatMap((r) => r.placeholders)
160 200 "info",
162 - } catch (error) {
163 - if (!isStaleContextError(error)) throw error;
202 + } catch {
203 + // Stale or broken UI diagnostics never affect provider redaction.
167 -function isStaleContextError(error: unknown) {
168 - return (
169 - error instanceof Error && error.message.includes("extension ctx is stale")
170 - );
173 207 function restoreEventProperty(
174 208 engine: LeaksEngine,
175 209 event: Record<string, unknown>,
211 245 Object.assign(target, source);
248 +const LEAKS_EXTENSION_ROOT = path.resolve(import.meta.dirname, "..");
250 +function isLeaksSourceMutation(event: unknown, cwd: string) {
251 + if (!isPlainObject(event) || !isPlainObject(event.input)) return false;
252 + if (event.toolName !== "write" && event.toolName !== "edit") return false;
253 + if (typeof event.input.path !== "string") return false;
254 + const target = path.resolve(cwd, event.input.path);
255 + const relative = path.relative(LEAKS_EXTENSION_ROOT, target);
256 + return (
257 + relative === "" ||
258 + (!relative.startsWith("..") && !path.isAbsolute(relative))
259 + );
214 262 function warnUnknownLocal(
215 263 engine: LeaksEngine,
216 264 value: unknown,
217 265 ctx: ExtensionContext,
218 266 surface: string,
267 + reported: Set<string>,
220 269 if (value === undefined) return;
221 270 const issue = engine.hydrateToolInput(value).issue;
225 274 issue.label === "UNSUPPORTED_OBJECT"
227 276 return;
277 + const key = `unresolved:${surface}:${issue.path}:${issue.label}`;
278 + if (reported.has(key)) return;
279 + reported.add(key);
228 280 notify(
230 282 `unresolved leaks placeholder in ${surface} at ${issue.path} (${issue.label})`,
236 288 engine: LeaksEngine,
237 289 pi: ExtensionAPI,
238 290 ctx: ExtensionContext,
291 + state: { tainted: boolean },
240 293 const entries = (ctx.sessionManager?.getBranch() ?? [])
241 294 .filter((entry) => entry.type === "custom")
244 297 customType: entry.customType,
245 298 data: entry.data,
247 - engine.configurePersistence(entries, (customType, data) =>
248 - pi.appendEntry(customType, data),
249 - );
300 + engine.configurePersistence(entries, (customType, data) => {
301 + try {
302 + pi.appendEntry(customType, data);
303 + } catch (error) {
304 + state.tainted = true;
305 + throw error;
307 + });
308 + if (state.tainted) engine.taintPersistence();
252 311 function notifyInMemorySession(ctx: ExtensionContext, reported: Set<string>) {
279 338 message: string,
280 339 severity: "info" | "warning" | "error",
282 - if (ctx.hasUI) ctx.ui.notify(message, severity);
283 - else console.error(`[leaks] ${message.replace(/\s*\n\s*/g, " | ")}`);
341 + try {
342 + if (ctx.hasUI) ctx.ui.notify(message, severity);
343 + else console.error(`[leaks] ${message.replace(/\s*\n\s*/g, " | ")}`);
344 + } catch {
345 + // Diagnostics are best-effort and never alter extension behavior.
286 349 function readSettings(cwd: string) {
303 366 const key = `${item.path || "$"} — ${item.family}`;
304 367 counts.set(key, (counts.get(key) ?? 0) + 1);
369 + const rows = [...counts]
370 + .slice(0, 8)
371 + .map(([key, count]) => `• ${key}${count > 1 ? ` ×${count}` : ""}`);
372 + if (counts.size > rows.length)
373 + rows.push(`• ${counts.size - rows.length} more location(s)`);
306 374 return [
307 375 `leaks kept ${ambiguities.length} ambiguous candidate(s) visible`,
308 - ...[...counts].map(
309 - ([key, count]) => `• ${key}${count > 1 ? ` ×${count}` : ""}`,
310 - ),
376 + ...rows,
311 377 ].join("\n");
349 415 function formatStatus(engine: LeaksEngine) {
350 416 const stats = engine.stats();
351 417 return [
352 - "leaks on",
418 + `leaks ${stats.persistenceEnabled ? "on" : "degraded"}`,
353 419 `built-in rules: ${stats.builtInRuleCount}`,
354 420 `custom regex: ${stats.customRegexCount}`,
355 421 `regex warnings: ${stats.regexWarningCount}`,

extensions/leaks/src/placeholders.ts

Modified
69 69 private readonly placeholderToSecret = new Map<string, string>();
70 70 private warnedCap = false;
71 71 private enabled = true;
72 + private lastMiss?: string;
73 74 constructor(options: PlaceholderStoreOptions = {}) {
74 75 this.digestOverride = options.digest;
88 89 this.disable("unsupported leaks generation version");
90 91 if (generationIndex < 0) {
91 - if (this.enabled) this.startGeneration();
92 + if (
93 + entries.some((entry) => entry.customType.startsWith("leaks-mapping-"))
94 + )
95 + this.disable("mapping record has no generation");
96 + else if (this.enabled) this.startGeneration();
92 97 return;
94 99 const generation = parseGeneration(entries[generationIndex].data);
117 122 continue;
119 124 const existing = this.placeholderToSecret.get(record.placeholder);
120 - if (existing !== undefined && existing !== value) {
125 + const reverse = this.secretToPlaceholder.get(value);
126 + if (
127 + (existing !== undefined && existing !== value) ||
128 + (reverse !== undefined && reverse !== record.placeholder)
129 + ) {
121 130 this.disable("conflicting leaks mapping record");
122 131 continue;
133 + if (this.placeholderToSecret.size >= this.cap) {
134 + this.disable("persisted mapping cap exceeded");
135 + continue;
124 137 this.placeholderToSecret.set(record.placeholder, value);
125 138 this.secretToPlaceholder.set(value, record.placeholder);
129 142 create(value: string, labels: SpanLabel[]): string | undefined {
143 + this.lastMiss = undefined;
130 144 const known = this.secretToPlaceholder.get(value);
131 145 if (known) return known;
132 - if (!this.enabled || !this.generation || !this.encryptionKey)
146 + if (!this.enabled || !this.generation || !this.encryptionKey) {
147 + this.lastMiss = "PERSISTENCE_DISABLED";
133 148 return undefined;
134 150 if (this.secretToPlaceholder.size >= this.cap) {
151 + this.lastMiss = "MAPPING_CAP";
135 152 this.warnCap();
136 153 return undefined;
138 155 const placeholder = this.format(value, labels);
139 156 const collision = this.placeholderToSecret.get(placeholder);
140 157 if (collision !== undefined && collision !== value) {
158 + this.lastMiss = "PLACEHOLDER_COLLISION";
141 159 this.warn(
142 160 "placeholder.collision",
143 161 "placeholder collision; value left visible",
149 167 if (!this.append) throw new Error("missing persistence sink");
150 168 this.append(MAPPING_TYPE, record);
151 169 } catch {
170 + this.lastMiss = "PERSISTENCE_FAILURE";
152 171 this.disable("mapping persistence failed");
153 172 return undefined;
174 193 return current;
196 + takeMiss() {
197 + const miss = this.lastMiss;
198 + this.lastMiss = undefined;
199 + return miss;
177 202 unresolved(text: string) {
178 203 return [...text.matchAll(ANY_PLACEHOLDER_RE)].map((match) => match[0]);
185 210 this.append(GENERATION_TYPE, generation);
186 211 this.reset();
187 212 this.activate(generation);
213 + return true;
188 214 } catch {
189 215 this.disable("generation persistence failed; mappings kept active");
216 + return false;
220 + taint(message = "persistence previously failed") {
221 + this.disable(message);
193 224 stats() {
194 225 return {
195 226 mappingCount: this.secretToPlaceholder.size,
224 255 this.placeholderToSecret.clear();
225 256 this.warnedCap = false;
226 257 this.enabled = true;
258 + this.lastMiss = undefined;
229 261 private format(value: string, labels: SpanLabel[]) {
239 271 const digest =
240 272 this.digestOverride?.(value) ??
241 273 createHmac("sha256", this.hmacKey as Buffer)
242 - .update(value)
274 + .update(encodeValue(value))
243 275 .digest("hex");
244 276 const hmac32 = digest
245 277 .toLowerCase()
261 293 cipher.setAAD(aad(generation.generationId, placeholder));
262 294 const ciphertext = Buffer.concat([
263 - cipher.update(value, "utf8"),
295 + cipher.update(encodeValue(value)),
264 296 cipher.final(),
266 298 return {
284 316 decipher.setAAD(aad(record.generationId, record.placeholder));
285 317 decipher.setAuthTag(Buffer.from(record.authTag, "base64url"));
286 - return new TextDecoder("utf-8", { fatal: true }).decode(
287 - Buffer.concat([
288 - decipher.update(Buffer.from(record.ciphertext, "base64url")),
289 - decipher.final(),
290 - ]),
291 - );
318 + const bytes = Buffer.concat([
319 + decipher.update(Buffer.from(record.ciphertext, "base64url")),
320 + decipher.final(),
321 + ]);
322 + if (bytes.length % 2 !== 0) return undefined;
323 + return bytes.toString("utf16le");
292 324 } catch {
293 325 return undefined;
348 +function encodeValue(value: string) {
349 + return Buffer.from(value, "utf16le");
316 352 function newGeneration(): GenerationRecord {
317 353 return {
318 354 version: 1,

extensions/leaks/src/structures.ts

Modified
5 5 const URL_CANDIDATE_RE = /\b[a-z][a-z0-9+.-]*:\/\/[^\s'"`]+/dgi;
6 6 const URL_CREDENTIAL_RE =
7 7 /\b[a-z][a-z0-9+.-]*:\/\/([^\s:@/]*)?:([^\s@/]+)@[^\s'"`]+/dgi;
8 -const QUERY_RE =
9 - /([?&])([A-Za-z0-9_-]*(?:token|key|secret|password|auth)[A-Za-z0-9_-]*)=([^&#\s'"`]+)/dgi;
8 +const QUERY_RE = /([?&])([^=&#\s'"`]+)=([^&#\s'"`]+)/dgi;
10 9 const AUTH_RE =
11 10 /(?:^|[\n\r\s'"`])Authorization:\s*(Bearer|Basic)\s+([^\s'"`]+)/dgi;
12 11 const X_API_RE = /(?:^|[\n\r\s'"`])(X-API-Key|Api-Key):\s*([^\s'"`]+)/dgi;
70 69 export function findStructureAmbiguities(text: string) {
71 70 const ambiguities: Array<{ family: string; start: number }> = [];
72 - for (const match of text.matchAll(JWT_RE))
73 - if (findJwtSpans(match[0]).length === 0)
71 + for (const match of text.matchAll(JWT_RE)) {
72 + const header = decodeJsonObject(match[0].split(".")[0] ?? "");
73 + if (
74 + header &&
75 + typeof header.alg === "string" &&
76 + header.alg.length > 0 &&
77 + findJwtSpans(match[0]).length === 0
78 + )
74 79 ambiguities.push({ family: "JWT", start: match.index as number });
80 + }
75 81 for (const match of text.matchAll(AUTH_RE))
77 83 match[1]?.toLowerCase() === "basic" &&
80 86 ambiguities.push({ family: "BASIC_AUTH", start: match.index as number });
81 87 for (const match of text.matchAll(URL_CANDIDATE_RE)) {
82 - if (!/[?&](?:token|secret|password|api[_-]?key)=/i.test(match[0])) continue;
88 + if (!candidateHasSensitiveQueryName(match[0])) continue;
83 89 if (findSensitiveQuerySpans(match[0]).length === 0)
84 90 ambiguities.push({ family: "URL_QUERY", start: match.index as number });
124 130 export function findSensitiveQuerySpans(text: string): SecretSpan[] {
125 131 const spans: SecretSpan[] = [];
126 - for (const match of text.matchAll(QUERY_RE)) {
127 - if (!queryHasParsedContext(text, match.index as number)) continue;
128 - const name = match[2] as string;
129 - const value = match[3] as string;
130 - if (!isSensitiveKey(name) || isWeakValue(value)) continue;
132 + for (const candidate of text.matchAll(URL_CANDIDATE_RE)) {
133 + try {
134 + new URL(candidate[0]);
135 + } catch {
136 + continue;
138 + const question = candidate[0].indexOf("?");
139 + if (question < 0) continue;
140 + const fragment = candidate[0].indexOf("#", question);
141 + const end = fragment < 0 ? candidate[0].length : fragment;
131 142 spans.push(
132 - makeSpan(
133 - match,
134 - 3,
135 - value,
136 - [label(match[2] as string, "structure")],
137 - "structure",
143 + ...parsedQuerySpans(
144 + candidate[0].slice(question + 1, end),
145 + (candidate.index as number) + question + 1,
146 + ),
147 + );
149 + const trimmedStart = text.search(/\S/);
150 + if (trimmedStart >= 0 && text[trimmedStart] === "?") {
151 + const endMatch = /[\s'"`]/.exec(text.slice(trimmedStart));
152 + const end = endMatch
153 + ? trimmedStart + (endMatch.index as number)
154 + : text.length;
155 + const fragment = text.indexOf("#", trimmedStart);
156 + const queryEnd = fragment >= 0 && fragment < end ? fragment : end;
157 + spans.push(
158 + ...parsedQuerySpans(
159 + text.slice(trimmedStart + 1, queryEnd),
160 + trimmedStart + 1,
331 354 return { tag, priority: source === "builtin" ? 40 : 20, source };
334 -function queryHasParsedContext(text: string, index: number) {
335 - if (text.slice(0, index).trim().length === 0 && text[index] === "?")
336 - return true;
337 - for (const candidate of text.matchAll(URL_CANDIDATE_RE)) {
338 - const start = candidate.index as number;
339 - if (index < start || index >= start + candidate[0].length) continue;
340 - try {
341 - new URL(candidate[0]);
342 - return true;
343 - } catch {
344 - return false;
345 - }
357 +function candidateHasSensitiveQueryName(candidate: string) {
358 + const question = candidate.indexOf("?");
359 + if (question < 0) return false;
360 + return [...new URLSearchParams(candidate.slice(question + 1))].some(
361 + ([name]) => isSensitiveKey(name),
362 + );
365 +function parsedQuerySpans(query: string, offset: number): SecretSpan[] {
366 + const parsed = [...new URLSearchParams(query)];
367 + const rawPairs: Array<{ pair: string; start: number }> = [];
368 + let cursor = 0;
369 + for (const pair of query.split("&")) {
370 + if (pair.length > 0) rawPairs.push({ pair, start: cursor });
371 + cursor += pair.length + 1;
347 - return false;
373 + if (parsed.length !== rawPairs.length) return [];
374 + const spans: SecretSpan[] = [];
375 + for (let index = 0; index < parsed.length; index++) {
376 + const [name, decodedValue] = parsed[index];
377 + const { pair, start } = rawPairs[index];
378 + const equals = pair.indexOf("=");
379 + if (equals <= 0) return [];
380 + const pairEntries = [...new URLSearchParams(pair)];
381 + if (
382 + pairEntries.length !== 1 ||
383 + pairEntries[0][0] !== name ||
384 + pairEntries[0][1] !== decodedValue
386 + return [];
387 + const rawValue = pair.slice(equals + 1);
388 + if (!isSensitiveKey(name) || isWeakValue(rawValue)) continue;
389 + const valueStart = offset + start + equals + 1;
390 + spans.push({
391 + start: valueStart,
392 + end: valueStart + rawValue.length,
393 + value: rawValue,
394 + labels: [label(name, "structure")],
395 + kind: "structure",
396 + confidence: 85,
397 + wholeSpan: false,
398 + });
400 + return spans;
350 403 function validBasic(value: string | undefined) {

extensions/leaks/src/types.ts

Modified
76 76 invalidRegexCount: number;
77 77 learnedCount: number;
78 78 mappingCount: number;
79 + persistenceEnabled: boolean;
79 80 lastProviderRedactionCount: number;
80 81 totalProviderRedactionCount: number;
81 82 lastProviderAmbiguityCount: number;

package-lock.json

Modified
221 221 "peerDependencies": {
222 222 "@earendil-works/pi-ai": "*",
223 - "@earendil-works/pi-coding-agent": "*"
223 + "@earendil-works/pi-coding-agent": "*",
224 + "typebox": "*"
226 227 "extensions/llmiterate": {

scripts/extensions.mjs

Modified
427 427 `cross-extension relative import ${spec} in ${rel(file, ext)}`,
430 - if (SECRET_RE.test(text) && !isSecretScanIgnored(file, ignores, root))
430 + if (
431 + !file.split(/[\\/]/).includes("__tests__") &&
432 + SECRET_RE.test(text) &&
433 + !isSecretScanIgnored(file, ignores, root)
431 435 err(errors, ext, `possible secret in ${rel(file, ext)}`);
433 437 for (const dep of [...packages].filter((p) => PI_PEERS.has(p)).sort())

scripts/run_leaks_fuzz.mjs

Modified
14 14 if (process.argv[1] === fileURLToPath(import.meta.url)) {
15 - const timeout = Number(process.env.LEAKS_FUZZ_TIMEOUT_MS ?? 120_000);
16 - const args = process.env.LEAKS_FUZZ_TEST_HANG
15 + const testing = process.env.LEAKS_FUZZ_TEST_HANG === "1";
16 + const requested = Number(process.env.LEAKS_FUZZ_TIMEOUT_MS ?? 120_000);
17 + const timeout = testing
18 + ? Math.max(
19 + 1,
20 + Math.min(Number.isFinite(requested) ? requested : 120_000, 120_000),
21 + )
22 + : 120_000;
23 + const args = testing
17 24 ? ["-e", "setInterval(() => {}, 1000)"]
19 26 "node_modules/vitest/vitest.mjs",