pi-ext
bugabingas pi extensions
owned by bugabinga
fix(leaks): reduce noisy provider redactions
973dbf7e8037d73dda2dcefe1682916e09f4b95c
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
Browse filesCompare with HEAD
Changed files (7)
177 177 and notifications without exposing secrets
178 178 - Report leaks provider redaction paths, labels, and placeholders in safe
179 179 metadata and show unbounded path/label details in redaction notifications
180 +- Suppress leaks assignment-span false positives on common programmer-noun keys
181 + (`seed`, `id`, `name`, `count`, `type`, `value`, `path`, `key`, `ts`, `time`,
182 + `date`, `idx`, `mode`, `flag`, `opts`, `params`, `args`, `options`, `label`,
183 + `field`, `tag`); heuristic only, does not affect dotenv/env learning
184 +- Deduplicate leaks `ctx.ui.notify` per-process via `notifiedPlaceholders` so
185 + re-notification of the same redacted value across requests is suppressed
extensions/leaks/__tests__/detectors.test.ts
Modifiedextensions/leaks/__tests__/structures.test.ts
Modified103 103 /^__LEAK_OPENSSH_PRIVATE_KEY_[a-f0-9]{12}__$/,
107 + it(
"skips assignment keys that are common programming nouns", ()
=> {
108 + const longValue
= "abcdef1234567890";
109 + for (
const key
of [
135 + const text
= `${key}=${longValue}`;
137 + __test.
findAssignmentSpans(text),
138 + `expected ${key}=<value> to produce zero spans`,
143 + it(
"stoplist does not block keys that overlap with SENSITIVE", ()
=> {
144 + const longValue
= "abcdef1234567890";
147 + __test.
findAssignmentSpans(
`KEY=${longValue}`).
length,
148 + ).
toBeGreaterThan(
0);
151 + __test.
findAssignmentSpans(
`TOKEN=${longValue}`).
length,
152 + ).
toBeGreaterThan(
0);
155 + it(
"stoplist is case-insensitive for common programming nouns", ()
=> {
156 + const longValue
= "abcdef1234567890";
157 + for (
const key
of [
"Seed",
"SEED",
"Id",
"ID",
"Name",
"Type"]) {
158 + const text
= `${key}=${longValue}`;
160 + __test.
findAssignmentSpans(text),
161 + `expected ${key}=<value> to produce zero spans`,
extensions/leaks/__tests__/ux.test.ts
Modified 33 + it(
"does not re-notify the same redacted value across provider turns",
async ()
=> {
34 + t
= await createTestSession({ extensions: [
extPath()] });
35 + await t.session.extensionRunner.
emitBeforeProviderRequest({ text: secret });
36 + await t.session.extensionRunner.
emitBeforeProviderRequest({ text: secret });
37 + await t.session.extensionRunner.
emitBeforeProviderRequest({ text: secret });
39 + const notices
= t.events
40 + .
uiCallsFor(
"notify")
41 + .
map((call)
=> String(call.args[
0]));
43 + notices.
filter((notice)
=> notice.
includes(
"leaks redacted")),
47 + it(
"re-notifies after /leaks clear and after reload",
async ()
=> {
48 + t
= await createTestSession({
49 + extensions: [
extPath()],
50 + mockUI: { confirm:
true },
53 + t.session.extensionRunner.extensions[
0].commands.
get(
"leaks");
54 + const ctx
= t.session.extensionRunner.
createContext();
56 + await t.session.extensionRunner.
emitBeforeProviderRequest({ text: secret });
57 + await t.session.extensionRunner.
emitBeforeProviderRequest({ text: secret });
58 + await command.
handler(
"clear", ctx);
59 + await t.session.extensionRunner.
emitBeforeProviderRequest({ text: secret });
61 + const notices
= t.events
62 + .
uiCallsFor(
"notify")
63 + .
map((call)
=> String(call.args[
0]));
65 + notices.
filter((notice)
=> notice.
includes(
"leaks redacted")),
69 + it(
"notice only lists new redactions when an old secret is repeated alongside a new one",
async ()
=> {
70 + const oldSecret
= "tdd-old-secret-value-" + "o".
repeat(
32);
71 + const newSecret
= "tdd-new-secret-value-" + "n".
repeat(
32);
72 + t
= await createTestSession({
73 + extensions: [
extPath()],
75 + [
"OLD_" + "SECRET"]: oldSecret,
76 + [
"NEW_" + "SECRET"]: newSecret,
80 + await t.session.extensionRunner.
emitBeforeProviderRequest({
81 + text:
`first ${oldSecret}`,
83 + await t.session.extensionRunner.
emitBeforeProviderRequest({
84 + text:
`again ${oldSecret} and now ${newSecret}`,
87 + const leakNotices
= t.events
88 + .
uiCallsFor(
"notify")
89 + .
map((call)
=> String(call.args[
0]))
90 + .
filter((notice)
=> notice.
includes(
"leaks redacted"));
91 + expect(leakNotices).
toHaveLength(
2);
92 + expect(leakNotices[
1]).
toContain(
"leaks redacted 1 provider value(s)");
93 + expect(leakNotices[
1]).
toContain(
"ENV_KEY");
94 + expect(leakNotices[
1]).not.
toContain(oldSecret);
95 + expect(leakNotices[
1]).not.
toContain(newSecret);
33 98 it(
"notification reports every provider redaction path and label",
async ()
=> {
34 99 const sensitiveValue
= "tdd-secret-value-" + "x".
repeat(
32);
35 100 t
= await createTestSession({
extensions/leaks/src/engine.ts
Modified 47 47 private totalProviderRedactionCount
= 0;
48 48 private
recentLabels: string[]
= [];
49 49 private
latestTags: string[]
= [];
50 + readonly notifiedPlaceholders
= new Set<
string>();
51 52 constructor(options: LeaksEngineOptions
= {}) {
52 53 this.settings
= { regex: options.settings?.regex
?? [] };
59 60 this.settings
= { regex: settings.regex };
60 61 this.
compileSettings();
61 62 this.
learn(cwd, env);
63 + this.notifiedPlaceholders.
clear();
144 146 this.lastProviderRedactionCount
= 0;
145 147 this.recentLabels
= [];
146 148 this.latestTags
= [];
149 + this.notifiedPlaceholders.
clear();
149 152 stats(): EngineStats {
extensions/leaks/src/pi.ts
Modified 20 20 const result
= engine.
redactDeep(
event.payload,
"provider");
22 22 ctx.ui.
setStatus(
"leaks",
`leaks on | last ${result.count}`);
23 - if (result.count
> 0) ctx.ui.
notify(
formatNotice(result),
"info");
23 + if (result.count
> 0) {
24 + const newPlaceholders
= result.redactions
25 + .
flatMap((r)
=> r.placeholders)
26 + .
filter((p)
=> !engine.notifiedPlaceholders.
has(p));
27 + if (newPlaceholders.
length > 0) {
28 + for (
const p
of newPlaceholders) engine.notifiedPlaceholders.
add(p);
29 + const freshRedactions
= result.redactions.
filter((r)
=> 30 + r.placeholders.
some((p)
=> newPlaceholders.
includes(p)),
34 + count: newPlaceholders.
length,
35 + redactions: freshRedactions,
25 42 return result.
value;
89 106 redactions:
Array<{
path: string;
labels: string[] }
>;
108 + const grouped
= new Map<
string,
number>();
109 + for (
const redaction
of result.redactions) {
110 + const key
= `${redaction.path}: ${redaction.labels.join(", ")}`;
111 + grouped.
set(key, (grouped.
get(key)
?? 0)
+ 1);
92 114 `leaks redacted ${result.count} provider value(s)`,
93 - ...result.redactions.
map(
94 - (redaction)
=> `${redaction.path}: ${redaction.labels.join(", ")}`,
115 + ...[
...grouped.
entries()].
map(([line, n])
=> 116 + n
> 1 ? `${line} (×${n})` : line,
extensions/leaks/src/structures.ts
Modified 9 9 const AUTH_RE
= /Authorization:\s*(Bearer|Basic)\s+([^\s'"`]+)/dgi;
10 10 const X_API_RE
= /\b(X-API-Key|X-Api-Key|Api-Key):\s*([^\s'"`]+)/dg;
11 11 const COOKIE_LINE_RE
= /Cookie:\s*([^\n]+)/dgi;
18 +const ASSIGNMENT_STOP_KEYS
= new Set([
13 46 /(?:^|[\n\r\s{,;])(?:export\s+)?["']?([A-Za-z_][A-Za-z0-9_-]*)["']?\s*(?:=|:|=>)\s*["']?([^\s'",;}]{1,512})["']?/dgi;
14 47 const XML_RE
= /<([A-Za-z_][A-Za-z0-9_-]*)>([^<]{1,512})<\/\1>/dgi;
119 152 for (
const match
of text.
matchAll(regex)) {
120 153 const key
= match[
1]
as string;
121 154 const value
= match[
2]
as string;
155 + if (ASSIGNMENT_STOP_KEYS.
has(key.
toLowerCase()))
continue;
122 156 if (
!isSensitiveKey(key))
continue;
123 157 if (
isWeakValue(value)
&& !highConfidenceSecretShape(value))
continue;