@desplega.ai/agent-swarm 1.164.1 → 1.166.0
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/README.md +1 -1
- package/dist/acp-adapter-yzfxn8vj.js +23 -0
- package/dist/{actions-hp2h32dx.js → actions-qz3m692w.js} +24 -28
- package/dist/{amp-adapter-zfd7djyx.js → amp-adapter-j1xbmsqz.js} +7 -7
- package/dist/{app-w2d26h4f.js → app-43vrdmv8.js} +9 -10
- package/dist/{assistant-45pc4en7.js → assistant-ertffmka.js} +25 -29
- package/dist/{boot-reembed-k1q2s4fc.js → boot-reembed-998jtpdg.js} +12 -15
- package/dist/{boot-reembed-6rhcpsjf.js → boot-reembed-s7k7c6v2.js} +13 -15
- package/dist/boot-scrub-sweep-nepsk4t1.js +211 -0
- package/dist/{boot-seeds-ex93edx7.js → boot-seeds-vvzs1zhk.js} +12 -12
- package/dist/{claude-adapter-hcxd0szm.js → claude-adapter-2zvmekrp.js} +15 -17
- package/dist/{claude-managed-adapter-fz7xps2r.js → claude-managed-adapter-s49wbk8t.js} +5 -5
- package/dist/{claude-managed-setup-xx6f15h9.js → claude-managed-setup-cvhqq8qn.js} +4 -4
- package/dist/{claude-sdk-session-6nb9raem.js → claude-sdk-session-kkbxtw5q.js} +2624 -2606
- package/dist/{cli-etbrt8x1.js → cli-0nhdwxd5.js} +4 -4
- package/dist/{cli-jeefgppq.js → cli-0qjcsxgz.js} +7 -7
- package/dist/{cli-6behs2bt.js → cli-32bca7nr.js} +1 -1
- package/dist/{cli-gt8v96qx.js → cli-3ddybbbx.js} +4 -4
- package/dist/{acp-adapter-rxvek4ym.js → cli-3qn4r334.js} +317 -35
- package/dist/{cli-1d3w4xm3.js → cli-4r1sjfc4.js} +14 -6
- package/dist/{cli-691f2rxm.js → cli-66zh26sp.js} +68 -16
- package/dist/{cli-et8wdyqh.js → cli-68r1j4sg.js} +9 -9
- package/dist/{cli-xb7kyanp.js → cli-8kgvmkak.js} +3 -3
- package/dist/{cli-fdpkw8vk.js → cli-8t229cmr.js} +8 -8
- package/dist/{cli-gc54qc0p.js → cli-aqcey741.js} +1 -1
- package/dist/{cli-4q4cmr4t.js → cli-cpfmqz3n.js} +8 -8
- package/dist/{cli-a9bw0xxt.js → cli-df56tqdw.js} +997 -408
- package/dist/{cli-n7h1kqpf.js → cli-dmtrxqhg.js} +6 -1
- package/dist/{cli-xfb7333f.js → cli-dw2q9f7g.js} +5 -5
- package/dist/{cli-4drstbb9.js → cli-ecknp7p1.js} +81 -23
- package/dist/{cli-v0pvvhfq.js → cli-efnd2kce.js} +36 -1
- package/dist/{cli-1wetf34q.js → cli-f2n17zhp.js} +1 -1
- package/dist/{cli-2c8eky5y.js → cli-feh3dkah.js} +1 -1
- package/dist/cli-fn697bnt.js +126 -0
- package/dist/{cli-v5pr2fgt.js → cli-gt8azyet.js} +3 -3
- package/dist/{cli-dbszf3rw.js → cli-h3x613ze.js} +4 -4
- package/dist/{cli-nwhb8y2e.js → cli-hf5s9pgf.js} +1 -1
- package/dist/cli-j2jbr8af.js +516 -0
- package/dist/{cli-agjzafns.js → cli-jhm6hzjn.js} +593 -10
- package/dist/{cli-j0tmc908.js → cli-jvj6a0cv.js} +484 -477
- package/dist/{cli-xxz89c2n.js → cli-mb75wpxf.js} +1 -1
- package/dist/{cli-07s39g1n.js → cli-mv2520nm.js} +1 -1
- package/dist/{cli-v90vfwyb.js → cli-mwegs4af.js} +5 -5
- package/dist/{cli-bz1gbac9.js → cli-p4ztb80h.js} +2 -2
- package/dist/{cli-1wd1n2ya.js → cli-rfphkzh5.js} +1 -1
- package/dist/{cli-976r1zqx.js → cli-rggdq8wq.js} +5 -5
- package/dist/{cli-3ajw5v5v.js → cli-rsy933yz.js} +6 -6
- package/dist/{cli-yj790e19.js → cli-tadfgd0t.js} +8 -1
- package/dist/{cli-cn53e7vc.js → cli-ttbsse3f.js} +6 -1
- package/dist/{cli-dyqsrqcf.js → cli-v2a8x45d.js} +4 -4
- package/dist/{cli-wbvnn6tk.js → cli-v6vv7dy8.js} +91 -9
- package/dist/{cli-z2ap2c0c.js → cli-vzc73wet.js} +90 -55
- package/dist/cli-wt7ccy4r.js +2654 -0
- package/dist/{cli-4cn19jvn.js → cli-x7kpr72a.js} +3 -3
- package/dist/{cli-003785v9.js → cli-xvc3q9br.js} +1 -1
- package/dist/{cli-v0e7jpr5.js → cli-xvdgasgy.js} +13 -4
- package/dist/{cli-asqeg4ve.js → cli-y59h2pk9.js} +2 -2
- package/dist/{cli-0wn3ypqv.js → cli-yshaazs1.js} +14121 -3478
- package/dist/{cli-wg8yjqtw.js → cli-ysnyhws9.js} +16 -3
- package/dist/cli-zp67qg5x.js +92 -0
- package/dist/{cli-g3qgrzck.js → cli-zsh093hk.js} +71 -3
- package/dist/{cli-ma3zvh39.js → cli-zy7vwsne.js} +6066 -5829
- package/dist/cli.js +79 -26
- package/dist/{codex-adapter-pcxdn10v.js → codex-adapter-dw1wxqt8.js} +10 -10
- package/dist/{codex-hook-b1fb7c2k.js → codex-hook-d2rkvf39.js} +1 -1
- package/dist/{codex-login-059nm145.js → codex-login-terbdsqq.js} +2 -2
- package/dist/{codex-session-runner-xzwwddp8.js → codex-session-runner-3cgb8y1g.js} +10 -10
- package/dist/{commands-98at8mkn.js → commands-mhxam6z2.js} +9 -9
- package/dist/{cursor-adapter-dkg6qnkp.js → cursor-adapter-2qda3st7.js} +6 -6
- package/dist/{db-01g8wtvw.js → db-sjks418k.js} +11 -9
- package/dist/{devin-adapter-qmttt2fz.js → devin-adapter-bffjj5n4.js} +2 -2
- package/dist/{dispatcher-nn2k1wxd.js → dispatcher-1es759rn.js} +22 -26
- package/dist/{dsh-adapter-w4d4vwdq.js → dsh-adapter-bek4cyw9.js} +6 -6
- package/dist/{e2b-9e4g2hvt.js → e2b-nd50eccg.js} +1 -1
- package/dist/{event-bus-z7v2t26e.js → event-bus-vnfthafg.js} +2 -2
- package/dist/grok-adapter-ar9cw9jg.js +29 -0
- package/dist/{handlers-b0kqsbg8.js → handlers-1gkbhktr.js} +25 -29
- package/dist/{hook-sap7v1aj.js → hook-ds2zxq9v.js} +16 -18
- package/dist/{hook-pz50gqep.js → hook-vxa3tcsy.js} +10 -12
- package/dist/{http-ncr8rmd0.js → http-3h21z9md.js} +679 -227
- package/dist/{index-c4aqcyz1.js → index-9b65j1m5.js} +11 -11
- package/dist/{index-r46s01nq.js → index-bn6cy8ps.js} +22 -26
- package/dist/{index-38kqdt3e.js → index-dkfxpkmm.js} +23 -27
- package/dist/{index-630kj5vd.js → index-f8xnqrye.js} +55 -43
- package/dist/{index-fdk1t4d6.js → index-n0rxa4ca.js} +11962 -9900
- package/dist/{index-9nrj7797.js → index-n99fycq7.js} +22 -26
- package/dist/{keepalive-31613r2h.js → keepalive-3xspa9jw.js} +14 -11
- package/dist/{lead-mx59tr5s.js → lead-6qphc124.js} +43 -43
- package/dist/{maintenance-55ff39ca.js → maintenance-0teem1bb.js} +10 -12
- package/dist/{node-f0ykebbv.js → node-9sg7ajby.js} +25 -7
- package/dist/{oauth-refresh-sweep-anma954w.js → oauth-refresh-sweep-sh9q25xp.js} +13 -10
- package/dist/{onboard-b2fy8ftb.js → onboard-54qmnqxe.js} +4 -3
- package/dist/{opencode-adapter-p1s92tmy.js → opencode-adapter-wjfa2wvd.js} +6 -6
- package/dist/{otel-impl-9brvt7xv.js → otel-impl-ycqzp2a1.js} +2 -2
- package/dist/{pi-mono-adapter-kz4rrwvd.js → pi-mono-adapter-e77e9zst.js} +6 -6
- package/dist/{pricing-refresh-7w8mbmva.js → pricing-refresh-atnkngqs.js} +10 -10
- package/dist/{rbac-roles-ejp7qwvb.js → rbac-roles-9pjphh9q.js} +10 -10
- package/dist/{rbac-roles-nhk4r7bc.js → rbac-roles-j78wdksm.js} +10 -10
- package/dist/{render-v2-2gzt8skq.js → render-v2-pxjs49fx.js} +9 -10
- package/dist/{setup-5et8t412.js → setup-ymej0xtx.js} +2 -2
- package/dist/{work-objects-tb0er7qa.js → work-objects-3nh4ymzb.js} +26 -30
- package/dist/{worker-62cv075d.js → worker-qa9fkz5s.js} +43 -43
- package/dist/{x-vbxb31jr.js → x-ma4gnfgy.js} +2 -2
- package/openapi.json +457 -31
- package/package.json +14 -6
- package/plugin/commands/create-pr.md +7 -1
- package/plugin/pi-skills/create-pr/SKILL.md +7 -1
- package/src/agentmail/app.ts +5 -4
- package/src/be/automation-preflight.ts +11 -9
- package/src/be/boot-scrub-sweep.ts +302 -0
- package/src/be/connector-codes.ts +81 -0
- package/src/be/crypto/key-bootstrap.ts +1 -1
- package/src/be/db/approvals.ts +15 -1
- package/src/be/db/codex-oauth-device-flows.ts +40 -0
- package/src/be/db/config-secrets.ts +31 -0
- package/src/be/db/runtime.ts +4 -0
- package/src/be/db/script-runs.ts +15 -0
- package/src/be/db/tasks/write.ts +1 -1
- package/src/be/db-queries/mcp-oauth.ts +5 -0
- package/src/be/db-queries/oauth.ts +77 -0
- package/src/be/db.ts +162 -59
- package/src/be/events.ts +17 -1
- package/src/be/memory/index-content.ts +2 -2
- package/src/be/memory/providers/sqlite-store.ts +63 -11
- package/src/be/memory/types.ts +14 -0
- package/src/be/migrations/197_connector_codes.sql +23 -0
- package/src/be/migrations/198_permission_audit_guest.sql +33 -0
- package/src/be/migrations/200_backfill_auto_memory_expiry.sql +20 -0
- package/src/be/migrations/201_workflow_replay_columns.sql +10 -0
- package/src/be/migrations/202_codex_oauth_device_flows.sql +24 -0
- package/src/be/model-tier-resolution.ts +2 -1
- package/src/be/model-validation.ts +1 -1
- package/src/be/pricing-normalize.ts +3 -0
- package/src/be/rbac-audit.ts +2 -1
- package/src/be/scripts/db.ts +28 -4
- package/src/be/scripts/source-secrets.ts +37 -0
- package/src/be/scripts/typecheck.ts +23 -2
- package/src/be/scrub-json.ts +32 -0
- package/src/be/sealed-json.ts +59 -0
- package/src/be/secret-registry.ts +131 -0
- package/src/be/seed-pricing.ts +14 -0
- package/src/be/users.ts +7 -1
- package/src/be/workflow-replay.ts +77 -0
- package/src/cli.tsx +7 -0
- package/src/commands/provider-credentials.ts +46 -8
- package/src/commands/runner.ts +2 -10
- package/src/extensions/contract-types.generated.ts +1 -1
- package/src/github/app.ts +4 -4
- package/src/heartbeat/heartbeat.ts +20 -8
- package/src/hooks/pr-body-guard.ts +1 -1
- package/src/http/agents.ts +1 -0
- package/src/http/approval-requests.ts +1 -0
- package/src/http/apps.ts +3 -0
- package/src/http/auth.ts +4 -1
- package/src/http/codex-oauth-device.ts +8 -10
- package/src/http/codex-oauth-keep-warm.ts +2 -2
- package/src/http/config-values.ts +59 -0
- package/src/http/config.ts +5 -0
- package/src/http/db-query-bounded.ts +3 -0
- package/src/http/db-query-shared.ts +107 -15
- package/src/http/db-query.ts +10 -2
- package/src/http/extensions.ts +1 -0
- package/src/http/index.ts +23 -6
- package/src/http/integrations.ts +1 -38
- package/src/http/ip-rate-limit.ts +82 -0
- package/src/http/kv.ts +38 -4
- package/src/http/mcp-servers.ts +1 -0
- package/src/http/memory.ts +9 -0
- package/src/http/models-catalog.ts +2 -0
- package/src/http/operator-actor.ts +4 -0
- package/src/http/page-proxy.ts +22 -0
- package/src/http/pages.ts +4 -2
- package/src/http/realtime.ts +1 -1
- package/src/http/request-principal.ts +14 -1
- package/src/http/script-connections.ts +8 -0
- package/src/http/script-runs.ts +12 -4
- package/src/http/scripts.ts +15 -0
- package/src/http/session-cost-recompute.ts +3 -2
- package/src/http/tasks.ts +9 -0
- package/src/http/users.ts +226 -0
- package/src/http/workflows.ts +3 -2
- package/src/http.ts +1 -0
- package/src/integrations/kapso/client.ts +3 -1
- package/src/jira/app.ts +2 -2
- package/src/kv-view.ts +324 -0
- package/src/linear/app.ts +2 -2
- package/src/oauth/mcp-wrapper.ts +1 -1
- package/src/prompts/memories.ts +42 -1
- package/src/providers/acp-adapter.ts +85 -24
- package/src/providers/acp-target-catalog.ts +54 -1
- package/src/providers/acp-targets.ts +358 -4
- package/src/providers/amp-adapter.ts +1 -1
- package/src/providers/cursor-adapter.ts +1 -1
- package/src/providers/grok-adapter.ts +186 -0
- package/src/providers/index.ts +5 -1
- package/src/providers/pricing-sources.md +6 -0
- package/src/providers/reasoning-effort.ts +17 -1
- package/src/providers/types.ts +2 -1
- package/src/rbac/can.ts +4 -3
- package/src/rbac/legacy-policy.ts +3 -3
- package/src/rbac/types.ts +6 -0
- package/src/script-workflows/supervisor.ts +11 -2
- package/src/scripts-runtime/eval-harness.ts +2 -12
- package/src/scripts-runtime/executors/quickjs-bundle.ts +152 -0
- package/src/scripts-runtime/executors/quickjs-prelude.ts +285 -0
- package/src/scripts-runtime/executors/quickjs-runner.ts +580 -0
- package/src/scripts-runtime/executors/quickjs-worker.ts +81 -0
- package/src/scripts-runtime/executors/quickjs.ts +196 -0
- package/src/scripts-runtime/executors/registry.ts +2 -0
- package/src/scripts-runtime/executors/sourcemap.ts +79 -0
- package/src/scripts-runtime/script-error-hints.ts +14 -0
- package/src/scripts-runtime/swarm-sdk.ts +9 -2
- package/src/scripts-runtime/types/stdlib.d.ts +27 -8
- package/src/scripts-runtime/types/swarm-extension.d.ts +3 -0
- package/src/scripts-runtime/types/swarm-sdk.d.ts +27 -8
- package/src/server-user.ts +2 -20
- package/src/server.ts +3 -1
- package/src/slack/app.ts +4 -0
- package/src/slack/config.ts +3 -1
- package/src/slack/egress-scrub.ts +87 -0
- package/src/tests/acp-adapter.test.ts +191 -2
- package/src/tests/boot-scrub-sweep.test.ts +390 -0
- package/src/tests/budget-user-scope.test.ts +7 -21
- package/src/tests/check-pr-body.test.ts +149 -6
- package/src/tests/check-text-columns.test.ts +145 -0
- package/src/tests/claude-adapter-binary.test.ts +1 -1
- package/src/tests/claude-sdk-process.fixture.ts +13 -2
- package/src/tests/codex-oauth-device.test.ts +23 -37
- package/src/tests/codex-oauth-keep-warm.test.ts +29 -0
- package/src/tests/console-scrub.test.ts +141 -0
- package/src/tests/credential-check.test.ts +90 -0
- package/src/tests/db-query-denylist.test.ts +202 -0
- package/src/tests/db-task-read-contract.test.ts +1 -0
- package/src/tests/db-task-write-contract.test.ts +1 -0
- package/src/tests/docs-index-footprint.test.js +3 -3
- package/src/tests/entrypoint-acp-target-binary.test.ts +44 -1
- package/src/tests/events-scrub.test.ts +88 -0
- package/src/tests/explicit-model-validation.test.ts +81 -0
- package/src/tests/extensions-pre-task.test.ts +33 -1
- package/src/tests/fixtures/grok/acp-updates-recorded.jsonl +53 -0
- package/src/tests/fixtures/grok/prompt-response-meta.json +36 -0
- package/src/tests/fixtures/secret-corpus.ts +320 -0
- package/src/tests/grok-adapter.test.ts +647 -0
- package/src/tests/heartbeat-checklist.test.ts +44 -0
- package/src/tests/integration-disable-flags.test.ts +156 -0
- package/src/tests/kv-http.test.ts +34 -0
- package/src/tests/kv-tool.test.ts +274 -1
- package/src/tests/kv-view.test.ts +147 -0
- package/src/tests/mcp-user-route.test.ts +257 -15
- package/src/tests/memory-injection-outcome.test.ts +143 -0
- package/src/tests/model-tier-resolution.test.ts +76 -3
- package/src/tests/page-guest-session.test.ts +424 -0
- package/src/tests/page-proxy.test.ts +1 -1
- package/src/tests/page-viewer-auth.test.ts +22 -1
- package/src/tests/pr-body-leaks.test.ts +157 -2
- package/src/tests/preload.ts +10 -0
- package/src/tests/provider-registration.test.ts +3 -1
- package/src/tests/rbac-audit.test.ts +32 -0
- package/src/tests/rbac-mcp-admission-e2e.test.ts +4 -62
- package/src/tests/script-connections.test.ts +9 -0
- package/src/tests/script-executor-conformance.test.ts +3 -0
- package/src/tests/script-executor-quickjs.test.ts +442 -0
- package/src/tests/script-executor-registry.test.ts +6 -1
- package/src/tests/script-runs-http.test.ts +126 -1
- package/src/tests/script-runs-scrub.test.ts +275 -0
- package/src/tests/scripts-http.test.ts +82 -1
- package/src/tests/scripts-mcp-e2e.test.ts +42 -6
- package/src/tests/scripts-runtime.test.ts +37 -0
- package/src/tests/scrubbed-text-12e.test.ts +289 -0
- package/src/tests/sealed-key-guard.test.ts +166 -0
- package/src/tests/secret-canary-sweep.test.ts +958 -0
- package/src/tests/secret-registry.test.ts +355 -0
- package/src/tests/secret-rules.test.ts +230 -0
- package/src/tests/secret-scrubber.test.ts +317 -1
- package/src/tests/session-costs-golden.test.ts +17 -0
- package/src/tests/slack-egress-scrub.test.ts +216 -0
- package/src/tests/swarm-tool-result-gate.test.ts +143 -30
- package/src/tests/task-tools-ctx.test.ts +3 -0
- package/src/tests/user-token-routes.test.ts +342 -3
- package/src/tests/workflow-replay.test.ts +518 -0
- package/src/tests/workflow-scrub.test.ts +242 -0
- package/src/tests/workflow-system-one-decision-providers.test.ts +737 -0
- package/src/tools/db-query.ts +1 -1
- package/src/tools/inject-learning.ts +1 -1
- package/src/tools/kv/kv-get.ts +136 -6
- package/src/tools/send-task.ts +61 -17
- package/src/tools/utils.ts +186 -43
- package/src/tools/workflows/get-workflow-run.ts +3 -2
- package/src/types.ts +16 -1
- package/src/utils/console-scrub-install.ts +5 -0
- package/src/utils/console-scrub.ts +57 -0
- package/src/utils/credentials.ts +8 -0
- package/src/utils/page-session.ts +6 -2
- package/src/utils/pr-body-leaks.ts +149 -10
- package/src/utils/request-auth-context.ts +2 -0
- package/src/utils/secret-rules.generated.ts +2055 -0
- package/src/utils/secret-scrubber.ts +662 -36
- package/src/workflows/engine.ts +39 -4
- package/src/workflows/executors/notify.ts +6 -1
- package/src/workflows/executors/system-one-decision.ts +31 -12
- package/src/workflows/executors/system-one-openai-wire.ts +168 -0
- package/src/workflows/executors/system-one-providers.ts +112 -11
- package/src/workflows/executors/system-one-wire.ts +79 -0
- package/src/workflows/recovery.ts +10 -1
- package/src/workflows/resume.ts +62 -3
- package/src/workflows/retry-poller.ts +3 -0
- package/templates/ai-toolbox.manifest.json +2 -2
- package/templates/skills/agent-browser/SKILL.md +5 -5
- package/templates/skills/agent-browser/config.json +1 -1
- package/templates/skills/agent-browser/content.md +4 -4
- package/templates/skills/artifacts/content.md +17 -7
- package/templates/skills/jira-interaction/config.json +1 -1
- package/templates/skills/jira-interaction/content.md +56 -205
- package/templates/skills/linear-interaction/config.json +1 -1
- package/templates/skills/linear-interaction/content.md +31 -50
- package/templates/skills/pages/content.md +8 -4
- package/templates/skills/qa/content.md +2 -2
- package/templates/skills/workflow-iterate/content.md +4 -4
- package/tsconfig.json +3 -3
- package/dist/boot-scrub-logs-t8xg7wd7.js +0 -99
- package/dist/cli-0a7r5331.js +0 -168
- package/dist/cli-93rxw9yd.js +0 -951
- package/dist/cli-cvk6yzw5.js +0 -40
- package/dist/cli-dgnj0zcc.js +0 -40
- package/dist/cli-qt5wzq6v.js +0 -256
- package/dist/cli-v7fqehqd.js +0 -9281
- package/dist/cli-vbr859rz.js +0 -572
- package/src/be/boot-scrub-logs.ts +0 -132
|
@@ -21,6 +21,24 @@
|
|
|
21
21
|
* API↔worker DB boundary (scripts/check-db-boundary.sh).
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
+
import { GITLEAKS_RULES } from "./secret-rules.generated";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Version of the redaction rules below. Bump it on EVERY rule change (new
|
|
28
|
+
* key, suffix, regex, pass or threshold): the API's boot retro-sweep
|
|
29
|
+
* (src/be/boot-scrub-sweep.ts) keys its done marker on this number and
|
|
30
|
+
* re-scrubs stored rows once per version. v2 = the #1907 rules, swept over
|
|
31
|
+
* session_logs only; v3 = the first version swept across every target table;
|
|
32
|
+
* v4 = the API's secret registry (src/be/secret-registry.ts) registers every
|
|
33
|
+
* stored secret at boot, plus its base64, base64url and URL-encoded forms, and
|
|
34
|
+
* the known-value pass matches them all through one combined regex; v5 = pass
|
|
35
|
+
* 5, the vendored gitleaks rule set, plus hand-written Resend, Google OAuth,
|
|
36
|
+
* Discord webhook, xAI and bare Telegram shapes in pass 2; v6 = pass 5 resumes
|
|
37
|
+
* after the secret, not the match, so adjacent secrets that share a delimiter
|
|
38
|
+
* both redact, and sourcegraph-access-token drops its bare 40-hex branch.
|
|
39
|
+
*/
|
|
40
|
+
export const SCRUBBER_RULES_VERSION = 6;
|
|
41
|
+
|
|
24
42
|
/** Env-var names that are always considered secrets, even without suffix hints. */
|
|
25
43
|
const SENSITIVE_KEY_EXACT = new Set<string>([
|
|
26
44
|
"API_KEY",
|
|
@@ -67,9 +85,25 @@ const SENSITIVE_KEY_EXACT = new Set<string>([
|
|
|
67
85
|
"LINEAR_OAUTH_CLIENT_SECRET",
|
|
68
86
|
"OTEL_EXPORTER_OTLP_HEADERS",
|
|
69
87
|
"SIGNOZ_INGESTION_KEY",
|
|
88
|
+
// Bare names, as they appear in .env files, JSON/YAML configs and headers.
|
|
89
|
+
// `PWD` is deliberately absent: it is the shell's working directory.
|
|
90
|
+
"SECRET",
|
|
91
|
+
"PASSWORD",
|
|
92
|
+
"PASSWD",
|
|
93
|
+
"TOKEN",
|
|
94
|
+
"PRIVATE_KEY",
|
|
95
|
+
"APIKEY",
|
|
96
|
+
"ACCESS_TOKEN",
|
|
97
|
+
"REFRESH_TOKEN",
|
|
98
|
+
"CLIENT_SECRET",
|
|
99
|
+
"AUTHORIZATION",
|
|
100
|
+
"CREDENTIALS",
|
|
70
101
|
]);
|
|
71
102
|
|
|
72
|
-
/**
|
|
103
|
+
/**
|
|
104
|
+
* Suffixes that mark an env-var value as sensitive by convention. There is no
|
|
105
|
+
* bare `_KEY` suffix: it would match `SORT_KEY`, `PRIMARY_KEY`, `contextKey`.
|
|
106
|
+
*/
|
|
73
107
|
const SENSITIVE_KEY_SUFFIXES = [
|
|
74
108
|
"_API_KEY",
|
|
75
109
|
"_TOKEN",
|
|
@@ -77,6 +111,13 @@ const SENSITIVE_KEY_SUFFIXES = [
|
|
|
77
111
|
"_PASSWORD",
|
|
78
112
|
"_PASS",
|
|
79
113
|
"_PRIVATE_KEY",
|
|
114
|
+
"_ACCESS_KEY",
|
|
115
|
+
"_SECRET_KEY",
|
|
116
|
+
"_APIKEY",
|
|
117
|
+
"_AUTH_HEADER",
|
|
118
|
+
"_CREDENTIALS",
|
|
119
|
+
"_DSN",
|
|
120
|
+
"_DEPLOY_KEY",
|
|
80
121
|
];
|
|
81
122
|
|
|
82
123
|
/** Keys that match the sensitive suffix heuristic but are actually safe URLs/configs. */
|
|
@@ -85,8 +126,33 @@ const NON_SECRET_EXCEPTIONS = new Set<string>([
|
|
|
85
126
|
"APP_URL",
|
|
86
127
|
"API_URL",
|
|
87
128
|
"TEMPLATE_REGISTRY_URL",
|
|
129
|
+
// A file path, not the credential itself.
|
|
130
|
+
"GOOGLE_APPLICATION_CREDENTIALS",
|
|
131
|
+
// Pagination cursors. Tool results are scrubbed before the model sees them,
|
|
132
|
+
// so redacting these would break paging through an API response.
|
|
133
|
+
"PAGE_TOKEN",
|
|
134
|
+
"NEXT_PAGE_TOKEN",
|
|
135
|
+
"PREV_PAGE_TOKEN",
|
|
136
|
+
"NEXT_TOKEN",
|
|
137
|
+
"CONTINUATION_TOKEN",
|
|
138
|
+
"SYNC_TOKEN",
|
|
139
|
+
"NEXT_SYNC_TOKEN",
|
|
88
140
|
]);
|
|
89
141
|
|
|
142
|
+
/**
|
|
143
|
+
* Canonical form of a key name for the sensitivity check: camelCase becomes
|
|
144
|
+
* snake case (`apiKey` → `API_KEY`), `.` and `-` become `_`, and the result is
|
|
145
|
+
* uppercased. An all-caps key is never split (`OAUTH2TOKEN` stays whole).
|
|
146
|
+
*/
|
|
147
|
+
export function normalizeKey(key: string): string {
|
|
148
|
+
if (!/[a-z.-]/.test(key)) return key;
|
|
149
|
+
let out = key;
|
|
150
|
+
if (/[a-z]/.test(out) && /[A-Z]/.test(out)) {
|
|
151
|
+
out = out.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2");
|
|
152
|
+
}
|
|
153
|
+
return out.replace(/[.-]/g, "_").toUpperCase();
|
|
154
|
+
}
|
|
155
|
+
|
|
90
156
|
/**
|
|
91
157
|
* Minimum length for an env-var value to be considered scrub-worthy.
|
|
92
158
|
* Short values (< 12 chars) cause false-positive replacements across
|
|
@@ -150,15 +216,26 @@ const BARE = String.raw`(?!\$)(?:\\[^nrtu"\s]|[^\s"'\\])+`;
|
|
|
150
216
|
* `KEY=value` where the value is redacted when KEY is sensitive, whatever the
|
|
151
217
|
* value's length and whether this process ever saw it (e.g. a token the
|
|
152
218
|
* harness generated inside a child process). The key must start a word or
|
|
153
|
-
* follow a JSON `\n`/`\r`/`\t` escape
|
|
219
|
+
* follow a JSON `\n`/`\r`/`\t` escape, and may contain dots
|
|
220
|
+
* (`SLACK.BOT.TOKEN=`). `==` comparisons are not assignments. There is no
|
|
221
|
+
* whitespace around `=` here, so `const password = getPassword()` in a logged
|
|
222
|
+
* diff is never touched; spaced `key = value` is only matched line-anchored
|
|
223
|
+
* (INI_ASSIGNMENT_RE).
|
|
154
224
|
*/
|
|
155
225
|
const ASSIGNMENT_RE = new RegExp(
|
|
156
|
-
String.raw`(?:(?<=\\[nrt])|(?<![\w
|
|
226
|
+
String.raw`(?:(?<=\\[nrt])|(?<![\w\\.]))([A-Za-z_][A-Za-z0-9_.]*)=(?!=)(${JSON_DQ}|${RAW_DQ}|${SQ}|${BARE})`,
|
|
157
227
|
"g",
|
|
158
228
|
);
|
|
159
229
|
|
|
230
|
+
/** A dotted key is sensitive when the whole name or its last segment is. */
|
|
231
|
+
function isSensitiveKeyPath(key: string): boolean {
|
|
232
|
+
if (isSensitiveKey(key)) return true;
|
|
233
|
+
const dot = key.lastIndexOf(".");
|
|
234
|
+
return dot >= 0 && isSensitiveKey(key.slice(dot + 1));
|
|
235
|
+
}
|
|
236
|
+
|
|
160
237
|
function redactAssignment(match: string, key: string, value: string): string {
|
|
161
|
-
if (!
|
|
238
|
+
if (!isSensitiveKeyPath(key)) return match;
|
|
162
239
|
let open = "";
|
|
163
240
|
let close = "";
|
|
164
241
|
for (const quote of ['\\"', '"', "'"]) {
|
|
@@ -172,6 +249,214 @@ function redactAssignment(match: string, key: string, value: string): string {
|
|
|
172
249
|
return `${key}=${open}[REDACTED:${key}]${close}`;
|
|
173
250
|
}
|
|
174
251
|
|
|
252
|
+
/**
|
|
253
|
+
* Values the key-context rules leave alone: empty, already redacted, a
|
|
254
|
+
* reference or template (`$VAR`, `${{ … }}`, `<your-token>`, `***`, `%VAR%`,
|
|
255
|
+
* `{{ x }}`), a YAML/JSON literal, or a bare number.
|
|
256
|
+
*/
|
|
257
|
+
function isPlaceholderValue(value: string): boolean {
|
|
258
|
+
return (
|
|
259
|
+
value === "" ||
|
|
260
|
+
value.includes("[REDACTED") ||
|
|
261
|
+
/^[$<*%{]/.test(value) ||
|
|
262
|
+
/^(?:null|none|nil|true|false|yes|no|undefined|~)$/i.test(value) ||
|
|
263
|
+
/^[+-]?\d+(?:\.\d+)?$/.test(value)
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* An unquoted right-hand side that reads as code or prose rather than a
|
|
269
|
+
* literal credential: a call, index, object or list (`get_token()`,
|
|
270
|
+
* `env["X"]`), a trailing `,`/`;`, a member chain (`process.env.TOKEN`), or a
|
|
271
|
+
* short plain word (`string`, `pwd`, `required`) as in a TS type or a name.
|
|
272
|
+
*/
|
|
273
|
+
function looksLikeCode(value: string): boolean {
|
|
274
|
+
return (
|
|
275
|
+
/[()[\]{};,]/.test(value) ||
|
|
276
|
+
/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)+$/.test(value) ||
|
|
277
|
+
(/^[A-Za-z_]+$/.test(value) && value.length < 16)
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Line boundaries, raw or as JSON `\n`/`\r` escapes inside a session-log
|
|
282
|
+
// string (whose closing `"` also ends the last line).
|
|
283
|
+
const LINE_START = String.raw`(?:^|(?<=\\[nr]))`;
|
|
284
|
+
const LINE_END = String.raw`(?=[ \t]*(?:$|\r|\\[nr]|"))`;
|
|
285
|
+
// A one-line value: double-, single- or JSON-escaped-double-quoted, or bare.
|
|
286
|
+
const LINE_VALUE = String.raw`"[^"\\\r\n]*"|'[^'\\\r\n]*'|\\"[^"\\\r\n]*\\"|[^\s"'\\]+`;
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Line-anchored INI/TOML `key = value` (`aws_secret_access_key = …` in
|
|
290
|
+
* ~/.aws/credentials). Spaces around `=` are only accepted here, where the
|
|
291
|
+
* key starts the line, so `const password = getPassword()` stays intact.
|
|
292
|
+
*/
|
|
293
|
+
const INI_ASSIGNMENT_RE = new RegExp(
|
|
294
|
+
String.raw`${LINE_START}([ \t]*)([A-Za-z_][\w.]*)([ \t]*=[ \t]*)(${LINE_VALUE})${LINE_END}`,
|
|
295
|
+
"gm",
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
/** Line-anchored YAML `key: value`, including list items (`- token: …`). */
|
|
299
|
+
const YAML_KEY_RE = new RegExp(
|
|
300
|
+
String.raw`${LINE_START}([ \t]*(?:-[ \t]+)?)([A-Za-z_][\w.-]*)([ \t]*:[ \t]+)(${LINE_VALUE})${LINE_END}`,
|
|
301
|
+
"gm",
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
function redactLineValue(
|
|
305
|
+
match: string,
|
|
306
|
+
lead: string,
|
|
307
|
+
key: string,
|
|
308
|
+
sep: string,
|
|
309
|
+
value: string,
|
|
310
|
+
): string {
|
|
311
|
+
if (!isSensitiveKeyPath(key)) return match;
|
|
312
|
+
const quote = /^(?:\\"|"|')/.exec(value)?.[0] ?? "";
|
|
313
|
+
const inner = quote ? value.slice(quote.length, -quote.length) : value;
|
|
314
|
+
if (isPlaceholderValue(inner) || (!quote && looksLikeCode(inner))) return match;
|
|
315
|
+
return `${lead}${key}${sep}${quote}[REDACTED:${key}]${quote}`;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const JSON_KEY = String.raw`[A-Za-z_][\w.-]{0,63}`;
|
|
319
|
+
/**
|
|
320
|
+
* The opening of `"key": "value"`, raw or JSON-escaped inside a session-log
|
|
321
|
+
* string (`\"key\":\"value\"`). Only string values are redacted. The value
|
|
322
|
+
* itself is walked by `jsonStringEnd`, not by the regex: a backtracking value
|
|
323
|
+
* pattern costs ~100 ms on a 200 KB unterminated value.
|
|
324
|
+
*/
|
|
325
|
+
const JSON_KEY_RE = new RegExp(String.raw`"(${JSON_KEY})"[ \t]*:[ \t]*"`, "g");
|
|
326
|
+
const ESCAPED_JSON_KEY_RE = new RegExp(String.raw`\\"(${JSON_KEY})\\"[ \t]*:[ \t]*\\"`, "g");
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Index of the quote token that closes the JSON string body starting at
|
|
330
|
+
* `start`. If the line ends first, returns `-(stop + 1)` where `stop` is the
|
|
331
|
+
* index the walk halted at, so the caller can resume past it. Escapes are
|
|
332
|
+
* consumed whole, so a PEM with `\n` escapes ends at its real closing quote.
|
|
333
|
+
* With `escaped`, the body is itself JSON-escaped: each `\x` pair is one inner
|
|
334
|
+
* character, and the close is an inner `"` (the pair `\"`) not preceded by an
|
|
335
|
+
* inner `\`.
|
|
336
|
+
*/
|
|
337
|
+
function jsonStringEnd(text: string, start: number, escaped: boolean): number {
|
|
338
|
+
let innerEscape = false;
|
|
339
|
+
for (let i = start; i < text.length; i++) {
|
|
340
|
+
let ch = text[i];
|
|
341
|
+
if (ch === "\r" || ch === "\n") return -(i + 1);
|
|
342
|
+
const at = i;
|
|
343
|
+
if (escaped) {
|
|
344
|
+
if (ch === '"') return -(i + 1);
|
|
345
|
+
if (ch === "\\") {
|
|
346
|
+
ch = text[++i];
|
|
347
|
+
if (ch === undefined || ch === "\r" || ch === "\n") return -(i + 1);
|
|
348
|
+
if (ch !== "\\" && ch !== '"') ch = "x";
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
if (innerEscape) innerEscape = false;
|
|
352
|
+
else if (ch === "\\") innerEscape = true;
|
|
353
|
+
else if (ch === '"') return at;
|
|
354
|
+
}
|
|
355
|
+
return -(text.length + 1);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function redactJsonValues(text: string, re: RegExp, escaped: boolean): string {
|
|
359
|
+
let out = "";
|
|
360
|
+
let last = 0;
|
|
361
|
+
re.lastIndex = 0;
|
|
362
|
+
for (let m = re.exec(text); m; m = re.exec(text)) {
|
|
363
|
+
const key = m[1] ?? "";
|
|
364
|
+
if (!isSensitiveKeyPath(key)) continue;
|
|
365
|
+
const valueStart = m.index + m[0].length;
|
|
366
|
+
const end = jsonStringEnd(text, valueStart, escaped);
|
|
367
|
+
if (end < 0) {
|
|
368
|
+
// Resume where the walk stopped so no span is walked twice. Back off one
|
|
369
|
+
// character: an escaped walk stops on the bare `"` of a `\"` opener.
|
|
370
|
+
re.lastIndex = Math.max(re.lastIndex, -end - 2);
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
re.lastIndex = end + 1;
|
|
374
|
+
if (isPlaceholderValue(text.slice(valueStart, end))) continue;
|
|
375
|
+
out += `${text.slice(last, valueStart)}[REDACTED:${key}]`;
|
|
376
|
+
last = end;
|
|
377
|
+
}
|
|
378
|
+
return last === 0 ? text : out + text.slice(last);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// An RFC 7235 token68 credential, as carried by Authorization headers.
|
|
382
|
+
// It must end the run, so a fragment glued to a marker (`x-[REDACTED:…]`) is skipped.
|
|
383
|
+
const TOKEN68 = String.raw`[A-Za-z0-9._~+/=-]{8,}(?![A-Za-z0-9._~+/=\[-])`;
|
|
384
|
+
// `Header: ` in raw, JSON (`"Header": "`), escaped JSON and curl `-H '…'` forms.
|
|
385
|
+
const HEADER_SEP = String.raw`\\?["']?[ \t]*:[ \t]*\\?["']?`;
|
|
386
|
+
|
|
387
|
+
/** `Authorization: Bearer <cred>`; the scheme survives redaction. */
|
|
388
|
+
const AUTH_HEADER_RE = new RegExp(
|
|
389
|
+
String.raw`(?<![\w-])((?:proxy-)?authorization)(${HEADER_SEP}(?:bearer|basic|token|bot)[ \t]+)(${TOKEN68})`,
|
|
390
|
+
"gi",
|
|
391
|
+
);
|
|
392
|
+
const API_KEY_HEADER_RE = new RegExp(
|
|
393
|
+
String.raw`(?<![\w-])(x-api-key)(${HEADER_SEP})(${TOKEN68})`,
|
|
394
|
+
"gi",
|
|
395
|
+
);
|
|
396
|
+
|
|
397
|
+
function redactHeader(match: string, name: string, sep: string, value: string): string {
|
|
398
|
+
if (/^[A-Za-z_]+$/.test(value) && value.length < 16) return match; // a prose word
|
|
399
|
+
return `${name}${sep}[REDACTED:${name.toLowerCase().replace(/-/g, "_")}]`;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/** curl `--password <pw>` and `-u|--user|-U|--proxy-user user:<pw>`. */
|
|
403
|
+
const CURL_PASSWORD_RE = /(?<=^|[\s'"])(--password(?:[ \t]+|=)\\?["']?)([^\s"'\\]+)/g;
|
|
404
|
+
const CURL_USER_RE =
|
|
405
|
+
/(?<=^|[\s'"])((?:-u|-U|--user|--proxy-user)(?:[ \t]+|=)\\?["']?([^\s"'\\:@]+):)([^\s"'\\@]+)/g;
|
|
406
|
+
|
|
407
|
+
/** `scheme://user:<pw>@host`: only the password goes, the host survives. */
|
|
408
|
+
const URL_USERINFO_RE =
|
|
409
|
+
/(?<![a-z0-9+.-])([a-z][a-z0-9+.-]{0,31}:\/\/[^\s/:@?#"'\\]+:)([^\s/@?#"'\\]+)(?=@)/gi;
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* PEM private-key blocks, raw or with literal `\n` escapes. The body cannot
|
|
413
|
+
* contain `-----`, so a missing END marker costs one scan to the next dash
|
|
414
|
+
* run, and the 16 KB cap bounds even that.
|
|
415
|
+
*/
|
|
416
|
+
const PEM_RE =
|
|
417
|
+
/(-----BEGIN [A-Z0-9 ]{0,32}PRIVATE KEY(?: BLOCK)?-----)((?:(?!-----)[\s\S]){1,16384})(-----END [A-Z0-9 ]{0,32}PRIVATE KEY(?: BLOCK)?-----)/g;
|
|
418
|
+
const PEM_MARKER = "[REDACTED:private_key]";
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Pass 4: credentials identified by their context (a sensitive JSON/YAML
|
|
422
|
+
* key, an auth header, a curl flag, URL userinfo, PEM armor) rather than by a
|
|
423
|
+
* vendor prefix. Every rule skips a value that is already redacted, so the
|
|
424
|
+
* pass is idempotent.
|
|
425
|
+
*/
|
|
426
|
+
function scrubKeyContext(text: string): string {
|
|
427
|
+
let out = text;
|
|
428
|
+
if (out.includes("PRIVATE KEY")) {
|
|
429
|
+
out = out.replace(PEM_RE, (match, begin: string, body: string, end: string) =>
|
|
430
|
+
body === PEM_MARKER ? match : `${begin}${PEM_MARKER}${end}`,
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
if (/authorization|x-api-key/i.test(out)) {
|
|
434
|
+
out = out.replace(AUTH_HEADER_RE, redactHeader).replace(API_KEY_HEADER_RE, redactHeader);
|
|
435
|
+
}
|
|
436
|
+
if (out.includes("--password")) {
|
|
437
|
+
out = out.replace(CURL_PASSWORD_RE, (match, flag: string, pw: string) =>
|
|
438
|
+
isPlaceholderValue(pw) ? match : `${flag}[REDACTED:curl_password]`,
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
if (/(?:^|\s)-(?:u|U|-user|-proxy-user)\b/.test(out)) {
|
|
442
|
+
out = out.replace(CURL_USER_RE, (match, prefix: string, user: string, pw: string) =>
|
|
443
|
+
// `-u 1000:1000` / `-u node:node` is a docker uid:gid, not a credential.
|
|
444
|
+
isPlaceholderValue(pw) || pw === user ? match : `${prefix}[REDACTED:curl_password]`,
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
if (out.includes("://")) {
|
|
448
|
+
out = out.replace(URL_USERINFO_RE, (match, prefix: string, pw: string) =>
|
|
449
|
+
isPlaceholderValue(pw) ? match : `${prefix}[REDACTED:url_password]`,
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
if (out.includes('"')) {
|
|
453
|
+
out = redactJsonValues(out, JSON_KEY_RE, false);
|
|
454
|
+
if (out.includes('\\"')) out = redactJsonValues(out, ESCAPED_JSON_KEY_RE, true);
|
|
455
|
+
}
|
|
456
|
+
if (out.includes(":")) out = out.replace(YAML_KEY_RE, redactLineValue);
|
|
457
|
+
return out;
|
|
458
|
+
}
|
|
459
|
+
|
|
175
460
|
/**
|
|
176
461
|
* Structural regex patterns for common credential shapes. Applied AFTER the
|
|
177
462
|
* env-value substitution pass so env-sourced replacements keep their
|
|
@@ -185,6 +470,9 @@ function redactAssignment(match: string, key: string, value: string): string {
|
|
|
185
470
|
// Leading word boundary that also matches after JSON escape sequences (\n, \t,
|
|
186
471
|
// \r, etc.) where the trailing char is alphanumeric and defeats standard \b.
|
|
187
472
|
const TB = String.raw`(?:(?<=\\[nrtbfu0])|(?<!\w))`;
|
|
473
|
+
// Rules whose token class includes `-` end on `(?!\w)`, not `\b`: a token
|
|
474
|
+
// ending in `-` has no word boundary after it, so `\b` backtracks and leaves
|
|
475
|
+
// the last character behind.
|
|
188
476
|
|
|
189
477
|
const TOKEN_REGEXES: ReadonlyArray<{ name: string; re: RegExp }> = [
|
|
190
478
|
// GitHub fine-grained PATs
|
|
@@ -194,34 +482,40 @@ const TOKEN_REGEXES: ReadonlyArray<{ name: string; re: RegExp }> = [
|
|
|
194
482
|
// ACP ephemeral session tokens (base62 payload)
|
|
195
483
|
{ name: "acp_session_token", re: new RegExp(String.raw`${TB}aseph_[A-Za-z0-9]{20,}\b`, "g") },
|
|
196
484
|
// GitLab personal access tokens
|
|
197
|
-
{ name: "gitlab_pat", re: new RegExp(String.raw`${TB}glpat-[A-Za-z0-9_-]{20,}
|
|
485
|
+
{ name: "gitlab_pat", re: new RegExp(String.raw`${TB}glpat-[A-Za-z0-9_-]{20,}(?!\w)`, "g") },
|
|
198
486
|
// Azure DevOps personal access tokens (84 chars, "AZDO" signature at offset 76)
|
|
199
487
|
{
|
|
200
488
|
name: "azure_devops_pat",
|
|
201
489
|
re: new RegExp(String.raw`${TB}[A-Za-z0-9]{76}AZDO[A-Za-z0-9]{4}\b`, "g"),
|
|
202
490
|
},
|
|
203
491
|
// Anthropic API keys (must match before the generic sk- rule below)
|
|
204
|
-
{ name: "anthropic_key", re: new RegExp(String.raw`${TB}sk-ant-[A-Za-z0-9_-]{20,}
|
|
492
|
+
{ name: "anthropic_key", re: new RegExp(String.raw`${TB}sk-ant-[A-Za-z0-9_-]{20,}(?!\w)`, "g") },
|
|
205
493
|
// OpenAI project keys
|
|
206
|
-
{
|
|
494
|
+
{
|
|
495
|
+
name: "openai_proj_key",
|
|
496
|
+
re: new RegExp(String.raw`${TB}sk-proj-[A-Za-z0-9_-]{20,}(?!\w)`, "g"),
|
|
497
|
+
},
|
|
207
498
|
// OpenRouter keys
|
|
208
499
|
{
|
|
209
500
|
name: "openrouter_key",
|
|
210
|
-
re: new RegExp(String.raw`${TB}sk-or-(?:v1-)?[A-Za-z0-9_-]{20,}
|
|
501
|
+
re: new RegExp(String.raw`${TB}sk-or-(?:v1-)?[A-Za-z0-9_-]{20,}(?!\w)`, "g"),
|
|
211
502
|
},
|
|
212
503
|
// Generic sk- legacy OpenAI keys (must come AFTER the ant/proj/or variants)
|
|
213
504
|
{ name: "sk_key", re: new RegExp(String.raw`${TB}sk-[A-Za-z0-9]{20,}\b`, "g") },
|
|
214
505
|
// Slack tokens
|
|
215
|
-
{
|
|
506
|
+
{
|
|
507
|
+
name: "slack_token",
|
|
508
|
+
re: new RegExp(String.raw`${TB}xox[baprseo]-[A-Za-z0-9-]{10,}(?!\w)`, "g"),
|
|
509
|
+
},
|
|
216
510
|
// AWS access key IDs
|
|
217
511
|
{ name: "aws_access_key", re: new RegExp(String.raw`${TB}AKIA[0-9A-Z]{16}\b`, "g") },
|
|
218
512
|
// Google API keys
|
|
219
|
-
{ name: "google_api_key", re: new RegExp(String.raw`${TB}AIza[A-Za-z0-9_-]{35}
|
|
513
|
+
{ name: "google_api_key", re: new RegExp(String.raw`${TB}AIza[A-Za-z0-9_-]{35}(?!\w)`, "g") },
|
|
220
514
|
// JWTs (3 dot-separated base64url segments)
|
|
221
515
|
{
|
|
222
516
|
name: "jwt",
|
|
223
517
|
re: new RegExp(
|
|
224
|
-
String.raw`${TB}eyJ[A-Za-z0-9_-]{10,}\.eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}
|
|
518
|
+
String.raw`${TB}eyJ[A-Za-z0-9_-]{10,}\.eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}(?!\w)`,
|
|
225
519
|
"g",
|
|
226
520
|
),
|
|
227
521
|
},
|
|
@@ -231,22 +525,202 @@ const TOKEN_REGEXES: ReadonlyArray<{ name: string; re: RegExp }> = [
|
|
|
231
525
|
re: new RegExp(String.raw`${TB}signoz-ingestion-key=[A-Za-z0-9._~+/-]{20,}={0,2}\b`, "g"),
|
|
232
526
|
},
|
|
233
527
|
// Linear OAuth tokens and API keys
|
|
234
|
-
{
|
|
235
|
-
|
|
528
|
+
{
|
|
529
|
+
name: "linear_oauth",
|
|
530
|
+
re: new RegExp(String.raw`${TB}lin_oauth_[A-Za-z0-9_-]{10,}(?!\w)`, "g"),
|
|
531
|
+
},
|
|
532
|
+
{ name: "linear_api", re: new RegExp(String.raw`${TB}lin_api_[A-Za-z0-9_-]{10,}(?!\w)`, "g") },
|
|
236
533
|
// npm tokens
|
|
237
|
-
{ name: "npm_token", re: new RegExp(String.raw`${TB}npm_[A-Za-z0-9_-]{20,}
|
|
534
|
+
{ name: "npm_token", re: new RegExp(String.raw`${TB}npm_[A-Za-z0-9_-]{20,}(?!\w)`, "g") },
|
|
238
535
|
// Jira API tokens (Atlassian cloud)
|
|
239
536
|
{
|
|
240
537
|
name: "atlassian_token",
|
|
241
|
-
re: new RegExp(String.raw`${TB}ATATT[A-Za-z0-9_
|
|
538
|
+
re: new RegExp(String.raw`${TB}ATATT[A-Za-z0-9_=-]{20,}(?![\w=])`, "g"),
|
|
242
539
|
},
|
|
243
540
|
// Agent-swarm MCP user tokens (`aswt_<base62-20+>`). Schema lands in
|
|
244
541
|
// migration 064; mint/revoke endpoints ship with the MCP-token plan.
|
|
245
542
|
// Rule lives here now so plaintexts never leak into logs once endpoints
|
|
246
543
|
// come online.
|
|
247
544
|
{ name: "mcp_token", re: new RegExp(String.raw`${TB}aswt_[A-Za-z0-9]{20,}\b`, "g") },
|
|
545
|
+
// Vendor shapes the gitleaks rule set (pass 5) has no rule for.
|
|
546
|
+
// Resend API keys: re_<8>_<24>, with a digit and an uppercase letter so
|
|
547
|
+
// snake_case identifiers never match.
|
|
548
|
+
{
|
|
549
|
+
name: "resend_key",
|
|
550
|
+
re: new RegExp(
|
|
551
|
+
String.raw`${TB}re_(?=[A-Za-z0-9_]*[0-9])(?=[A-Za-z0-9_]*[A-Z])[A-Za-z0-9]{8}_[A-Za-z0-9]{24}\b`,
|
|
552
|
+
"g",
|
|
553
|
+
),
|
|
554
|
+
},
|
|
555
|
+
// Google OAuth access tokens and refresh tokens
|
|
556
|
+
{ name: "google_oauth_token", re: new RegExp(String.raw`${TB}ya29\.[A-Za-z0-9_-]{20,}`, "g") },
|
|
557
|
+
{ name: "google_refresh_token", re: /(?<![\w/])1\/\/0[A-Za-z0-9_-]{30,}/g },
|
|
558
|
+
// Discord webhook URLs (the token is the last path segment)
|
|
559
|
+
{
|
|
560
|
+
name: "discord_webhook",
|
|
561
|
+
re: /https?:\/\/(?:ptb\.|canary\.)?discord(?:app)?\.com\/api\/webhooks\/\d+\/[A-Za-z0-9_-]{50,}/g,
|
|
562
|
+
},
|
|
563
|
+
// xAI API keys
|
|
564
|
+
{ name: "xai_key", re: new RegExp(String.raw`${TB}xai-[A-Za-z0-9]{40,}\b`, "g") },
|
|
565
|
+
// Telegram bot tokens without a "telegram" keyword nearby: <bot id>:AA<33>
|
|
566
|
+
{
|
|
567
|
+
name: "telegram_bot_token",
|
|
568
|
+
re: new RegExp(String.raw`${TB}\d{8,10}:AA[A-Za-z0-9_-]{33}(?![A-Za-z0-9_-])`, "g"),
|
|
569
|
+
},
|
|
248
570
|
];
|
|
249
571
|
|
|
572
|
+
/**
|
|
573
|
+
* Pass 5: the vendored gitleaks rule set (src/utils/secret-rules.generated.ts).
|
|
574
|
+
* Compiled on first use. A rule runs only when the text contains one of its
|
|
575
|
+
* keywords, and a match counts only when its secret clears the rule's entropy
|
|
576
|
+
* floor and no allowlist claims it, the same gates gitleaks applies.
|
|
577
|
+
*/
|
|
578
|
+
interface CompiledAllowlist {
|
|
579
|
+
target: "secret" | "match";
|
|
580
|
+
res: RegExp[];
|
|
581
|
+
stopwords: string[];
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
interface CompiledGitleaksRule {
|
|
585
|
+
id: string;
|
|
586
|
+
re: RegExp;
|
|
587
|
+
keywords: string[];
|
|
588
|
+
entropy?: number;
|
|
589
|
+
secretGroup?: number;
|
|
590
|
+
redactWholeMatch?: boolean;
|
|
591
|
+
allowlists: CompiledAllowlist[];
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
interface CompiledGitleaks {
|
|
595
|
+
/** Every keyword in one case-insensitive, longest-first alternation. */
|
|
596
|
+
keywordRe: RegExp;
|
|
597
|
+
/** keyword -> every keyword it contains, itself included. */
|
|
598
|
+
implied: Map<string, string[]>;
|
|
599
|
+
rules: CompiledGitleaksRule[];
|
|
600
|
+
global: CompiledAllowlist;
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
let gitleaks: CompiledGitleaks | null = null;
|
|
604
|
+
|
|
605
|
+
function getGitleaks(): CompiledGitleaks {
|
|
606
|
+
if (gitleaks) return gitleaks;
|
|
607
|
+
const compile = (r: { source: string; flags: string }) => new RegExp(r.source, r.flags);
|
|
608
|
+
const rules = GITLEAKS_RULES.rules.map((rule) => ({
|
|
609
|
+
id: rule.id,
|
|
610
|
+
re: new RegExp(rule.source, `${rule.flags}gd`),
|
|
611
|
+
keywords: rule.keywords,
|
|
612
|
+
entropy: rule.entropy,
|
|
613
|
+
secretGroup: rule.secretGroup,
|
|
614
|
+
redactWholeMatch: rule.redactWholeMatch,
|
|
615
|
+
allowlists: (rule.allowlists ?? []).map((list) => ({
|
|
616
|
+
target: list.target,
|
|
617
|
+
res: list.regexes.map(compile),
|
|
618
|
+
stopwords: list.stopwords,
|
|
619
|
+
})),
|
|
620
|
+
}));
|
|
621
|
+
const keywords = [...new Set(rules.flatMap((rule) => rule.keywords))].sort(
|
|
622
|
+
(a, b) => b.length - a.length,
|
|
623
|
+
);
|
|
624
|
+
gitleaks = {
|
|
625
|
+
keywordRe: new RegExp(keywords.map(escapeRegExp).join("|"), "gi"),
|
|
626
|
+
implied: new Map(keywords.map((k) => [k, keywords.filter((other) => k.includes(other))])),
|
|
627
|
+
rules,
|
|
628
|
+
global: {
|
|
629
|
+
target: "secret",
|
|
630
|
+
res: GITLEAKS_RULES.globalAllowlist.regexes.map(compile),
|
|
631
|
+
stopwords: GITLEAKS_RULES.globalAllowlist.stopwords,
|
|
632
|
+
},
|
|
633
|
+
};
|
|
634
|
+
return gitleaks;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/** Shannon entropy in bits per character, as gitleaks computes it. */
|
|
638
|
+
function shannonEntropy(value: string): number {
|
|
639
|
+
if (value.length === 0) return 0;
|
|
640
|
+
const counts = new Map<string, number>();
|
|
641
|
+
for (const ch of value) counts.set(ch, (counts.get(ch) ?? 0) + 1);
|
|
642
|
+
let entropy = 0;
|
|
643
|
+
for (const count of counts.values()) {
|
|
644
|
+
const p = count / value.length;
|
|
645
|
+
entropy -= p * Math.log2(p);
|
|
646
|
+
}
|
|
647
|
+
return entropy;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
function allowedBy(list: CompiledAllowlist, secret: string, match: string): boolean {
|
|
651
|
+
const target = list.target === "match" ? match : secret;
|
|
652
|
+
if (list.res.some((re) => re.test(target))) return true;
|
|
653
|
+
if (list.stopwords.length === 0) return false;
|
|
654
|
+
const lower = secret.toLowerCase();
|
|
655
|
+
return list.stopwords.some((word) => lower.includes(word));
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
function applyGitleaksRule(text: string, rule: CompiledGitleaksRule, global: CompiledAllowlist) {
|
|
659
|
+
const { re } = rule;
|
|
660
|
+
re.lastIndex = 0;
|
|
661
|
+
let out = "";
|
|
662
|
+
let last = 0;
|
|
663
|
+
let changed = false;
|
|
664
|
+
for (let m = re.exec(text); m !== null; m = re.exec(text)) {
|
|
665
|
+
if (m[0].length === 0) {
|
|
666
|
+
re.lastIndex++;
|
|
667
|
+
continue;
|
|
668
|
+
}
|
|
669
|
+
// gitleaks' secret: the configured group, else the first non-empty group,
|
|
670
|
+
// else the whole match. Only the secret is redacted; the context stays.
|
|
671
|
+
let group = 0;
|
|
672
|
+
if (rule.secretGroup && m[rule.secretGroup]) group = rule.secretGroup;
|
|
673
|
+
else if (!rule.redactWholeMatch && !rule.secretGroup) {
|
|
674
|
+
group = m.findIndex((g, i) => i > 0 && !!g);
|
|
675
|
+
if (group === -1) group = 0;
|
|
676
|
+
}
|
|
677
|
+
const secret = m[group] as string;
|
|
678
|
+
const span = m.indices?.[group];
|
|
679
|
+
if (!span) continue;
|
|
680
|
+
// Resume at the end of the secret, not the match. Many rules consume a
|
|
681
|
+
// delimiter on each side, so `a b` shares one space: resuming after it
|
|
682
|
+
// hides the second secret's leading boundary. The next match starts at or
|
|
683
|
+
// after span[1], so redacted spans never overlap; the max keeps progress.
|
|
684
|
+
re.lastIndex = Math.max(span[1], m.index + 1);
|
|
685
|
+
if (rule.entropy && shannonEntropy(secret) <= rule.entropy) continue;
|
|
686
|
+
if (allowedBy(global, secret, m[0])) continue;
|
|
687
|
+
if (rule.allowlists.some((list) => allowedBy(list, secret, m[0]))) continue;
|
|
688
|
+
out += `${text.slice(last, span[0])}[REDACTED:gitleaks:${rule.id}]`;
|
|
689
|
+
last = span[1];
|
|
690
|
+
changed = true;
|
|
691
|
+
}
|
|
692
|
+
return changed ? out + text.slice(last) : text;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
let gitleaksPassEnabled = true;
|
|
696
|
+
|
|
697
|
+
/** Test-only: switch pass 5 off to measure what it costs. */
|
|
698
|
+
export function setGitleaksPassEnabledForTesting(enabled: boolean): void {
|
|
699
|
+
gitleaksPassEnabled = enabled;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
function scrubGitleaks(text: string): string {
|
|
703
|
+
if (!gitleaksPassEnabled) return text;
|
|
704
|
+
const { keywordRe, implied, rules, global } = getGitleaks();
|
|
705
|
+
// Visit every start position that has a keyword. The alternation is
|
|
706
|
+
// longest-first, so a shorter keyword starting at the same position is a
|
|
707
|
+
// substring of the one found, and `implied` adds it.
|
|
708
|
+
const present = new Set<string>();
|
|
709
|
+
keywordRe.lastIndex = 0;
|
|
710
|
+
for (let m = keywordRe.exec(text); m !== null; m = keywordRe.exec(text)) {
|
|
711
|
+
for (const keyword of implied.get(m[0].toLowerCase()) ?? []) present.add(keyword);
|
|
712
|
+
keywordRe.lastIndex = m.index + 1;
|
|
713
|
+
}
|
|
714
|
+
if (present.size === 0) return text;
|
|
715
|
+
let out = text;
|
|
716
|
+
for (const rule of rules) {
|
|
717
|
+
if (rule.keywords.some((keyword) => present.has(keyword))) {
|
|
718
|
+
out = applyGitleaksRule(out, rule, global);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
return out;
|
|
722
|
+
}
|
|
723
|
+
|
|
250
724
|
interface EnvValueEntry {
|
|
251
725
|
value: string;
|
|
252
726
|
name: string;
|
|
@@ -257,8 +731,28 @@ interface ScrubCache {
|
|
|
257
731
|
snapshotKey: string;
|
|
258
732
|
}
|
|
259
733
|
|
|
734
|
+
/**
|
|
735
|
+
* Pass 1 matcher: every known value (env entries + volatile secrets) in one
|
|
736
|
+
* alternation regex, longest value first, so each scrub is a single scan no
|
|
737
|
+
* matter how many values are registered.
|
|
738
|
+
*/
|
|
739
|
+
interface KnownValueMatcher {
|
|
740
|
+
/** null when there is nothing to match, or the regex could not be built. */
|
|
741
|
+
re: RegExp | null;
|
|
742
|
+
/** value -> marker name. */
|
|
743
|
+
names: Map<string, string>;
|
|
744
|
+
/** Longest-first values, used only when `re` failed to build. */
|
|
745
|
+
fallback: string[];
|
|
746
|
+
/** Inputs the matcher was built from; a change on either rebuilds it. */
|
|
747
|
+
builtFor: ScrubCache;
|
|
748
|
+
builtAtGeneration: number;
|
|
749
|
+
}
|
|
750
|
+
|
|
260
751
|
let cache: ScrubCache | null = null;
|
|
752
|
+
let matcher: KnownValueMatcher | null = null;
|
|
261
753
|
const volatileSecrets = new Map<string, string>();
|
|
754
|
+
/** Bumped whenever `volatileSecrets` changes, so the matcher rebuilds lazily. */
|
|
755
|
+
let volatileGeneration = 0;
|
|
262
756
|
/** Key names marked secret at runtime (swarm_config rows with isSecret=1). */
|
|
263
757
|
const registeredSensitiveKeys = new Set<string>();
|
|
264
758
|
|
|
@@ -274,11 +768,31 @@ function snapshotEnv(): string {
|
|
|
274
768
|
return parts.join("|");
|
|
275
769
|
}
|
|
276
770
|
|
|
771
|
+
/**
|
|
772
|
+
* Memoized verdicts. Every scrub call re-checks every env key, and log text
|
|
773
|
+
* repeats the same JSON/YAML keys, so the normalization runs once per name.
|
|
774
|
+
* Bounded because log text can carry arbitrary key names; cleared whenever
|
|
775
|
+
* the registered key set changes.
|
|
776
|
+
*/
|
|
777
|
+
const sensitiveKeyVerdicts = new Map<string, boolean>();
|
|
778
|
+
const MAX_KEY_VERDICTS = 4096;
|
|
779
|
+
|
|
277
780
|
export function isSensitiveKey(key: string): boolean {
|
|
278
|
-
|
|
279
|
-
if (
|
|
781
|
+
const cached = sensitiveKeyVerdicts.get(key);
|
|
782
|
+
if (cached !== undefined) return cached;
|
|
783
|
+
const verdict = computeIsSensitiveKey(key);
|
|
784
|
+
if (sensitiveKeyVerdicts.size >= MAX_KEY_VERDICTS) sensitiveKeyVerdicts.clear();
|
|
785
|
+
sensitiveKeyVerdicts.set(key, verdict);
|
|
786
|
+
return verdict;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
function computeIsSensitiveKey(key: string): boolean {
|
|
790
|
+
const normalized = normalizeKey(key);
|
|
791
|
+
if (NON_SECRET_EXCEPTIONS.has(normalized)) return false;
|
|
792
|
+
if (SENSITIVE_KEY_EXACT.has(normalized)) return true;
|
|
793
|
+
if (registeredSensitiveKeys.has(key) || registeredSensitiveKeys.has(normalized)) return true;
|
|
280
794
|
for (const suffix of SENSITIVE_KEY_SUFFIXES) {
|
|
281
|
-
if (
|
|
795
|
+
if (normalized.endsWith(suffix)) return true;
|
|
282
796
|
}
|
|
283
797
|
// Codex OAuth pool credentials: codex_oauth (legacy) + codex_oauth_0…N (pool slots).
|
|
284
798
|
// The outer JSON structure (accountId, expires) isn't covered by TOKEN_REGEXES.
|
|
@@ -326,29 +840,77 @@ function getCache(): ScrubCache {
|
|
|
326
840
|
return cache;
|
|
327
841
|
}
|
|
328
842
|
|
|
843
|
+
function escapeRegExp(value: string): string {
|
|
844
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
function buildMatcher(envCache: ScrubCache): KnownValueMatcher {
|
|
848
|
+
// Volatile names first, env names second: when a value is both, the env
|
|
849
|
+
// name wins, as it did when the env pass ran before the volatile pass.
|
|
850
|
+
const names = new Map<string, string>(volatileSecrets);
|
|
851
|
+
for (const { value, name } of envCache.entries) names.set(value, name);
|
|
852
|
+
|
|
853
|
+
// Longest first: a regex alternation takes the first alternative that
|
|
854
|
+
// matches at a position, so a value that is a prefix of a longer one must
|
|
855
|
+
// come after it or the longer value would be cut in half.
|
|
856
|
+
const values = [...names.keys()].sort((a, b) => b.length - a.length);
|
|
857
|
+
let re: RegExp | null = null;
|
|
858
|
+
if (values.length > 0) {
|
|
859
|
+
try {
|
|
860
|
+
re = new RegExp(values.map(escapeRegExp).join("|"), "g");
|
|
861
|
+
} catch {
|
|
862
|
+
// Pattern too large for the engine: fall back to the per-value loop.
|
|
863
|
+
re = null;
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
return {
|
|
867
|
+
re,
|
|
868
|
+
names,
|
|
869
|
+
fallback: re ? [] : values,
|
|
870
|
+
builtFor: envCache,
|
|
871
|
+
builtAtGeneration: volatileGeneration,
|
|
872
|
+
};
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
function getMatcher(): KnownValueMatcher {
|
|
876
|
+
const envCache = getCache();
|
|
877
|
+
if (
|
|
878
|
+
!matcher ||
|
|
879
|
+
matcher.builtFor !== envCache ||
|
|
880
|
+
matcher.builtAtGeneration !== volatileGeneration
|
|
881
|
+
) {
|
|
882
|
+
matcher = buildMatcher(envCache);
|
|
883
|
+
}
|
|
884
|
+
return matcher;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
/**
|
|
888
|
+
* A string that has passed through `scrubSecrets`. Still a plain `string` at
|
|
889
|
+
* runtime; the brand lets a DB writer demand scrubbed input so `tsc` rejects a
|
|
890
|
+
* raw string. Only `scrubSecrets` produces it.
|
|
891
|
+
*/
|
|
892
|
+
export type ScrubbedText = string & { readonly __scrubbed: true };
|
|
893
|
+
|
|
329
894
|
/**
|
|
330
895
|
* Replace known secret values in `text` with `[REDACTED:<name>]` markers.
|
|
331
896
|
* Null/undefined inputs return an empty string. Empty strings pass through.
|
|
332
897
|
*/
|
|
333
|
-
export function scrubSecrets(text: string | null | undefined):
|
|
334
|
-
if (text == null) return "";
|
|
335
|
-
if (text.length === 0) return text;
|
|
898
|
+
export function scrubSecrets(text: string | null | undefined): ScrubbedText {
|
|
899
|
+
if (text == null) return "" as ScrubbedText;
|
|
900
|
+
if (text.length === 0) return text as ScrubbedText;
|
|
336
901
|
|
|
337
902
|
let out = text;
|
|
338
903
|
|
|
339
|
-
// Pass 1: exact-match
|
|
340
|
-
//
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
for (const [value, name] of volatileSecrets) {
|
|
350
|
-
if (out.includes(value)) {
|
|
351
|
-
out = out.split(value).join(`[REDACTED:${name}]`);
|
|
904
|
+
// Pass 1: exact-match known values, env first then volatile (registered at
|
|
905
|
+
// runtime, incl. every stored secret the API's secret registry loads). The
|
|
906
|
+
// marker keeps the env-var / source name for debugging.
|
|
907
|
+
const { re, names, fallback } = getMatcher();
|
|
908
|
+
if (re) {
|
|
909
|
+
re.lastIndex = 0;
|
|
910
|
+
out = out.replace(re, (match) => `[REDACTED:${names.get(match) ?? "secret"}]`);
|
|
911
|
+
} else {
|
|
912
|
+
for (const value of fallback) {
|
|
913
|
+
if (out.includes(value)) out = out.split(value).join(`[REDACTED:${names.get(value)}]`);
|
|
352
914
|
}
|
|
353
915
|
}
|
|
354
916
|
|
|
@@ -362,8 +924,64 @@ export function scrubSecrets(text: string | null | undefined): string {
|
|
|
362
924
|
// Pass 3: values of sensitive `KEY=value` assignments (env dumps, .env
|
|
363
925
|
// files, shell traces), including ones too short for pass 1.
|
|
364
926
|
out = out.replace(ASSIGNMENT_RE, redactAssignment);
|
|
927
|
+
if (out.includes("=")) out = out.replace(INI_ASSIGNMENT_RE, redactLineValue);
|
|
365
928
|
|
|
366
|
-
|
|
929
|
+
// Pass 4: credentials known by their context (JSON/YAML keys, auth headers,
|
|
930
|
+
// curl flags, URL userinfo, PEM blocks).
|
|
931
|
+
out = scrubKeyContext(out);
|
|
932
|
+
|
|
933
|
+
// Pass 5: vendor token shapes from the gitleaks rule set, behind a keyword
|
|
934
|
+
// prefilter and each rule's entropy floor.
|
|
935
|
+
return scrubGitleaks(out) as ScrubbedText;
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
/** What `findSecretsIn` found: names and rule ids only, never the values. */
|
|
939
|
+
export interface SecretFindings {
|
|
940
|
+
/** Names of known values (env + registered secrets, every encoded form). */
|
|
941
|
+
knownValues: string[];
|
|
942
|
+
/** Ids of gitleaks rules whose pattern matched. */
|
|
943
|
+
gitleaksRules: string[];
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
/**
|
|
947
|
+
* Detect, without redacting, the two secret classes a write must refuse
|
|
948
|
+
* outright: a known value (pass 1, every form it was registered in) and a
|
|
949
|
+
* gitleaks vendor-token rule (pass 5). The key-context passes are left out on
|
|
950
|
+
* purpose: on code they flag `password: "…"`-shaped literals that are often
|
|
951
|
+
* not secrets.
|
|
952
|
+
*/
|
|
953
|
+
export function findSecretsIn(text: string): SecretFindings {
|
|
954
|
+
const knownValues = new Set<string>();
|
|
955
|
+
const gitleaksRules = new Set<string>();
|
|
956
|
+
if (text.length === 0) return { knownValues: [], gitleaksRules: [] };
|
|
957
|
+
|
|
958
|
+
const { re, names, fallback } = getMatcher();
|
|
959
|
+
if (re) {
|
|
960
|
+
re.lastIndex = 0;
|
|
961
|
+
for (let m = re.exec(text); m !== null; m = re.exec(text)) {
|
|
962
|
+
knownValues.add(names.get(m[0]) ?? "secret");
|
|
963
|
+
}
|
|
964
|
+
} else {
|
|
965
|
+
for (const value of fallback) {
|
|
966
|
+
if (text.includes(value)) knownValues.add(names.get(value) ?? "secret");
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
if (gitleaksPassEnabled) {
|
|
971
|
+
const { keywordRe, implied, rules, global } = getGitleaks();
|
|
972
|
+
const present = new Set<string>();
|
|
973
|
+
keywordRe.lastIndex = 0;
|
|
974
|
+
for (let m = keywordRe.exec(text); m !== null; m = keywordRe.exec(text)) {
|
|
975
|
+
for (const keyword of implied.get(m[0].toLowerCase()) ?? []) present.add(keyword);
|
|
976
|
+
keywordRe.lastIndex = m.index + 1;
|
|
977
|
+
}
|
|
978
|
+
for (const rule of rules) {
|
|
979
|
+
if (!rule.keywords.some((keyword) => present.has(keyword))) continue;
|
|
980
|
+
if (applyGitleaksRule(text, rule, global) !== text) gitleaksRules.add(rule.id);
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
return { knownValues: [...knownValues].sort(), gitleaksRules: [...gitleaksRules].sort() };
|
|
367
985
|
}
|
|
368
986
|
|
|
369
987
|
export function scrubObject<T>(value: T, seen = new WeakSet<object>()): T {
|
|
@@ -406,7 +1024,11 @@ export function refreshSecretScrubberCache(): void {
|
|
|
406
1024
|
*/
|
|
407
1025
|
export function registerVolatileSecret(value: string, name: string): void {
|
|
408
1026
|
if (value.length < MIN_VALUE_LENGTH) return;
|
|
409
|
-
for (const form of escapedForms(value))
|
|
1027
|
+
for (const form of escapedForms(value)) {
|
|
1028
|
+
if (volatileSecrets.get(form) === name) continue;
|
|
1029
|
+
volatileSecrets.set(form, name);
|
|
1030
|
+
volatileGeneration++;
|
|
1031
|
+
}
|
|
410
1032
|
}
|
|
411
1033
|
|
|
412
1034
|
/**
|
|
@@ -418,12 +1040,16 @@ export function registerVolatileSecret(value: string, name: string): void {
|
|
|
418
1040
|
export function registerSensitiveKeyName(key: string): void {
|
|
419
1041
|
if (registeredSensitiveKeys.has(key)) return;
|
|
420
1042
|
registeredSensitiveKeys.add(key);
|
|
1043
|
+
sensitiveKeyVerdicts.clear();
|
|
421
1044
|
cache = null;
|
|
422
1045
|
}
|
|
423
1046
|
|
|
424
1047
|
/** Test-only: drop volatile values and runtime-registered key names. */
|
|
425
1048
|
export function clearVolatileSecretsForTesting(): void {
|
|
426
1049
|
volatileSecrets.clear();
|
|
1050
|
+
volatileGeneration++;
|
|
1051
|
+
matcher = null;
|
|
427
1052
|
registeredSensitiveKeys.clear();
|
|
1053
|
+
sensitiveKeyVerdicts.clear();
|
|
428
1054
|
cache = null;
|
|
429
1055
|
}
|