failproofai 1.0.4-beta.7 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.next/standalone/.next/BUILD_ID +1 -1
- package/.next/standalone/.next/build-manifest.json +5 -5
- package/.next/standalone/.next/prerender-manifest.json +4 -4
- package/.next/standalone/.next/required-server-files.json +1 -1
- package/.next/standalone/.next/server/app/_global-error/page/build-manifest.json +2 -2
- package/.next/standalone/.next/server/app/_global-error/page/server-reference-manifest.json +1 -1
- package/.next/standalone/.next/server/app/_global-error/page.js +2 -2
- package/.next/standalone/.next/server/app/_global-error/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/_global-error.html +1 -1
- package/.next/standalone/.next/server/app/_global-error.rsc +7 -7
- package/.next/standalone/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +6 -6
- package/.next/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +7 -7
- package/.next/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_not-found/page/build-manifest.json +2 -2
- package/.next/standalone/.next/server/app/_not-found/page/server-reference-manifest.json +1 -1
- package/.next/standalone/.next/server/app/_not-found/page.js +2 -2
- package/.next/standalone/.next/server/app/_not-found/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/_not-found.html +1 -1
- package/.next/standalone/.next/server/app/_not-found.rsc +14 -14
- package/.next/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +14 -14
- package/.next/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +13 -13
- package/.next/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/api/audit/invite/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/audit/run/route.js +4 -4
- package/.next/standalone/.next/server/app/api/audit/run/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/audit/status/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/auth/login-request/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/auth/login-verify/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/auth/logout/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/auth/status/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/download/[project]/[session]/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/audit/page/build-manifest.json +2 -2
- package/.next/standalone/.next/server/app/audit/page/server-reference-manifest.json +4 -37
- package/.next/standalone/.next/server/app/audit/page.js +2 -2
- package/.next/standalone/.next/server/app/audit/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/audit/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/index.html +1 -1
- package/.next/standalone/.next/server/app/index.rsc +14 -14
- package/.next/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +13 -13
- package/.next/standalone/.next/server/app/index.segments/_full.segment.rsc +14 -14
- package/.next/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/page/build-manifest.json +2 -2
- package/.next/standalone/.next/server/app/page/server-reference-manifest.json +1 -1
- package/.next/standalone/.next/server/app/page.js +2 -2
- package/.next/standalone/.next/server/app/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/policies/page/build-manifest.json +2 -2
- package/.next/standalone/.next/server/app/policies/page/server-reference-manifest.json +14 -14
- package/.next/standalone/.next/server/app/policies/page.js +4 -4
- package/.next/standalone/.next/server/app/policies/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/policies/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/project/[name]/page/build-manifest.json +2 -2
- package/.next/standalone/.next/server/app/project/[name]/page/server-reference-manifest.json +1 -1
- package/.next/standalone/.next/server/app/project/[name]/page.js +3 -3
- package/.next/standalone/.next/server/app/project/[name]/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/project/[name]/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page/build-manifest.json +2 -2
- package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page/react-loadable-manifest.json +2 -2
- package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page/server-reference-manifest.json +2 -2
- package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page.js +4 -4
- package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/projects/page/build-manifest.json +2 -2
- package/.next/standalone/.next/server/app/projects/page/server-reference-manifest.json +1 -1
- package/.next/standalone/.next/server/app/projects/page.js +3 -3
- package/.next/standalone/.next/server/app/projects/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/projects/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/settings/page/build-manifest.json +2 -2
- package/.next/standalone/.next/server/app/settings/page/server-reference-manifest.json +4 -15
- package/.next/standalone/.next/server/app/settings/page.js +4 -4
- package/.next/standalone/.next/server/app/settings/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/settings/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/chunks/{[externals]__0v1hz15._.js → [externals]__0-9ti7z._.js} +1 -1
- package/.next/standalone/.next/server/chunks/{[externals]__1nb206a._.js → [externals]__0u3wrvq._.js} +1 -1
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__0o07qi9._.js +1 -1
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__0rv7m0k._.js +1 -1
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__17g9wh7._.js +1 -1
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__1legmza._.js +1 -1
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__1p-qi2t._.js +1 -1
- package/.next/standalone/.next/server/chunks/_0tovk6q._.js +1 -1
- package/.next/standalone/.next/server/chunks/_0trp3yc._.js +1 -1
- package/.next/standalone/.next/server/chunks/{_0otft92._.js → _1-akg6w._.js} +2 -2
- package/.next/standalone/.next/server/chunks/_1ek68ln._.js +10 -10
- package/.next/standalone/.next/server/chunks/_1vslkoe._.js +1 -1
- package/.next/standalone/.next/server/chunks/lib_telemetry_ts_0dctyyw._.js +1 -1
- package/.next/standalone/.next/server/chunks/package_json_[json]_cjs_1nxcc4v._.js +1 -1
- package/.next/standalone/.next/server/chunks/src_hooks_fp-home_ts_09kv0bn._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/{[root-of-the-server]__1fvfw59._.js → [root-of-the-server]__00-s7h8._.js} +1 -1
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__013jr2b._.js +4 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__01wy8d-._.js +4 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__02npjtd._.js +4 -0
- package/.next/standalone/.next/server/chunks/ssr/{[root-of-the-server]__12hbpha._.js → [root-of-the-server]__09flfsx._.js} +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0da85px._.js +4 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0ftmoxc._.js +4 -0
- package/.next/standalone/.next/server/chunks/ssr/{[root-of-the-server]__0kokc8z._.js → [root-of-the-server]__0n_lxhg._.js} +1 -1
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0oa1lav._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0p-5p8u._.js +4 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0s740oi._.js +6 -0
- package/.next/standalone/.next/server/chunks/ssr/{[root-of-the-server]__0dxf928._.js → [root-of-the-server]__190won8._.js} +1 -1
- package/.next/standalone/.next/server/chunks/ssr/{[root-of-the-server]__0n2txhk._.js → [root-of-the-server]__1ctpynv._.js} +1 -1
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1p2otjt._.js +4 -0
- package/.next/standalone/.next/server/chunks/ssr/_02yoeej._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/{_0a0zlpr._.js → _04rbnaq._.js} +2 -2
- package/.next/standalone/.next/server/chunks/ssr/_08x1r5t._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/{_0s-77v5._.js → _0h_douw._.js} +1 -1
- package/.next/standalone/.next/server/chunks/ssr/_1_ozgif._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/_1ddpc5g._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/_1es2j7i._.js +14 -51
- package/.next/standalone/.next/server/chunks/ssr/{_07t3jol._.js → _1u8-lu2._.js} +2 -2
- package/.next/standalone/.next/server/chunks/ssr/_1ylae7o._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/_1zopuov._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/_next-internal_server_app_policies_page_actions_1sp2-yo.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/app_audit__components_audit-dashboard_tsx_0p9ud47._.js +69 -1
- package/.next/standalone/.next/server/chunks/ssr/app_global-error_tsx_1kp6l3x._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/app_policies_hooks-client_tsx_19dqvpc._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/app_settings_settings-client_tsx_20lq-mq._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/node_modules_13n822a._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/node_modules_html-to-image_es_index_1ao30b1.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_builtin-policies_ts_09j2ndl._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_fp-config_ts_04t589g._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/src_hooks_fp-home_ts_0je3xkv._.js +1 -1
- package/.next/standalone/.next/server/middleware-build-manifest.js +5 -5
- package/.next/standalone/.next/server/pages/404.html +1 -1
- package/.next/standalone/.next/server/pages/500.html +1 -1
- package/.next/standalone/.next/server/server-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/server-reference-manifest.json +21 -65
- package/.next/standalone/.next/static/chunks/{0f1pznnc7zlub.js → 0-tyrpwuc3lla.js} +1 -1
- package/.next/standalone/.next/static/chunks/0ca7octhod0g2.js +69 -0
- package/.next/standalone/.next/static/chunks/0u64yey446k4f.css +1 -0
- package/.next/standalone/.next/static/chunks/{1csubx9gwhsf6.js → 1j6o9min_6qa9.js} +1 -1
- package/.next/standalone/.next/static/chunks/27cl8h-c2w7cd.js +1 -0
- package/.next/standalone/.next/static/chunks/{0jpd8dv2vk930.css → 29-iqnp9v_axt.css} +1 -1
- package/.next/standalone/.next/static/chunks/{3uyhmm01g64k4.css → 2k9f4tyv04809.css} +0 -1
- package/.next/standalone/.next/static/chunks/{0t6ea7d3bkmdv.js → 2lwipmv5etc8m.js} +1 -1
- package/.next/standalone/.next/static/chunks/2pd16tn5qmx13.js +1 -0
- package/.next/standalone/.next/static/chunks/{0ntdfr2552x-h.js → 2u8vh73tpw28_.js} +1 -1
- package/.next/standalone/.next/static/chunks/{15uon66hpwbgg.js → 31u94yukw9fz-.js} +1 -1
- package/.next/standalone/.next/static/chunks/{2pwfrn6_mw-1u.js → 3p9_8x5ezce-9.js} +1 -1
- package/.next/standalone/.next/static/chunks/3qfoeqhy5l10x.js +1 -0
- package/.next/standalone/.next/static/chunks/{083fk73jtv9a0.js → 3tjji451hrgc0.js} +1 -1
- package/.next/standalone/.next/static/chunks/3zkg2s2vzxc3d.js +1 -0
- package/.next/standalone/.next/static/chunks/{turbopack-3s3c-u_u_l0u9.js → turbopack-3p73obe0xmrxm.js} +1 -1
- package/.next/standalone/.opencode/plugins/failproofai.mjs +27 -51
- package/.next/standalone/app/actions/get-scheduled-audit.ts +0 -5
- package/.next/standalone/app/actions/update-scheduled-audit.ts +57 -18
- package/.next/standalone/app/api/auth/status/route.ts +2 -3
- package/.next/standalone/app/audit/_components/audit-dashboard.tsx +34 -140
- package/.next/standalone/app/audit/_components/audit-poster.tsx +10 -29
- package/.next/standalone/app/audit/_components/come-back-better-section.tsx +1 -6
- package/.next/standalone/app/audit/_components/empty-state.tsx +1 -4
- package/.next/standalone/app/audit/_components/how-to-improve-section.tsx +5 -19
- package/.next/standalone/app/audit/_components/share-templates.ts +44 -110
- package/.next/standalone/app/audit/audit-styles.css +1 -132
- package/.next/standalone/app/settings/page.tsx +1 -1
- package/.next/standalone/app/settings/settings-client.tsx +45 -50
- package/.next/standalone/lib/auth/api-server-client.ts +5 -33
- package/.next/standalone/lib/claude-sessions.ts +27 -101
- package/.next/standalone/lib/codex-sessions.ts +4 -20
- package/.next/standalone/lib/copilot-sessions.ts +1 -32
- package/.next/standalone/lib/cursor-sessions.ts +5 -62
- package/.next/standalone/lib/sqlite-reader.ts +1 -78
- package/.next/standalone/package.json +9 -9
- package/.next/standalone/server.js +1 -1
- package/bin/failproofai.mjs +1 -1
- package/dist/cli.mjs +500 -1762
- package/dist/worker.mjs +16 -138
- package/lib/auth/api-server-client.ts +5 -33
- package/lib/claude-sessions.ts +27 -101
- package/lib/codex-sessions.ts +4 -20
- package/lib/copilot-sessions.ts +1 -32
- package/lib/cursor-sessions.ts +5 -62
- package/lib/sqlite-reader.ts +1 -78
- package/package.json +9 -9
- package/pi-extension/index.ts +5 -50
- package/src/audit/cache.ts +0 -6
- package/src/audit/cli-adapters/claude.ts +0 -13
- package/src/audit/cli-login.ts +1 -4
- package/src/audit/cli.ts +7 -157
- package/src/audit/harm-report.ts +4 -111
- package/src/audit/index.ts +15 -286
- package/src/audit/machine-store.ts +9 -8
- package/src/audit/redact-example.ts +15 -324
- package/src/audit/report-harm.ts +37 -33
- package/src/audit/report.ts +3 -6
- package/src/audit/schedule-cli.ts +33 -54
- package/src/audit/scoring.ts +0 -49
- package/src/audit/types.ts +0 -52
- package/src/hooks/builtin-policies.ts +2 -67
- package/src/hooks/configure-wizard.ts +0 -55
- package/src/hooks/fp-config.ts +48 -83
- package/src/hooks/fp-home.ts +0 -27
- package/src/hooks/integrations.ts +14 -51
- package/src/hooks/uninstall-cli.ts +2 -17
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0-4ja6q._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__00cr3xu._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__04px77e._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0egr5s1._.js +0 -6
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0i0l1di._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0r3c1_0._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__17xnxlx._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1ckpmkk._.js +0 -4
- package/.next/standalone/.next/server/chunks/ssr/_04ng_6x._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/_0l2hi_d._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/app_audit__components_rerun-button_tsx_0blihgw._.js +0 -3
- package/.next/standalone/.next/static/chunks/0divvxng208xo.js +0 -1
- package/.next/standalone/.next/static/chunks/27du9n7ssja7l.js +0 -1
- package/.next/standalone/.next/static/chunks/2h_pcb1y8_jde.js +0 -1
- package/.next/standalone/app/actions/get-leaks.ts +0 -104
- package/.next/standalone/app/audit/_components/leak-section.tsx +0 -192
- package/src/audit/desktop-notify.ts +0 -420
- package/src/audit/leak-fingerprint.ts +0 -198
- package/src/audit/leak-record.ts +0 -248
- package/src/audit/leak-scan.ts +0 -268
- package/src/audit/leak-store.ts +0 -220
- package/src/audit/macos-notifier.ts +0 -298
- package/src/hooks/notice.ts +0 -24
- /package/.next/standalone/.next/static/{YiPsVpjrc-pEQoN7XvhZ0 → dg8VQ7Ejlo0Qsh_x92oIt}/_buildManifest.js +0 -0
- /package/.next/standalone/.next/static/{YiPsVpjrc-pEQoN7XvhZ0 → dg8VQ7Ejlo0Qsh_x92oIt}/_clientMiddlewareManifest.js +0 -0
- /package/.next/standalone/.next/static/{YiPsVpjrc-pEQoN7XvhZ0 → dg8VQ7Ejlo0Qsh_x92oIt}/_ssgManifest.js +0 -0
package/src/audit/leak-record.ts
DELETED
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The per-credential record — what the audit knows that `AuditCount` cannot say.
|
|
3
|
-
*
|
|
4
|
-
* `AuditCount` aggregates BY RULE: it can report that `sanitize-api-keys` fired
|
|
5
|
-
* 47 times and show three 80-character examples. It cannot enumerate 47 distinct
|
|
6
|
-
* keys, say which of them is the same key seen twice, or answer "which CLI, in
|
|
7
|
-
* which project, at what time, and how did it get there". Every surface the
|
|
8
|
-
* narrowed product needs — the emailed digest, the dashboard's leak view, and
|
|
9
|
-
* the once-per-finding notification guard — asks exactly those questions, so
|
|
10
|
-
* none of them can be built on the rule-level record.
|
|
11
|
-
*
|
|
12
|
-
* ## Grouped by VALUE, not by occurrence — this is the whole bloat story
|
|
13
|
-
*
|
|
14
|
-
* The obvious shape is one row per sighting. Measured against the real corpus
|
|
15
|
-
* that is 10,301 rows, against roughly 266 distinct values, against about 25
|
|
16
|
-
* genuinely real credentials. Two orders of magnitude of duplication, because
|
|
17
|
-
* one pasted key fans out across every session that touched it — the single
|
|
18
|
-
* confirmed-live password in the corpus appeared in 11 files and 22 occurrences,
|
|
19
|
-
* partly because Claude's own checkpoint records replay the prompt that carried
|
|
20
|
-
* it.
|
|
21
|
-
*
|
|
22
|
-
* So the unit is the DISTINCT VALUE, with a bounded list of sightings attached
|
|
23
|
-
* as evidence. A finding seen a thousand times costs the same on disk as one
|
|
24
|
-
* seen twice: `MAX_SIGHTINGS` entries, plus a count. At the corpus's own numbers
|
|
25
|
-
* that is roughly 130 KB for the whole file, which is why this is one file and
|
|
26
|
-
* not a directory — a per-finding file would spend more on inodes and directory
|
|
27
|
-
* entries than on the findings.
|
|
28
|
-
*
|
|
29
|
-
* ## What is deliberately NOT stored
|
|
30
|
-
*
|
|
31
|
-
* The credential itself, ever. The record holds a salted id (for dedupe across
|
|
32
|
-
* scans) and a fingerprint (for a human to recognise the key in a console) and
|
|
33
|
-
* nothing that could reconstruct the value. `~/.failproofai/` is a directory the
|
|
34
|
-
* user did not ask for and cannot audit, so a leak scanner that caches the leaks
|
|
35
|
-
* has made the problem worse rather than better.
|
|
36
|
-
*/
|
|
37
|
-
import type { IntegrationType } from "../hooks/types";
|
|
38
|
-
import type { LeakFingerprint } from "./leak-fingerprint";
|
|
39
|
-
|
|
40
|
-
/** Sightings kept per distinct value. Enough to answer 5W1H for the first and
|
|
41
|
-
* most recent exposure without storing the long tail nobody reads. */
|
|
42
|
-
export const MAX_SIGHTINGS = 5;
|
|
43
|
-
|
|
44
|
-
/** Findings not seen in this many days are dropped on the next write. A key
|
|
45
|
-
* whose transcripts have aged out of the scan window is not evidence of
|
|
46
|
-
* anything current, and keeping it forever grows the file without bound. */
|
|
47
|
-
export const FINDING_TTL_DAYS = 90;
|
|
48
|
-
|
|
49
|
-
/** Cap on distinct findings retained, newest-first. A machine with more than
|
|
50
|
-
* this is not going to triage them, and the census measured a name-only rule
|
|
51
|
-
* emitting thousands — the cap is what stops a bad matcher filling the disk. */
|
|
52
|
-
export const MAX_FINDINGS = 500;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* How a credential came to be where it was found — the "how" of 5W1H.
|
|
56
|
-
*
|
|
57
|
-
* Derived from the tool event rather than authored, so it is always specific:
|
|
58
|
-
* "read from ~/…/.env" beats "detected in a file operation". The path is
|
|
59
|
-
* home-shortened by the caller before it reaches here.
|
|
60
|
-
*/
|
|
61
|
-
export interface LeakMechanism {
|
|
62
|
-
/** Short past-tense phrase, e.g. "read from ~/…/.env". */
|
|
63
|
-
summary: string;
|
|
64
|
-
/** Canonical tool name (Bash, Read, Write, Edit…). */
|
|
65
|
-
toolName: string;
|
|
66
|
-
/** Where the value appeared: the tool's INPUT (the agent sent it) or its
|
|
67
|
-
* RESULT (the agent received it). Different exposures with different
|
|
68
|
-
* remedies — an input is deniable at PreToolUse, a result is not. */
|
|
69
|
-
direction: "input" | "result";
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/** One exposure of one credential: the where/when/who of 5W1H. */
|
|
73
|
-
export interface LeakSighting {
|
|
74
|
-
/** WHO — the harness whose transcript carried it. */
|
|
75
|
-
cli: IntegrationType;
|
|
76
|
-
/** WHERE — session and project. `cwd` is already home-shortened. */
|
|
77
|
-
sessionId: string;
|
|
78
|
-
cwd: string;
|
|
79
|
-
/** WHEN — ISO-8601, from the transcript line. */
|
|
80
|
-
at: string;
|
|
81
|
-
/** HOW. */
|
|
82
|
-
mechanism: LeakMechanism;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/** One distinct credential, however many times it was seen. */
|
|
86
|
-
export interface LeakFinding {
|
|
87
|
-
/** Salted, machine-local, stable across scans. Never derived from the
|
|
88
|
-
* fingerprint, which is not unique. */
|
|
89
|
-
id: string;
|
|
90
|
-
/** WHAT — the masked rendering, its class, and its length. */
|
|
91
|
-
fingerprint: LeakFingerprint;
|
|
92
|
-
/** The identifier it was assigned to, when it came from an assignment
|
|
93
|
-
* (`COMPOSIO_API_KEY`). For the 230-of-237 first-party class this is the
|
|
94
|
-
* only actionable field there is, since no vendor console exists. */
|
|
95
|
-
name: string | null;
|
|
96
|
-
/** Which rule found it, for explaining and for suppression. */
|
|
97
|
-
rule: string;
|
|
98
|
-
/** How much we trust the attribution — mirrors the pattern census's tiers. */
|
|
99
|
-
confidence: "doc-verified" | "source-verified" | "partner-corroborated" | "observed-only" | "name-only";
|
|
100
|
-
firstSeen: string;
|
|
101
|
-
lastSeen: string;
|
|
102
|
-
/** Total exposures, which is NOT `sightings.length` — see MAX_SIGHTINGS. */
|
|
103
|
-
occurrences: number;
|
|
104
|
-
/** Bounded evidence, oldest first. */
|
|
105
|
-
sightings: LeakSighting[];
|
|
106
|
-
/** Set when the user dismisses it. Dismissed findings are retained (so they
|
|
107
|
-
* do not re-alert) but never notified about again. */
|
|
108
|
-
dismissedAt?: string;
|
|
109
|
-
/** Set when a notice for this finding has been delivered, so the next scan
|
|
110
|
-
* stays quiet. The delivery guard itself is a separate O_EXCL marker; this
|
|
111
|
-
* is the human-readable record of it. */
|
|
112
|
-
notifiedAt?: string;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export interface LeakRecord {
|
|
116
|
-
schemaVersion: number;
|
|
117
|
-
/** Per-machine HMAC salt for `fingerprintId`. Generated once, never sent. */
|
|
118
|
-
salt: string;
|
|
119
|
-
updatedAt: string;
|
|
120
|
-
findings: LeakFinding[];
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export const LEAK_RECORD_SCHEMA_VERSION = 1;
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Fold one new sighting into the record.
|
|
127
|
-
*
|
|
128
|
-
* Returns whether this is a **newly seen** credential, which is what the
|
|
129
|
-
* notification guard keys on: a finding whose id is already present must not
|
|
130
|
-
* alert again, however many new sightings it accumulates. Getting this backwards
|
|
131
|
-
* is the failure the census measured — keying on the rule-level examples, which
|
|
132
|
-
* `mergeIncremental` freezes at the first three, silently misses the arrival of
|
|
133
|
-
* a brand-new key while re-alerting for old ones.
|
|
134
|
-
*/
|
|
135
|
-
export function upsertFinding(
|
|
136
|
-
record: LeakRecord,
|
|
137
|
-
incoming: Omit<LeakFinding, "firstSeen" | "lastSeen" | "occurrences" | "sightings"> & {
|
|
138
|
-
sighting: LeakSighting;
|
|
139
|
-
},
|
|
140
|
-
): { record: LeakRecord; isNew: boolean } {
|
|
141
|
-
const { sighting, ...rest } = incoming;
|
|
142
|
-
const existing = record.findings.find((f) => f.id === rest.id);
|
|
143
|
-
|
|
144
|
-
if (!existing) {
|
|
145
|
-
record.findings.push({
|
|
146
|
-
...rest,
|
|
147
|
-
firstSeen: sighting.at,
|
|
148
|
-
lastSeen: sighting.at,
|
|
149
|
-
occurrences: 1,
|
|
150
|
-
sightings: [sighting],
|
|
151
|
-
});
|
|
152
|
-
return { record, isNew: true };
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Keep the earliest sighting AND the most recent evidence. The report/email
|
|
156
|
-
// promises the CLI and timestamp of the latest exposure; keeping only the
|
|
157
|
-
// first five made those fields stale forever after a busy credential crossed
|
|
158
|
-
// the cap. Middle sightings are the expendable ones.
|
|
159
|
-
const seen = existing.sightings.some(
|
|
160
|
-
(s) =>
|
|
161
|
-
s.sessionId === sighting.sessionId &&
|
|
162
|
-
s.at === sighting.at &&
|
|
163
|
-
s.mechanism.direction === sighting.mechanism.direction &&
|
|
164
|
-
s.mechanism.summary === sighting.mechanism.summary,
|
|
165
|
-
);
|
|
166
|
-
// Cached transcript results are folded through this function again. An
|
|
167
|
-
// identical sighting is therefore not a new exposure and must not inflate
|
|
168
|
-
// the count each time the same cache entry is reused.
|
|
169
|
-
if (seen) return { record, isNew: false };
|
|
170
|
-
|
|
171
|
-
existing.occurrences += 1;
|
|
172
|
-
if (sighting.at > existing.lastSeen) existing.lastSeen = sighting.at;
|
|
173
|
-
if (sighting.at < existing.firstSeen) existing.firstSeen = sighting.at;
|
|
174
|
-
|
|
175
|
-
existing.sightings.push(sighting);
|
|
176
|
-
existing.sightings.sort((a, b) => a.at.localeCompare(b.at));
|
|
177
|
-
if (existing.sightings.length > MAX_SIGHTINGS) {
|
|
178
|
-
existing.sightings.splice(1, existing.sightings.length - MAX_SIGHTINGS);
|
|
179
|
-
}
|
|
180
|
-
return { record, isNew: false };
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Drop what is no longer worth keeping, so the file cannot grow without bound.
|
|
185
|
-
*
|
|
186
|
-
* Order matters: age out first, then cap. Capping first would let a burst of
|
|
187
|
-
* stale findings evict fresh ones.
|
|
188
|
-
*/
|
|
189
|
-
export function pruneRecord(record: LeakRecord, nowMs: number): LeakRecord {
|
|
190
|
-
const cutoff = new Date(nowMs - FINDING_TTL_DAYS * 86_400_000).toISOString();
|
|
191
|
-
// A missing or malformed timestamp cannot be aged out safely. Keep it until
|
|
192
|
-
// the bounded-cap pass below rather than silently deleting a finding that the
|
|
193
|
-
// reporting path deliberately surfaces as having an unknown date.
|
|
194
|
-
const live = record.findings.filter(
|
|
195
|
-
(f) => !f.lastSeen || !Number.isFinite(Date.parse(f.lastSeen)) || f.lastSeen >= cutoff,
|
|
196
|
-
);
|
|
197
|
-
live.sort((a, b) => (a.lastSeen < b.lastSeen ? 1 : a.lastSeen > b.lastSeen ? -1 : 0));
|
|
198
|
-
record.findings = live.slice(0, MAX_FINDINGS);
|
|
199
|
-
return record;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/** An empty record, for a machine that has never scanned. */
|
|
203
|
-
export function emptyRecord(salt: string, nowIso: string): LeakRecord {
|
|
204
|
-
return {
|
|
205
|
-
schemaVersion: LEAK_RECORD_SCHEMA_VERSION,
|
|
206
|
-
salt,
|
|
207
|
-
updatedAt: nowIso,
|
|
208
|
-
findings: [],
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Describe how a credential came to be in a tool event.
|
|
214
|
-
*
|
|
215
|
-
* Specific by construction: the path or command is what makes a finding
|
|
216
|
-
* recognisable to the person who caused it, and a generic phrase ("detected in
|
|
217
|
-
* tool input") is the kind of alert people learn to ignore.
|
|
218
|
-
*/
|
|
219
|
-
export function describeMechanism(
|
|
220
|
-
toolName: string,
|
|
221
|
-
direction: "input" | "result",
|
|
222
|
-
shortPath: string | null,
|
|
223
|
-
): LeakMechanism {
|
|
224
|
-
const where = shortPath ? ` ${shortPath}` : "";
|
|
225
|
-
let summary: string;
|
|
226
|
-
if (direction === "result") {
|
|
227
|
-
summary = shortPath ? `appeared in the output of reading${where}` : "appeared in tool output";
|
|
228
|
-
} else {
|
|
229
|
-
switch (toolName) {
|
|
230
|
-
case "Read":
|
|
231
|
-
summary = `read from${where || " a file"}`;
|
|
232
|
-
break;
|
|
233
|
-
case "Write":
|
|
234
|
-
summary = `written to${where || " a file"}`;
|
|
235
|
-
break;
|
|
236
|
-
case "Edit":
|
|
237
|
-
case "NotebookEdit":
|
|
238
|
-
summary = `edited into${where || " a file"}`;
|
|
239
|
-
break;
|
|
240
|
-
case "Bash":
|
|
241
|
-
summary = "passed in a shell command";
|
|
242
|
-
break;
|
|
243
|
-
default:
|
|
244
|
-
summary = `sent to the ${toolName} tool`;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
return { summary, toolName, direction };
|
|
248
|
-
}
|
package/src/audit/leak-scan.ts
DELETED
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pulling credential VALUES out of a tool event.
|
|
3
|
-
*
|
|
4
|
-
* The audit already replays every event through the policy engine, but
|
|
5
|
-
* `ReplayHit` carries `{policyName, decision, reason}` and no matched text —
|
|
6
|
-
* the engine answers "did a rule fire", not "on what". That is the right answer
|
|
7
|
-
* for enforcement and the wrong one for a leak report, which has to say *which*
|
|
8
|
-
* key, so this walks the event itself.
|
|
9
|
-
*
|
|
10
|
-
* Running beside the replay rather than inside it is also what the pattern
|
|
11
|
-
* census concluded independently: detection wants a vocabulary tuned for
|
|
12
|
-
* PRECISION (a false positive becomes an email to a customer about a key that
|
|
13
|
-
* never leaked), while the redactor's vocabulary is tuned for RECALL (a false
|
|
14
|
-
* positive costs a few characters in a digest). Sharing one list would drag one
|
|
15
|
-
* of them to the other's error costs — measured, importing the detector's names
|
|
16
|
-
* into the redactor stopped 305 of 646 currently-masked names from being masked.
|
|
17
|
-
*
|
|
18
|
-
* ## Where it looks, and why both directions matter
|
|
19
|
-
*
|
|
20
|
-
* Tool INPUT and tool RESULT are separate exposures with separate remedies. An
|
|
21
|
-
* input is what the agent SENT — deniable at PreToolUse on all 12 CLIs, and
|
|
22
|
-
* 39.5% of measured credential appearances live there. A result is what the
|
|
23
|
-
* agent RECEIVED, blockable on 2 of 12 and only after the fact. The record keeps
|
|
24
|
-
* them apart so the report can tell a user which of the two happened.
|
|
25
|
-
*/
|
|
26
|
-
import { SECRET_PATTERNS } from "../hooks/builtin-policies";
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Cache key for the credential detector.
|
|
30
|
-
*
|
|
31
|
-
* The transcript cache used to key only on builtin policies and behavioural
|
|
32
|
-
* audit detectors. Changing THIS scanner therefore kept serving the old
|
|
33
|
-
* `result.leaks` forever, which made a precision fix appear to do nothing on a
|
|
34
|
-
* warm machine. Bump this whenever matching or suppression semantics change.
|
|
35
|
-
*/
|
|
36
|
-
export const LEAK_SCAN_VERSION = 6;
|
|
37
|
-
|
|
38
|
-
/** One credential value found in one event. */
|
|
39
|
-
export interface SecretMatch {
|
|
40
|
-
/** The raw value. Held in memory only — the caller fingerprints it and must
|
|
41
|
-
* never persist or transmit this. */
|
|
42
|
-
value: string;
|
|
43
|
-
/** The identifier it was assigned to, when a recognized shaped value also
|
|
44
|
-
* appeared in an assignment. Used only as an actionable label. */
|
|
45
|
-
name: string | null;
|
|
46
|
-
/** Which recognizable credential shape found it. */
|
|
47
|
-
rule: string;
|
|
48
|
-
/** Whether the value carried a recognised vendor shape. Drives the record's
|
|
49
|
-
* confidence, and therefore whether an alert may name a console. */
|
|
50
|
-
shaped: boolean;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* `NAME=value` in its four real spellings.
|
|
55
|
-
*
|
|
56
|
-
* Kept in step with `redact-example.ts`'s ASSIGNMENT_RE — same four shapes, same
|
|
57
|
-
* scheme guard — because a value the DETECTOR can report but the REDACTOR
|
|
58
|
-
* cannot mask is a leak in the report itself. The redactor may be broader; it
|
|
59
|
-
* must never be narrower. `__tests__/audit/leak-scan.test.ts` asserts that
|
|
60
|
-
* direction explicitly.
|
|
61
|
-
*/
|
|
62
|
-
/**
|
|
63
|
-
* The identifier is BOUNDED, and the bound is load-bearing rather than tidy.
|
|
64
|
-
*
|
|
65
|
-
* Unbounded (`[A-Za-z0-9_]*`), this is quadratic on a long unbroken token: the
|
|
66
|
-
* engine starts at every one of n positions, consumes the whole run, then
|
|
67
|
-
* backtracks a character at a time looking for the `=` or `:` that never comes.
|
|
68
|
-
* Measured on a plain 300 KB base64 blob — `"A".repeat(300000)` — it ran for
|
|
69
|
-
* over 20 SECONDS on one string. That is not an exotic input: agent transcripts
|
|
70
|
-
* carry base64 images, minified bundles and whole file contents as single
|
|
71
|
-
* lines, and the audit reads every one of them. A scheduled scan hitting a few
|
|
72
|
-
* of these would stall for minutes with nobody watching.
|
|
73
|
-
*
|
|
74
|
-
* 128 characters is far past any real environment-variable or field name, so
|
|
75
|
-
* bounding it costs nothing that exists and makes the scan linear in n.
|
|
76
|
-
*/
|
|
77
|
-
const ASSIGNMENT_RE =
|
|
78
|
-
/(["']?)\b([A-Za-z_][A-Za-z0-9_]{0,127})\1([ \t]*(?::(?!\/\/)|=)[ \t]*)("[^"]*"|'[^']*'|[^\s;|&"']+)/g;
|
|
79
|
-
|
|
80
|
-
/** Strip one layer of surrounding quotes. */
|
|
81
|
-
function unquote(v: string): string {
|
|
82
|
-
return (v.startsWith('"') && v.endsWith('"')) || (v.startsWith("'") && v.endsWith("'"))
|
|
83
|
-
? v.slice(1, -1)
|
|
84
|
-
: v;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* SHA-256 of credentials the vendors themselves publish in their documentation.
|
|
89
|
-
*
|
|
90
|
-
* The single highest-value refuter in the whole detector, and the only one that
|
|
91
|
-
* is decisive rather than heuristic. Measured on the real corpus: **456 of 457
|
|
92
|
-
* `AKIA` matches were AWS's own documentation literal** — 99.8% of that
|
|
93
|
-
* pattern's entire output, and 232 findings collapsing to zero. Across the
|
|
94
|
-
* pattern census, 44 of 113 patterns with five or more hits were at least 85%
|
|
95
|
-
* one literal, and 30 fired on nothing else at all.
|
|
96
|
-
*
|
|
97
|
-
* Stored as hashes so this file does not itself contain the values — a
|
|
98
|
-
* denylist written in plaintext is a file our own scanner flags, and one that
|
|
99
|
-
* lands in the corpus of every machine that installs us.
|
|
100
|
-
*
|
|
101
|
-
* A hash comparison cannot false-positive: either the value is byte-identical
|
|
102
|
-
* to a published sample or it is not. That is what makes this worth more than
|
|
103
|
-
* any amount of pattern tuning.
|
|
104
|
-
*/
|
|
105
|
-
const DOCS_LITERALS = new Set([
|
|
106
|
-
"1a5d44a2dca19669d72edf4c4f1c27c4c1ca4b4408fbb17f6ce4ad452d78ddb3", // AWS access key ID
|
|
107
|
-
"78314b11be2e581549ac1c4f616563fad3fdf0c3b71678f6e2299182080e0598", // AWS secret access key
|
|
108
|
-
"cb20d34a7adda2f5d2043836051e242fd4c2b233e02c80c91fe9d5af9b100574", // AWS temporary key ID
|
|
109
|
-
"3543c50b0cb9cea8e55eb1f529b79f043cb250d485fde7b66cabbb5183add7da", // GitHub PAT sample
|
|
110
|
-
"1fae28c1b317300acfd90078c973567c8159015822b0c8b81508a5ec40517d20", // Google API key sample
|
|
111
|
-
"23219833092a3136d7ad178ccb62ebd6ac8cba54ff24c2cfcd37b84aba9e95cf", // SendGrid key sample
|
|
112
|
-
"872db7f4419592e397ef45230f910e06b48c36ed9970cf1f9e4fb896e69f129c", // Slack bot token sample
|
|
113
|
-
"78a08441f4314f0a2833cfe58c62e555a162264206982cda39f6804f5048f570", // Stripe live key sample
|
|
114
|
-
"2cafc0970149a84f3b9e62eaf169f36f59907a3b3e31f7b82e68c69cd27f7326", // Stripe test key sample
|
|
115
|
-
"b363ade84d56c43bebbc9339b4971e340e3f13f7f8d45580b53373d2763e9e33", // Twilio account SID sample
|
|
116
|
-
]);
|
|
117
|
-
|
|
118
|
-
/** True when the value is a credential a vendor published on purpose. */
|
|
119
|
-
export function isDocsLiteral(value: string): boolean {
|
|
120
|
-
// Required lazily so this module stays importable from the browser bundle.
|
|
121
|
-
const { createHash } = require("node:crypto") as typeof import("node:crypto");
|
|
122
|
-
return DOCS_LITERALS.has(createHash("sha256").update(value).digest("hex"));
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Text that is failproofai's OWN output being replayed back at us.
|
|
127
|
-
*
|
|
128
|
-
* Auditing for secrets writes secrets into the corpus the next audit reads.
|
|
129
|
-
* That is measured, not theoretical: the single largest organic cluster in
|
|
130
|
-
* 1.6 GB of transcripts was one file — a previous secret-audit run quoting back
|
|
131
|
-
* the credentials it had found (123 Atlassian tokens, 26 Telegram, 25 Slack,
|
|
132
|
-
* 18 GitHub) — and 108 of the 161 patterns that matched anything matched ONLY
|
|
133
|
-
* inside the investigation's own transcripts.
|
|
134
|
-
*
|
|
135
|
-
* Left unhandled the count climbs every scan, each report inflating the next.
|
|
136
|
-
* These markers appear in our own rendered output and essentially nowhere else.
|
|
137
|
-
*/
|
|
138
|
-
const SELF_OUTPUT_MARKERS = [
|
|
139
|
-
"[REDACTED:",
|
|
140
|
-
"[redacted:",
|
|
141
|
-
"failproofai audit",
|
|
142
|
-
"assigned secret]",
|
|
143
|
-
];
|
|
144
|
-
|
|
145
|
-
/** True when this text is our own report, not a transcript of real work. */
|
|
146
|
-
export function isSelfOutput(text: string): boolean {
|
|
147
|
-
return SELF_OUTPUT_MARKERS.some((m) => text.includes(m));
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Literal prefixes that must appear before any vendor regex is worth running.
|
|
152
|
-
*
|
|
153
|
-
* A prefilter, and it is not an optimisation — it is what makes the pattern set
|
|
154
|
-
* shippable at all. The census measured the cost as LINEAR in pattern count:
|
|
155
|
-
* ~0.095s per pattern per 6 MB, so 288 patterns over a 1.6 GB corpus is roughly
|
|
156
|
-
* two hours, while the handful that ever match take five seconds. Scanning is
|
|
157
|
-
* already the audit's slowest phase and the whole point of adding vendors is
|
|
158
|
-
* that most of them never fire on any given machine.
|
|
159
|
-
*
|
|
160
|
-
* So: one cheap pass over the text asking "does any prefix appear at all", and
|
|
161
|
-
* the regexes only run when one does. Derived from `SECRET_PATTERNS` at module
|
|
162
|
-
* load rather than hand-maintained, because a hand-copied list that drifts from
|
|
163
|
-
* its source silently stops matching — the exact failure class this repo already
|
|
164
|
-
* has a tripwire test for elsewhere.
|
|
165
|
-
*
|
|
166
|
-
* Patterns with no literal prefix (a bare JWT, a connection string, the Telegram
|
|
167
|
-
* `\d{8,10}:` shape) yield no gate token and are always run; they are few, and
|
|
168
|
-
* a pattern that cannot be prefiltered is one whose cost has to be paid.
|
|
169
|
-
*/
|
|
170
|
-
function literalPrefixOf(source: string): string | null {
|
|
171
|
-
// Walk the regex source until the first construct that is not a plain
|
|
172
|
-
// literal. Anything before that is text the input must contain verbatim.
|
|
173
|
-
let out = "";
|
|
174
|
-
for (let i = 0; i < source.length; i++) {
|
|
175
|
-
const c = source[i];
|
|
176
|
-
if (c === "\\") {
|
|
177
|
-
// An escape: only a handful are literal characters we can rely on.
|
|
178
|
-
const next = source[i + 1];
|
|
179
|
-
if (next === undefined) break;
|
|
180
|
-
if (/[dwsSDWbB]/.test(next)) break; // a class, not a literal
|
|
181
|
-
out += next;
|
|
182
|
-
i++;
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
if ("[](){}|?*+^$.".includes(c)) break;
|
|
186
|
-
out += c;
|
|
187
|
-
}
|
|
188
|
-
// Two characters is the shortest gate worth having: shorter than that and the
|
|
189
|
-
// prefilter matches nearly every input and buys nothing.
|
|
190
|
-
return out.length >= 2 ? out : null;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/** Built once. Each entry is `[pattern, label, gate]`; a null gate always runs. */
|
|
194
|
-
const GATED_PATTERNS: ReadonlyArray<readonly [RegExp, string, string | null]> =
|
|
195
|
-
SECRET_PATTERNS.map(([re, label]) => [re, label, literalPrefixOf(re.source)] as const);
|
|
196
|
-
|
|
197
|
-
/** Patterns worth running against this text. */
|
|
198
|
-
function applicablePatterns(text: string): ReadonlyArray<readonly [RegExp, string, string | null]> {
|
|
199
|
-
return GATED_PATTERNS.filter(([, , gate]) => gate === null || text.includes(gate));
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Every credential value in one blob of text.
|
|
204
|
-
*
|
|
205
|
-
* Vendor SHAPES first, then secret-NAMED assignments, deduped by value so one
|
|
206
|
-
* key matched by both layers is reported once — under its vendor label, which
|
|
207
|
-
* is the one that can carry a revocation link. The two layers are near-disjoint
|
|
208
|
-
* in practice: 55.9% of real vendor-shaped credentials in the corpus have no
|
|
209
|
-
* secret-ish word within 60 characters, and 230 of 237 secret-named assignments
|
|
210
|
-
* match no vendor pattern at all.
|
|
211
|
-
*
|
|
212
|
-
* Both refuters run before anything is reported: our own replayed output is
|
|
213
|
-
* dropped whole, and every published documentation sample is dropped by hash.
|
|
214
|
-
*/
|
|
215
|
-
export function findSecrets(text: string): SecretMatch[] {
|
|
216
|
-
if (!text) return [];
|
|
217
|
-
// Our own report replayed into a transcript is not a leak — see isSelfOutput.
|
|
218
|
-
if (isSelfOutput(text)) return [];
|
|
219
|
-
const byValue = new Map<string, SecretMatch>();
|
|
220
|
-
|
|
221
|
-
for (const [pattern, label] of applicablePatterns(text)) {
|
|
222
|
-
const re = new RegExp(pattern.source, pattern.flags.includes("g") ? pattern.flags : pattern.flags + "g");
|
|
223
|
-
for (const m of text.matchAll(re)) {
|
|
224
|
-
const value = m[0];
|
|
225
|
-
if (isDocsLiteral(value)) continue;
|
|
226
|
-
if (!byValue.has(value)) byValue.set(value, { value, name: null, rule: label, shaped: true });
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// Names annotate a value the shape layer already proved; they no longer
|
|
231
|
-
// create findings. Even after increasingly elaborate value heuristics, the
|
|
232
|
-
// name-only lane still produced hundreds of code literals and test fixtures
|
|
233
|
-
// on the measured machine. The product now deliberately prefers missing an
|
|
234
|
-
// unrecognisable first-party password over telling somebody they leaked 500
|
|
235
|
-
// credentials they do not have.
|
|
236
|
-
for (const m of text.matchAll(ASSIGNMENT_RE)) {
|
|
237
|
-
const name = m[2];
|
|
238
|
-
const value = unquote(m[4]);
|
|
239
|
-
const existing = byValue.get(value);
|
|
240
|
-
if (existing) existing.name ??= name;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
return [...byValue.values()];
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Serialize a tool input for scanning.
|
|
248
|
-
*
|
|
249
|
-
* Every string leaf, not just `command`: the measured surface includes file
|
|
250
|
-
* bodies on Write, replacement text on Edit, headers on WebFetch and arbitrary
|
|
251
|
-
* MCP payloads. `JSON.stringify` would work but escapes quotes, which breaks
|
|
252
|
-
* the assignment grammar on exactly the JSON-config shape that carries most
|
|
253
|
-
* first-party keys — so the leaves are joined raw.
|
|
254
|
-
*/
|
|
255
|
-
export function flattenToolInput(input: unknown, depth = 0): string {
|
|
256
|
-
if (depth > 6 || input == null) return "";
|
|
257
|
-
if (typeof input === "string") return input;
|
|
258
|
-
if (typeof input === "number" || typeof input === "boolean") return String(input);
|
|
259
|
-
if (Array.isArray(input)) return input.map((v) => flattenToolInput(v, depth + 1)).join("\n");
|
|
260
|
-
if (typeof input === "object") {
|
|
261
|
-
return Object.entries(input as Record<string, unknown>)
|
|
262
|
-
// Keep the key adjacent to the value so `{"api_key": "…"}` still reads as
|
|
263
|
-
// an assignment to the grammar above.
|
|
264
|
-
.map(([k, v]) => `${k}=${flattenToolInput(v, depth + 1)}`)
|
|
265
|
-
.join("\n");
|
|
266
|
-
}
|
|
267
|
-
return "";
|
|
268
|
-
}
|