failproofai 1.0.3 → 1.0.4-beta.2
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 +5 -5
- 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.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.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 +15 -15
- package/.next/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +15 -15
- package/.next/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +14 -14
- package/.next/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
- package/.next/standalone/.next/server/app/api/audit/invite/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/audit/invite/route_client-reference-manifest.js +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/run/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/api/audit/status/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/audit/status/route_client-reference-manifest.js +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-request/route_client-reference-manifest.js +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/login-verify/route_client-reference-manifest.js +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/logout/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/api/auth/status/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/auth/status/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/api/download/[project]/[session]/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/download/[project]/[session]/route_client-reference-manifest.js +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 +37 -4
- 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 +15 -15
- package/.next/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +14 -14
- package/.next/standalone/.next/server/app/index.segments/_full.segment.rsc +15 -15
- package/.next/standalone/.next/server/app/index.segments/_tree.segment.rsc +2 -2
- 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.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.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.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.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.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 -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]__0-9ti7z._.js → [externals]__1lh7m5d._.js} +1 -1
- package/.next/standalone/.next/server/chunks/{[externals]__0u3wrvq._.js → [externals]__1rqkg_y._.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]__1adacul._.js +1 -1
- package/.next/standalone/.next/server/chunks/{_1-akg6w._.js → _08w6xzm._.js} +2 -2
- 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/_1ek68ln._.js +4 -4
- package/.next/standalone/.next/server/chunks/lib_telemetry_ts_0dctyyw._.js +1 -1
- package/.next/standalone/.next/server/chunks/node_modules_posthog-node_dist_entrypoints_index_node_mjs_01r25oi._.js +2 -2
- package/.next/standalone/.next/server/chunks/node_modules_posthog-node_dist_entrypoints_index_node_mjs_09z9-p7._.js +2 -2
- 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]__013jr2b._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__01wy8d-._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__02npjtd._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0da85px._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0ftmoxc._.js +2 -2
- 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 +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0rgu2r3._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0s740oi._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1p2otjt._.js +2 -2
- package/.next/standalone/.next/server/chunks/ssr/_0-oij9d._.js +23 -0
- package/.next/standalone/.next/server/chunks/ssr/_08x1r5t._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/_0l2hi_d._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/_0oq1dh6._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/_1es2j7i._.js +47 -13
- package/.next/standalone/.next/server/chunks/ssr/_1u8-lu2._.js +1 -1
- 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 +1 -69
- package/.next/standalone/.next/server/chunks/ssr/app_audit__components_rerun-button_tsx_0blihgw._.js +3 -0
- 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_posthog-node_dist_entrypoints_index_node_mjs_11bnuzn._.js +2 -2
- 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 +54 -21
- package/.next/standalone/.next/static/chunks/010bv1w6j171t.js +1 -0
- package/.next/standalone/.next/static/chunks/04r6ch8uf_n8m.js +1 -0
- package/.next/standalone/.next/static/chunks/{29-iqnp9v_axt.css → 0o-hh5_turzlz.css} +1 -1
- package/.next/standalone/.next/static/chunks/{40nr6ehj4p3cw.css → 0qmsunv04x4na.css} +1 -1
- package/.next/standalone/.next/static/chunks/{0ollg-nnu3t3e.js → 0wz8yftk18ts2.js} +1 -1
- package/.next/standalone/.next/static/chunks/0zebh1n9jkfbt.js +1 -0
- package/.next/standalone/.next/static/chunks/1eyl7fzkmnkf_.js +1 -0
- package/.next/standalone/.next/static/chunks/1pb1oztsbwcss.js +1 -0
- package/.next/standalone/.next/static/chunks/{1-_zkmnm-jwei.js → 2aquitk72k2op.js} +1 -1
- package/.next/standalone/.next/static/chunks/2bi_1y0a_smt7.js +6 -0
- package/.next/standalone/.next/static/chunks/{42yfkhekx440s.js → 2ej3b8gk5ittu.js} +1 -1
- package/.next/standalone/.next/static/chunks/{354-n7p7labpn.js → 2zafgs90r_leq.js} +1 -1
- package/.next/standalone/.next/static/chunks/{2xm5mj1d21b4n.js → 32spub4wqjem-.js} +1 -1
- package/.next/standalone/.next/static/chunks/{1a6u7l3giejch.js → 3m4upvybtrexd.js} +1 -1
- package/.next/standalone/.next/static/chunks/{2k9f4tyv04809.css → 3uyhmm01g64k4.css} +1 -0
- package/.next/standalone/.next/static/chunks/{turbopack-2x-o099q64i8h.js → turbopack-3s3c-u_u_l0u9.js} +1 -1
- package/.next/standalone/.opencode/plugins/failproofai.mjs +51 -27
- package/.next/standalone/app/actions/get-leaks.ts +100 -0
- package/.next/standalone/app/audit/_components/audit-dashboard.tsx +112 -33
- package/.next/standalone/app/audit/_components/audit-poster.tsx +29 -10
- package/.next/standalone/app/audit/_components/come-back-better-section.tsx +6 -1
- package/.next/standalone/app/audit/_components/empty-state.tsx +4 -1
- package/.next/standalone/app/audit/_components/how-to-improve-section.tsx +19 -5
- package/.next/standalone/app/audit/_components/leak-section.tsx +179 -0
- package/.next/standalone/app/audit/_components/share-templates.ts +110 -44
- package/.next/standalone/app/audit/audit-styles.css +114 -1
- package/.next/standalone/fp-cloud-cli/CHANGELOG.md +26 -3
- package/.next/standalone/fp-cloud-cli/fp_cli/_click_compat.py +31 -8
- package/.next/standalone/fp-cloud-cli/fp_cli/permissions.py +1 -0
- package/.next/standalone/fp-cloud-cli/pyproject.toml +9 -2
- package/.next/standalone/fp-cloud-cli/tests/test_click_compat.py +54 -0
- package/.next/standalone/fp-cloud-cli/uv.lock +9 -12
- package/.next/standalone/lib/auth/api-server-client.ts +28 -0
- package/.next/standalone/lib/claude-sessions.ts +101 -27
- package/.next/standalone/node_modules/@next/env/package.json +1 -1
- package/.next/standalone/node_modules/next/dist/build/swc/index.js +1 -1
- package/.next/standalone/node_modules/next/dist/compiled/next-server/app-page-turbo-experimental.runtime.prod.js +1 -1
- package/.next/standalone/node_modules/next/dist/compiled/next-server/app-page-turbo.runtime.prod.js +1 -1
- package/.next/standalone/node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.prod.js +1 -1
- package/.next/standalone/node_modules/next/dist/compiled/next-server/pages-turbo.runtime.prod.js +5 -5
- package/.next/standalone/node_modules/next/dist/experimental/testmode/fetch.js +10 -2
- package/.next/standalone/node_modules/next/dist/lib/patch-incorrect-lockfile.js +3 -3
- package/.next/standalone/node_modules/next/dist/lib/typescript/runTypeScriptCli.js +2 -2
- package/.next/standalone/node_modules/next/dist/lib/verify-typescript-setup.js +3 -1
- package/.next/standalone/node_modules/next/dist/server/config.js +1 -1
- package/.next/standalone/node_modules/next/dist/server/dev/hot-reloader-turbopack.js +2 -2
- package/.next/standalone/node_modules/next/dist/server/dev/hot-reloader-webpack.js +1 -1
- package/.next/standalone/node_modules/next/dist/server/lib/app-info-log.js +1 -1
- package/.next/standalone/node_modules/next/dist/server/lib/incremental-cache/file-system-cache.js +17 -4
- package/.next/standalone/node_modules/next/dist/server/lib/start-server.js +1 -1
- package/.next/standalone/node_modules/next/dist/shared/lib/router/utils/escape-path-delimiters.js +1 -1
- package/.next/standalone/node_modules/next/dist/telemetry/anonymous-meta.js +1 -1
- package/.next/standalone/node_modules/next/dist/telemetry/events/swc-load-failure.js +1 -1
- package/.next/standalone/node_modules/next/dist/telemetry/events/version.js +2 -2
- package/.next/standalone/node_modules/next/package.json +11 -11
- package/.next/standalone/package.json +14 -13
- package/.next/standalone/sdk/python/CHANGELOG.md +155 -0
- package/.next/standalone/sdk/python/README.md +8 -0
- package/.next/standalone/sdk/python/examples/evaluator_worker.py +121 -0
- package/.next/standalone/sdk/python/failproofai_sdk/_version.py +1 -1
- package/.next/standalone/sdk/python/failproofai_sdk/evaluator/__init__.py +101 -0
- package/.next/standalone/sdk/python/failproofai_sdk/evaluator/__main__.py +49 -0
- package/.next/standalone/sdk/python/failproofai_sdk/evaluator/_sandbox_runner.py +63 -0
- package/.next/standalone/sdk/python/failproofai_sdk/evaluator/authoring.py +404 -0
- package/.next/standalone/sdk/python/failproofai_sdk/evaluator/client.py +299 -0
- package/.next/standalone/sdk/python/failproofai_sdk/evaluator/protocol.py +754 -0
- package/.next/standalone/sdk/python/failproofai_sdk/evaluator/runtime.py +936 -0
- package/.next/standalone/sdk/python/failproofai_sdk/evaluator/source.py +684 -0
- package/.next/standalone/sdk/python/tests/fixtures/evaluator_v2/README.md +28 -0
- package/.next/standalone/sdk/python/tests/fixtures/evaluator_v2/contract.json +252 -0
- package/.next/standalone/sdk/python/tests/test_evaluator_authoring.py +124 -0
- package/.next/standalone/sdk/python/tests/test_evaluator_client.py +253 -0
- package/.next/standalone/sdk/python/tests/test_evaluator_example.py +35 -0
- package/.next/standalone/sdk/python/tests/test_evaluator_http_e2e.py +636 -0
- package/.next/standalone/sdk/python/tests/test_evaluator_main.py +47 -0
- package/.next/standalone/sdk/python/tests/test_evaluator_protocol.py +246 -0
- package/.next/standalone/sdk/python/tests/test_evaluator_review_fixes.py +164 -0
- package/.next/standalone/sdk/python/tests/test_evaluator_runtime.py +1103 -0
- package/.next/standalone/sdk/python/tests/test_evaluator_source.py +430 -0
- package/.next/standalone/sdk/python/tests/test_zero_dependencies.py +17 -0
- package/.next/standalone/sdk/python/uv.lock +29 -29
- package/.next/standalone/server.js +1 -1
- package/README.md +13 -58
- package/dist/cli.mjs +5368 -8756
- package/dist/worker.mjs +539 -312
- package/lib/auth/api-server-client.ts +28 -0
- package/lib/claude-sessions.ts +101 -27
- package/package.json +14 -13
- package/pi-extension/index.ts +42 -4
- package/scripts/changelog-open.py +115 -0
- package/src/audit/cli.ts +134 -0
- package/src/audit/desktop-notify.ts +420 -0
- package/src/audit/harm-report.ts +101 -0
- package/src/audit/index.ts +141 -13
- package/src/audit/leak-fingerprint.ts +200 -0
- package/src/audit/leak-notice.ts +161 -0
- package/src/audit/leak-record.ts +232 -0
- package/src/audit/leak-scan.ts +292 -0
- package/src/audit/leak-store.ts +217 -0
- package/src/audit/macos-notifier.ts +310 -0
- package/src/audit/redact-example.ts +266 -14
- package/src/audit/report-harm.ts +12 -1
- package/src/audit/report.ts +6 -3
- package/src/audit/schedule-cli.ts +37 -0
- package/src/audit/scoring.ts +49 -0
- package/src/audit/types.ts +41 -0
- package/src/hooks/builtin-policies.ts +67 -2
- package/src/hooks/configure-wizard.ts +20 -0
- package/src/hooks/fp-config.ts +71 -11
- package/src/hooks/fp-home.ts +27 -0
- package/src/hooks/handler.ts +59 -1
- package/src/hooks/integrations.ts +47 -13
- package/src/hooks/notice.ts +155 -0
- package/src/hooks/uninstall-cli.ts +15 -0
- package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1b5jzxr._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/_0j6gd_k._.js +0 -23
- package/.next/standalone/.next/server/chunks/ssr/_0v8eebd._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/_1ylae7o._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/_1zopuov._.js +0 -3
- package/.next/standalone/.next/server/chunks/ssr/node_modules_html-to-image_es_index_1ao30b1.js +0 -3
- package/.next/standalone/.next/static/chunks/03slu0c8_71y7.js +0 -1
- package/.next/standalone/.next/static/chunks/0nm11ysn0153h.js +0 -1
- package/.next/standalone/.next/static/chunks/0u64yey446k4f.css +0 -1
- package/.next/standalone/.next/static/chunks/1r9676mkvihto.js +0 -1
- package/.next/standalone/.next/static/chunks/30pct5s734jua.js +0 -6
- package/.next/standalone/.next/static/chunks/3pibxnbhjza7n.js +0 -69
- package/.next/standalone/.next/static/chunks/3qfoeqhy5l10x.js +0 -1
- package/.next/standalone/.next/static/chunks/3zkg2s2vzxc3d.js +0 -1
- package/.next/standalone/.next/static/chunks/41b5ptaocvi_l.js +0 -1
- /package/.next/standalone/.next/static/{JBYgkXkA1PS48m9P_hKNw → aKNv4Kmv98Xpwns0Xa-C-}/_buildManifest.js +0 -0
- /package/.next/standalone/.next/static/{JBYgkXkA1PS48m9P_hKNw → aKNv4Kmv98Xpwns0Xa-C-}/_clientMiddlewareManifest.js +0 -0
- /package/.next/standalone/.next/static/{JBYgkXkA1PS48m9P_hKNw → aKNv4Kmv98Xpwns0Xa-C-}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A desktop notification on Linux, from a process with no desktop.
|
|
3
|
+
*
|
|
4
|
+
* The scheduled audit runs as a child of a SYSTEM-scope service. Its
|
|
5
|
+
* environment was measured on a real machine and carries no
|
|
6
|
+
* `DBUS_SESSION_BUS_ADDRESS`, no `DISPLAY`, no `WAYLAND_DISPLAY` and no
|
|
7
|
+
* `XDG_RUNTIME_DIR` — the daemon starts at boot, before anyone logs in, which
|
|
8
|
+
* is the whole reason it survives logout.
|
|
9
|
+
*
|
|
10
|
+
* That turns out not to be a permission problem. `/run/user/<uid>/bus` exists
|
|
11
|
+
* whenever the user is logged in, the daemon already runs as that uid, and
|
|
12
|
+
* D-Bus's EXTERNAL auth is `SO_PEERCRED` — the kernel vouches for the uid, so
|
|
13
|
+
* there is no cookie, no session membership and no environment to inherit. The
|
|
14
|
+
* address just has to be CONSTRUCTED rather than read. Proven on a real bus
|
|
15
|
+
* with a fully scrubbed environment: `AUTH … OK` → accepted.
|
|
16
|
+
*
|
|
17
|
+
* ## Awaiting the reply is the entire correctness story
|
|
18
|
+
*
|
|
19
|
+
* Measured: a call sent with NO_REPLY_EXPECTED against a bus with no
|
|
20
|
+
* notification server returns exit 0, empty stdout, empty stderr — the
|
|
21
|
+
* notification silently evaporates. The same call awaiting its reply returns a
|
|
22
|
+
* named error. Ship the fire-and-forget variant and you get exactly the failure
|
|
23
|
+
* this feature exists to avoid: believing the user was told.
|
|
24
|
+
*
|
|
25
|
+
* With the reply awaited every failure is loud and fast (10-16ms measured):
|
|
26
|
+
* logged out → ENOENT on connect, stale socket → ECONNREFUSED, no desktop →
|
|
27
|
+
* `org.freedesktop.DBus.Error.ServiceUnknown`.
|
|
28
|
+
*
|
|
29
|
+
* One failure is NOT detectable from here and must not be papered over: on a
|
|
30
|
+
* locked screen the shell still owns the name and still returns an id, while
|
|
31
|
+
* the user sees nothing. `Notify` succeeding means the server accepted it,
|
|
32
|
+
* never that a human saw it — which is why the queue, not the toast, is the
|
|
33
|
+
* record of a finding.
|
|
34
|
+
*
|
|
35
|
+
* No dependency: the wire protocol is written by hand rather than pulling a
|
|
36
|
+
* D-Bus client into a package that installs into other people's machines.
|
|
37
|
+
*/
|
|
38
|
+
import { connect, type Socket } from "node:net";
|
|
39
|
+
|
|
40
|
+
/** Milliseconds allowed for the whole exchange. Generous — a live bus answers
|
|
41
|
+
* in ~10ms, and this runs off the hook path entirely. */
|
|
42
|
+
const TIMEOUT_MS = 2_000;
|
|
43
|
+
|
|
44
|
+
export type NotifyOutcome =
|
|
45
|
+
| { ok: true; id: number }
|
|
46
|
+
| { ok: false; reason: "no-session" | "no-server" | "refused" | "timeout" | "error"; detail: string };
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A D-Bus marshaller that knows where it is.
|
|
50
|
+
*
|
|
51
|
+
* Every alignment rule in the wire format is stated relative to the START OF
|
|
52
|
+
* THE MESSAGE, which is why this tracks an offset instead of padding buffers in
|
|
53
|
+
* isolation. The first version of this file did the latter — each helper padded
|
|
54
|
+
* its own result to the boundary it needed — and it produced a header-fields
|
|
55
|
+
* array two bytes too long, because the padding after the LAST element belongs
|
|
56
|
+
* to the message rather than to the array. Real `dbus-daemon` dropped the
|
|
57
|
+
* connection; the hand-written test server did not, because it mirrored the
|
|
58
|
+
* same assumption the encoder made. The byte diff against a real client's
|
|
59
|
+
* `Hello` is what settled it (0x70 vs 0x6e), and it is why the tests below now
|
|
60
|
+
* run against a real bus.
|
|
61
|
+
*/
|
|
62
|
+
class Marshal {
|
|
63
|
+
private chunks: Buffer[] = [];
|
|
64
|
+
private len = 0;
|
|
65
|
+
|
|
66
|
+
/** Pad to the next `n`-byte boundary, counted from the start of the message. */
|
|
67
|
+
align(n: number): void {
|
|
68
|
+
const pad = (n - (this.len % n)) % n;
|
|
69
|
+
if (pad) this.raw(Buffer.alloc(pad));
|
|
70
|
+
}
|
|
71
|
+
raw(b: Buffer): void {
|
|
72
|
+
this.chunks.push(b);
|
|
73
|
+
this.len += b.length;
|
|
74
|
+
}
|
|
75
|
+
byte(v: number): void {
|
|
76
|
+
this.raw(Buffer.from([v]));
|
|
77
|
+
}
|
|
78
|
+
u32(v: number): void {
|
|
79
|
+
this.align(4);
|
|
80
|
+
const b = Buffer.alloc(4);
|
|
81
|
+
b.writeUInt32LE(v, 0);
|
|
82
|
+
this.raw(b);
|
|
83
|
+
}
|
|
84
|
+
i32(v: number): void {
|
|
85
|
+
this.align(4);
|
|
86
|
+
const b = Buffer.alloc(4);
|
|
87
|
+
b.writeInt32LE(v, 0);
|
|
88
|
+
this.raw(b);
|
|
89
|
+
}
|
|
90
|
+
/** STRING / OBJECT_PATH: 4-aligned length, bytes, NUL. */
|
|
91
|
+
str(v: string): void {
|
|
92
|
+
const b = Buffer.from(v, "utf8");
|
|
93
|
+
this.u32(b.length);
|
|
94
|
+
this.raw(b);
|
|
95
|
+
this.byte(0);
|
|
96
|
+
}
|
|
97
|
+
/** SIGNATURE: a single length BYTE, bytes, NUL. No alignment. */
|
|
98
|
+
sig(v: string): void {
|
|
99
|
+
const b = Buffer.from(v, "utf8");
|
|
100
|
+
this.byte(b.length);
|
|
101
|
+
this.raw(b);
|
|
102
|
+
this.byte(0);
|
|
103
|
+
}
|
|
104
|
+
get length(): number {
|
|
105
|
+
return this.len;
|
|
106
|
+
}
|
|
107
|
+
buffer(): Buffer {
|
|
108
|
+
return Buffer.concat(this.chunks);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** One header field: a STRUCT of (BYTE code, VARIANT value), 8-aligned. */
|
|
113
|
+
type HeaderField = readonly [code: number, signature: string, value: string];
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Encode the header-fields array.
|
|
117
|
+
*
|
|
118
|
+
* Returns the declared length SEPARATELY from the bytes, because they are not
|
|
119
|
+
* the same number: the length stops at the end of the last element's content,
|
|
120
|
+
* while the message then pads to 8 before the body. Conflating them is the bug
|
|
121
|
+
* described on `Marshal`.
|
|
122
|
+
*/
|
|
123
|
+
function headerFields(fields: readonly HeaderField[]): { data: Buffer; declaredLength: number } {
|
|
124
|
+
// The array's data starts at message offset 16, which is already 8-aligned,
|
|
125
|
+
// so offsets inside this marshaller line up with the real message.
|
|
126
|
+
const m = new Marshal();
|
|
127
|
+
for (const [code, signature, value] of fields) {
|
|
128
|
+
m.align(8); // each STRUCT element starts on an 8-byte boundary
|
|
129
|
+
m.byte(code);
|
|
130
|
+
m.sig(signature);
|
|
131
|
+
// Every header field we send is a string-like: OBJECT_PATH, STRING or
|
|
132
|
+
// SIGNATURE. Nothing here needs a numeric variant.
|
|
133
|
+
if (signature === "g") m.sig(value);
|
|
134
|
+
else m.str(value);
|
|
135
|
+
}
|
|
136
|
+
// No trailing padding was added, so the buffer length IS the declared length.
|
|
137
|
+
return { data: m.buffer(), declaredLength: m.length };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** A METHOD_CALL: fixed header, header fields, 8-byte pad, then the body. */
|
|
141
|
+
function methodCall(serial: number, fields: readonly HeaderField[], body: Buffer): Buffer {
|
|
142
|
+
const { data, declaredLength } = headerFields(fields);
|
|
143
|
+
const head = new Marshal();
|
|
144
|
+
head.raw(Buffer.from([0x6c, 1, 0, 1])); // little-endian, METHOD_CALL, no flags, proto 1
|
|
145
|
+
head.u32(body.length);
|
|
146
|
+
head.u32(serial);
|
|
147
|
+
head.u32(declaredLength);
|
|
148
|
+
head.raw(data);
|
|
149
|
+
head.align(8); // the body always starts on an 8-byte boundary
|
|
150
|
+
return Buffer.concat([head.buffer(), body]);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* The arguments of `org.freedesktop.Notifications.Notify`.
|
|
155
|
+
*
|
|
156
|
+
* Signature `susssasa{sv}i`: app_name, replaces_id, app_icon, summary, body,
|
|
157
|
+
* actions, hints, expire_timeout.
|
|
158
|
+
*/
|
|
159
|
+
function notifyBody(app: string, replacesId: number, summary: string, body: string): Buffer {
|
|
160
|
+
const m = new Marshal();
|
|
161
|
+
m.str(app);
|
|
162
|
+
m.u32(replacesId);
|
|
163
|
+
m.str(""); // app_icon — none; the app name is what identifies us
|
|
164
|
+
m.str(summary);
|
|
165
|
+
m.str(body);
|
|
166
|
+
m.u32(0); // actions: `as`, empty. Element alignment 4, already met.
|
|
167
|
+
m.u32(0); // hints: `a{sv}`, empty...
|
|
168
|
+
m.align(8); // ...and an array pads to its ELEMENT alignment even when
|
|
169
|
+
// empty. DICT_ENTRY is 8, so this padding is required and
|
|
170
|
+
// counts toward the body length.
|
|
171
|
+
m.i32(-1); // expire_timeout: -1 lets the server decide
|
|
172
|
+
return m.buffer();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** `org.freedesktop.DBus.Hello` — mandatory before any other method call. */
|
|
176
|
+
const HELLO_FIELDS: readonly HeaderField[] = [
|
|
177
|
+
[1, "o", "/org/freedesktop/DBus"],
|
|
178
|
+
[6, "s", "org.freedesktop.DBus"],
|
|
179
|
+
[2, "s", "org.freedesktop.DBus"],
|
|
180
|
+
[3, "s", "Hello"],
|
|
181
|
+
];
|
|
182
|
+
|
|
183
|
+
const NOTIFY_FIELDS: readonly HeaderField[] = [
|
|
184
|
+
[1, "o", "/org/freedesktop/Notifications"],
|
|
185
|
+
[6, "s", "org.freedesktop.Notifications"],
|
|
186
|
+
[2, "s", "org.freedesktop.Notifications"],
|
|
187
|
+
[3, "s", "Notify"],
|
|
188
|
+
[8, "g", "susssasa{sv}i"],
|
|
189
|
+
];
|
|
190
|
+
|
|
191
|
+
/** A parsed inbound message: only what the state machine dispatches on. */
|
|
192
|
+
interface Incoming {
|
|
193
|
+
type: number;
|
|
194
|
+
replySerial: number | null;
|
|
195
|
+
errorName: string | null;
|
|
196
|
+
bodyStart: number;
|
|
197
|
+
bodyLength: number;
|
|
198
|
+
total: number;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Read one whole message out of `buf`, or null when it has not all arrived.
|
|
203
|
+
*
|
|
204
|
+
* A framed reader rather than "assume one message per chunk", because a real
|
|
205
|
+
* bus does not oblige: it answers `Hello` with a METHOD_RETURN and then emits a
|
|
206
|
+
* `NameAcquired` SIGNAL, and the two can land in one chunk or two. The earlier
|
|
207
|
+
* version consumed whichever chunk came first and treated the NEXT one as its
|
|
208
|
+
* reply — which, for a SIGNAL, is neither an error nor a return, so it reported
|
|
209
|
+
* the notification as delivered with a garbage id.
|
|
210
|
+
*/
|
|
211
|
+
function readMessage(buf: Buffer): Incoming | null {
|
|
212
|
+
if (buf.length < 16) return null;
|
|
213
|
+
const bodyLength = buf.readUInt32LE(4);
|
|
214
|
+
const fieldsLength = buf.readUInt32LE(12);
|
|
215
|
+
const bodyStart = 16 + fieldsLength + ((8 - (fieldsLength % 8)) % 8);
|
|
216
|
+
const total = bodyStart + bodyLength;
|
|
217
|
+
if (buf.length < total) return null;
|
|
218
|
+
|
|
219
|
+
let replySerial: number | null = null;
|
|
220
|
+
let errorName: string | null = null;
|
|
221
|
+
// Walk the header fields far enough to find REPLY_SERIAL (5) and ERROR_NAME
|
|
222
|
+
// (4). Anything unparseable stops the walk rather than throwing: a header we
|
|
223
|
+
// cannot read is a message we ignore, not a crash on the audit's exit path.
|
|
224
|
+
let i = 16;
|
|
225
|
+
const end = 16 + fieldsLength;
|
|
226
|
+
while (i < end) {
|
|
227
|
+
i += (8 - ((i - 16) % 8)) % 8; // struct alignment, relative to the array start
|
|
228
|
+
if (i + 4 > end) break;
|
|
229
|
+
const code = buf[i];
|
|
230
|
+
const sigLen = buf[i + 1];
|
|
231
|
+
const sig = buf.toString("latin1", i + 2, i + 2 + sigLen);
|
|
232
|
+
i += 2 + sigLen + 1;
|
|
233
|
+
if (sig === "u") {
|
|
234
|
+
i += (4 - ((i - 16) % 4)) % 4;
|
|
235
|
+
if (i + 4 > end) break;
|
|
236
|
+
if (code === 5) replySerial = buf.readUInt32LE(i);
|
|
237
|
+
i += 4;
|
|
238
|
+
} else if (sig === "s" || sig === "o") {
|
|
239
|
+
i += (4 - ((i - 16) % 4)) % 4;
|
|
240
|
+
if (i + 4 > end) break;
|
|
241
|
+
const len = buf.readUInt32LE(i);
|
|
242
|
+
if (i + 4 + len > end) break;
|
|
243
|
+
if (code === 4) errorName = buf.toString("utf8", i + 4, i + 4 + len);
|
|
244
|
+
i += 4 + len + 1;
|
|
245
|
+
} else if (sig === "g") {
|
|
246
|
+
const len = buf[i];
|
|
247
|
+
i += 1 + len + 1;
|
|
248
|
+
} else {
|
|
249
|
+
break; // a type we do not send and cannot size; stop rather than guess
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return { type: buf[1], replySerial, errorName, bodyStart, bodyLength, total };
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Where this process's session bus lives.
|
|
257
|
+
*
|
|
258
|
+
* Two callers with opposite environments, one rule. A human running
|
|
259
|
+
* `failproofai audit` in their terminal HAS `DBUS_SESSION_BUS_ADDRESS`, and on
|
|
260
|
+
* an unusual setup it is the only correct answer — so it wins when it is there
|
|
261
|
+
* and names a socket we can open. The scheduled audit, a child of a system
|
|
262
|
+
* service started before login, has nothing: for it the address is CONSTRUCTED
|
|
263
|
+
* from the uid, which works because D-Bus EXTERNAL auth is `SO_PEERCRED` and
|
|
264
|
+
* the kernel supplies the identity the environment could not.
|
|
265
|
+
*
|
|
266
|
+
* Only the `unix:path=` form is honored. The spec allows `unix:abstract=`,
|
|
267
|
+
* `tcp:` and semicolon-separated alternatives; a bus we cannot dial is better
|
|
268
|
+
* reported as "no session" than dialed wrong, and the fallback below already
|
|
269
|
+
* covers every desktop that ships systemd.
|
|
270
|
+
*/
|
|
271
|
+
export function resolveBusPath(env: Readonly<Record<string, string | undefined>>): string | null {
|
|
272
|
+
const declared = env.DBUS_SESSION_BUS_ADDRESS;
|
|
273
|
+
if (declared) {
|
|
274
|
+
for (const part of declared.split(";")) {
|
|
275
|
+
const m = /^unix:(?:.*,)?path=([^,]+)/.exec(part.trim());
|
|
276
|
+
if (m) return m[1];
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
const uid = typeof process.getuid === "function" ? process.getuid() : -1;
|
|
280
|
+
return uid >= 0 ? `/run/user/${uid}/bus` : null;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Post a notification, awaiting the reply.
|
|
285
|
+
*
|
|
286
|
+
* `replacesId` reuses an earlier notification's id so repeated scans update one
|
|
287
|
+
* bubble instead of stacking a fresh alert every time — the difference between
|
|
288
|
+
* a reminder and a nag.
|
|
289
|
+
*/
|
|
290
|
+
export function notifyDesktop(
|
|
291
|
+
summary: string,
|
|
292
|
+
body: string,
|
|
293
|
+
replacesId = 0,
|
|
294
|
+
opts: { socketPath?: string } = {},
|
|
295
|
+
): Promise<NotifyOutcome> {
|
|
296
|
+
return new Promise((resolvePromise) => {
|
|
297
|
+
if (process.platform !== "linux" && !opts.socketPath) {
|
|
298
|
+
resolvePromise({ ok: false, reason: "error", detail: "linux only" });
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
const uid = typeof process.getuid === "function" ? process.getuid() : -1;
|
|
302
|
+
const path = opts.socketPath ?? resolveBusPath(process.env as Record<string, string | undefined>);
|
|
303
|
+
if (!path || uid < 0) {
|
|
304
|
+
resolvePromise({ ok: false, reason: "no-session", detail: "no bus address" });
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
let settled = false;
|
|
309
|
+
const done = (o: NotifyOutcome) => {
|
|
310
|
+
if (settled) return;
|
|
311
|
+
settled = true;
|
|
312
|
+
clearTimeout(timer);
|
|
313
|
+
try { sock.destroy(); } catch { /* already gone */ }
|
|
314
|
+
resolvePromise(o);
|
|
315
|
+
};
|
|
316
|
+
const timer = setTimeout(() => done({ ok: false, reason: "timeout", detail: `${TIMEOUT_MS}ms` }), TIMEOUT_MS);
|
|
317
|
+
|
|
318
|
+
let sock: Socket;
|
|
319
|
+
try {
|
|
320
|
+
sock = connect(path);
|
|
321
|
+
} catch (err) {
|
|
322
|
+
done({ ok: false, reason: "no-session", detail: String(err) });
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
let stage: "auth" | "hello" | "notify" = "auth";
|
|
327
|
+
let buf = Buffer.alloc(0);
|
|
328
|
+
|
|
329
|
+
sock.on("error", (err: NodeJS.ErrnoException) => {
|
|
330
|
+
// ENOENT: nobody is logged in, so /run/user/<uid> does not exist.
|
|
331
|
+
// ECONNREFUSED: a stale socket left behind by a dead bus.
|
|
332
|
+
done({
|
|
333
|
+
ok: false,
|
|
334
|
+
reason: err.code === "ENOENT" || err.code === "ECONNREFUSED" ? "no-session" : "error",
|
|
335
|
+
detail: err.code ?? String(err),
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
// A bus that hangs up mid-exchange is the signature of a message it could
|
|
340
|
+
// not parse. Without this the socket simply goes quiet and the whole thing
|
|
341
|
+
// reports a 2-second timeout — which points at a slow desktop rather than
|
|
342
|
+
// at us, and is exactly how the header-length bug survived its first tests.
|
|
343
|
+
sock.on("close", () => {
|
|
344
|
+
done({ ok: false, reason: "refused", detail: `bus closed the connection during ${stage}` });
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
sock.on("connect", () => {
|
|
348
|
+
// SASL EXTERNAL: the kernel already told the bus our uid over SO_PEERCRED,
|
|
349
|
+
// so the "credential" is just that uid in hex and no secret is exchanged.
|
|
350
|
+
const hexUid = Buffer.from(String(uid), "utf8").toString("hex");
|
|
351
|
+
sock.write(Buffer.concat([Buffer.from([0]), Buffer.from(`AUTH EXTERNAL ${hexUid}\r\n`, "utf8")]));
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
sock.on("data", (chunk: Buffer) => {
|
|
355
|
+
buf = Buffer.concat([buf, chunk]);
|
|
356
|
+
|
|
357
|
+
if (stage === "auth") {
|
|
358
|
+
const text = buf.toString("latin1");
|
|
359
|
+
const nl = text.indexOf("\r\n");
|
|
360
|
+
if (nl === -1) return;
|
|
361
|
+
if (!text.startsWith("OK")) {
|
|
362
|
+
done({ ok: false, reason: "refused", detail: text.slice(0, nl).trim().slice(0, 80) });
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
// Anything after the OK line is already binary protocol — keep it.
|
|
366
|
+
buf = buf.subarray(nl + 2);
|
|
367
|
+
stage = "hello";
|
|
368
|
+
sock.write(Buffer.from("BEGIN\r\n", "utf8"));
|
|
369
|
+
sock.write(methodCall(1, HELLO_FIELDS, Buffer.alloc(0)));
|
|
370
|
+
// Fall through: the reply may already be in `buf`.
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// Consume whole messages only. The bus answers Hello and then emits a
|
|
374
|
+
// NameAcquired SIGNAL; both can arrive in one chunk, and neither is
|
|
375
|
+
// guaranteed to arrive whole.
|
|
376
|
+
for (;;) {
|
|
377
|
+
const msg = readMessage(buf);
|
|
378
|
+
if (!msg) return;
|
|
379
|
+
const frame = buf.subarray(0, msg.total);
|
|
380
|
+
buf = buf.subarray(msg.total);
|
|
381
|
+
|
|
382
|
+
// 1 = METHOD_CALL, 2 = METHOD_RETURN, 3 = ERROR, 4 = SIGNAL.
|
|
383
|
+
if (msg.type === 4 || msg.type === 1) continue; // NameAcquired and friends
|
|
384
|
+
|
|
385
|
+
if (stage === "hello") {
|
|
386
|
+
if (msg.type === 3) {
|
|
387
|
+
done({ ok: false, reason: "refused", detail: msg.errorName ?? "Hello failed" });
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
if (msg.replySerial !== 1) continue;
|
|
391
|
+
stage = "notify";
|
|
392
|
+
sock.write(methodCall(2, NOTIFY_FIELDS, notifyBody("failproofai", replacesId, summary, body)));
|
|
393
|
+
continue;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// Only OUR call's reply settles this. Matching on serial rather than on
|
|
397
|
+
// "the next message" is what keeps an unrelated signal from being read
|
|
398
|
+
// as a successful delivery.
|
|
399
|
+
if (msg.replySerial !== 2) continue;
|
|
400
|
+
|
|
401
|
+
if (msg.type === 3) {
|
|
402
|
+
const name = msg.errorName ?? "";
|
|
403
|
+
// The common one: logged in, but nothing is drawing notifications.
|
|
404
|
+
const noServer = name.includes("ServiceUnknown") || name.includes("NameHasNoOwner");
|
|
405
|
+
done({ ok: false, reason: noServer ? "no-server" : "error", detail: name || "error" });
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// METHOD_RETURN. The body is a single UINT32 id — read it back so a
|
|
410
|
+
// future call could replace this bubble rather than stack a new one.
|
|
411
|
+
const id =
|
|
412
|
+
msg.bodyLength >= 4 && frame.length >= msg.bodyStart + 4
|
|
413
|
+
? frame.readUInt32LE(msg.bodyStart)
|
|
414
|
+
: 0;
|
|
415
|
+
done({ ok: true, id });
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
});
|
|
420
|
+
}
|
package/src/audit/harm-report.ts
CHANGED
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
*/
|
|
49
49
|
import type { AuditCount, AuditResult } from "./types";
|
|
50
50
|
import { redactExample } from "./redact-example";
|
|
51
|
+
import type { LeakFinding } from "./leak-record";
|
|
51
52
|
|
|
52
53
|
/** Severities that mean "the engine would have stopped this". */
|
|
53
54
|
const HARMFUL_SEVERITIES = new Set(["deny", "sanitize"]);
|
|
@@ -72,10 +73,58 @@ export interface ReportedPolicy {
|
|
|
72
73
|
examples: string[];
|
|
73
74
|
}
|
|
74
75
|
|
|
76
|
+
/**
|
|
77
|
+
* One leaked credential, as the digest carries it.
|
|
78
|
+
*
|
|
79
|
+
* **Nothing here can contain the secret**, and that is a structural property
|
|
80
|
+
* rather than a promise this function keeps. `LeakFinding` has no field holding
|
|
81
|
+
* the raw value — `recordLeaks` fingerprints at the moment of detection and
|
|
82
|
+
* stores only the mask — so there is no raw value on disk for this to leak even
|
|
83
|
+
* by accident. The most a bug here can send is a mask, a length and a label.
|
|
84
|
+
*
|
|
85
|
+
* The identifier NAME (`COMPOSIO_API_KEY`) is sent, and is not a secret: it is
|
|
86
|
+
* the left-hand side of an assignment, and for the first-party class — 230 of
|
|
87
|
+
* the 237 secret-named assignments the census measured, which no vendor console
|
|
88
|
+
* can revoke — it is the only actionable thing in the finding. Without it the
|
|
89
|
+
* digest can say a key leaked and not which one.
|
|
90
|
+
*/
|
|
91
|
+
export interface ReportedLeak {
|
|
92
|
+
/** The machine-local salted id, so a reader can act on the same row twice.
|
|
93
|
+
* An HMAC under a salt that never leaves the machine — it names the finding
|
|
94
|
+
* without describing it. */
|
|
95
|
+
id: string;
|
|
96
|
+
/** WHAT. `ghp_••••••••4f2a`, or `[13-char password]` when nothing was minted. */
|
|
97
|
+
display: string;
|
|
98
|
+
label: string;
|
|
99
|
+
length: number;
|
|
100
|
+
/** False means "we know it leaked, not who issued it" — which changes the
|
|
101
|
+
* advice from "revoke at this console" to "find where this came from". */
|
|
102
|
+
attributed: boolean;
|
|
103
|
+
/** The identifier it was assigned to, when there was one. */
|
|
104
|
+
name: string | null;
|
|
105
|
+
confidence: string;
|
|
106
|
+
first_seen: string;
|
|
107
|
+
last_seen: string;
|
|
108
|
+
occurrences: number;
|
|
109
|
+
/** WHO — the harness whose transcript carried it. */
|
|
110
|
+
cli: string;
|
|
111
|
+
/** WHERE — home-shortened already, like every path in `examples`. */
|
|
112
|
+
project: string;
|
|
113
|
+
/** HOW — "read from ~/…/.env". */
|
|
114
|
+
mechanism: string;
|
|
115
|
+
/** Input means the agent SENT it (deniable at PreToolUse next time); result
|
|
116
|
+
* means the agent RECEIVED it, which no gate can undo. */
|
|
117
|
+
direction: "input" | "result";
|
|
118
|
+
}
|
|
119
|
+
|
|
75
120
|
export interface HarmReport {
|
|
76
121
|
window_from?: string;
|
|
77
122
|
window_to: string;
|
|
78
123
|
harmful: ReportedPolicy[];
|
|
124
|
+
/** Credentials seen in this window. Separate from `harmful` because it is a
|
|
125
|
+
* different kind of claim: `harmful` counts policy activity, this names a
|
|
126
|
+
* specific object that needs rotating. */
|
|
127
|
+
leaks: ReportedLeak[];
|
|
79
128
|
}
|
|
80
129
|
|
|
81
130
|
/** `failproofai/block-rm-rf` → `block-rm-rf`. */
|
|
@@ -226,10 +275,61 @@ export function selectHarmful(
|
|
|
226
275
|
* lower bound", so a policy carrying no usable timestamps is reported once on a
|
|
227
276
|
* new machine rather than silently dropped by the bound this now always sets.
|
|
228
277
|
*/
|
|
278
|
+
/**
|
|
279
|
+
* The leaks worth putting in this window's digest.
|
|
280
|
+
*
|
|
281
|
+
* Windowed on `lastSeen`, not `firstSeen`: a key first seen months ago and used
|
|
282
|
+
* again yesterday is live, and reporting it only in the window it debuted would
|
|
283
|
+
* mean the digest goes quiet on exactly the credentials still in circulation.
|
|
284
|
+
*
|
|
285
|
+
* Dismissed findings never appear. A person who looked at a row and said "that
|
|
286
|
+
* is not a secret" has given the only judgement available that beats ours, and
|
|
287
|
+
* mailing it to them weekly afterwards is how a tool teaches people to filter
|
|
288
|
+
* it out of their inbox.
|
|
289
|
+
*/
|
|
290
|
+
export function selectLeaks(findings: LeakFinding[], from: Date, to: Date): ReportedLeak[] {
|
|
291
|
+
const lo = from.getTime();
|
|
292
|
+
const hi = to.getTime();
|
|
293
|
+
const out: ReportedLeak[] = [];
|
|
294
|
+
for (const f of findings) {
|
|
295
|
+
if (f.dismissedAt) continue;
|
|
296
|
+
const last = ts(f.lastSeen);
|
|
297
|
+
// No usable timestamp means it cannot be placed in a window. Included
|
|
298
|
+
// rather than dropped, for the same reason `includeUnplaceable` exists
|
|
299
|
+
// above: silence about a credential is the failure that costs something.
|
|
300
|
+
if (last !== null && (last < lo || last > hi)) continue;
|
|
301
|
+
// The most recent exposure is the one worth describing: it is where the key
|
|
302
|
+
// is now, not where it was first noticed.
|
|
303
|
+
// Defensive even though `readLeakRecord` already sanitises: this is
|
|
304
|
+
// exported and takes whatever a caller hands it.
|
|
305
|
+
const seen = f.sightings?.[f.sightings.length - 1];
|
|
306
|
+
out.push({
|
|
307
|
+
id: f.id,
|
|
308
|
+
display: f.fingerprint?.display ?? "[credential]",
|
|
309
|
+
label: f.fingerprint?.label ?? "secret",
|
|
310
|
+
length: f.fingerprint?.length ?? 0,
|
|
311
|
+
attributed: f.fingerprint?.attributed === true,
|
|
312
|
+
name: f.name,
|
|
313
|
+
confidence: f.confidence,
|
|
314
|
+
first_seen: f.firstSeen,
|
|
315
|
+
last_seen: f.lastSeen,
|
|
316
|
+
occurrences: f.occurrences,
|
|
317
|
+
cli: seen?.cli ?? "unknown",
|
|
318
|
+
project: seen?.cwd ?? "unknown",
|
|
319
|
+
mechanism: seen?.mechanism?.summary ?? "seen in a transcript",
|
|
320
|
+
direction: seen?.mechanism?.direction ?? "result",
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
// Most recently seen first: the digest's first row should be the one whose
|
|
324
|
+
// key is most likely still in use.
|
|
325
|
+
return out.sort((a, b) => (ts(b.last_seen) ?? 0) - (ts(a.last_seen) ?? 0));
|
|
326
|
+
}
|
|
327
|
+
|
|
229
328
|
export function buildHarmReport(
|
|
230
329
|
result: AuditResult,
|
|
231
330
|
lastReportedAt: string | undefined,
|
|
232
331
|
intervalDays: number,
|
|
332
|
+
leakFindings: LeakFinding[] = [],
|
|
233
333
|
): HarmReport {
|
|
234
334
|
const to = new Date(Date.parse(result.scannedAt));
|
|
235
335
|
const windowTo = Number.isFinite(to.getTime()) ? to : new Date();
|
|
@@ -256,5 +356,6 @@ export function buildHarmReport(
|
|
|
256
356
|
window_from: from.toISOString(),
|
|
257
357
|
window_to: windowTo.toISOString(),
|
|
258
358
|
harmful: selectHarmful(result, from, windowTo, { includeUnplaceable: isFirstReport }),
|
|
359
|
+
leaks: selectLeaks(leakFindings, from, windowTo),
|
|
259
360
|
};
|
|
260
361
|
}
|