flare-redact 1.9.1 → 1.10.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.
Files changed (70) hide show
  1. package/CHANGELOG.md +98 -0
  2. package/README.md +16 -7
  3. package/bench/adversarial-runtime.mjs +27 -6
  4. package/dist/ai-sdk.d.ts +62 -0
  5. package/dist/ai-sdk.d.ts.map +1 -0
  6. package/dist/ai-sdk.js +263 -0
  7. package/dist/ai-sdk.js.map +1 -0
  8. package/dist/checksums.d.ts +43 -0
  9. package/dist/checksums.d.ts.map +1 -1
  10. package/dist/checksums.js +184 -0
  11. package/dist/checksums.js.map +1 -1
  12. package/dist/cli.d.ts.map +1 -1
  13. package/dist/cli.js +5 -2
  14. package/dist/cli.js.map +1 -1
  15. package/dist/detectors.d.ts.map +1 -1
  16. package/dist/detectors.js +7 -4
  17. package/dist/detectors.js.map +1 -1
  18. package/dist/extra.d.ts.map +1 -1
  19. package/dist/extra.js +229 -1
  20. package/dist/extra.js.map +1 -1
  21. package/dist/file-discovery.d.ts +5 -0
  22. package/dist/file-discovery.d.ts.map +1 -1
  23. package/dist/file-discovery.js +5 -1
  24. package/dist/file-discovery.js.map +1 -1
  25. package/dist/gateway/body.d.ts.map +1 -1
  26. package/dist/gateway/body.js +2 -1
  27. package/dist/gateway/body.js.map +1 -1
  28. package/dist/gateway/config.d.ts +5 -3
  29. package/dist/gateway/config.d.ts.map +1 -1
  30. package/dist/gateway/config.js.map +1 -1
  31. package/dist/gateway/index.d.ts +1 -0
  32. package/dist/gateway/index.d.ts.map +1 -1
  33. package/dist/gateway/index.js +1 -0
  34. package/dist/gateway/index.js.map +1 -1
  35. package/dist/gateway/server.d.ts.map +1 -1
  36. package/dist/gateway/server.js +17 -1
  37. package/dist/gateway/server.js.map +1 -1
  38. package/dist/gateway/sse.d.ts +35 -0
  39. package/dist/gateway/sse.d.ts.map +1 -0
  40. package/dist/gateway/sse.js +217 -0
  41. package/dist/gateway/sse.js.map +1 -0
  42. package/dist/help.d.ts.map +1 -1
  43. package/dist/help.js +11 -5
  44. package/dist/help.js.map +1 -1
  45. package/dist/init.d.ts.map +1 -1
  46. package/dist/init.js +12 -3
  47. package/dist/init.js.map +1 -1
  48. package/dist/llm.d.ts.map +1 -1
  49. package/dist/llm.js +20 -9
  50. package/dist/llm.js.map +1 -1
  51. package/dist/locales.d.ts +3 -2
  52. package/dist/locales.d.ts.map +1 -1
  53. package/dist/locales.js +152 -3
  54. package/dist/locales.js.map +1 -1
  55. package/dist/pack.d.ts.map +1 -1
  56. package/dist/pack.js +14 -1
  57. package/dist/pack.js.map +1 -1
  58. package/dist/vault.d.ts +26 -1
  59. package/dist/vault.d.ts.map +1 -1
  60. package/dist/vault.js +61 -3
  61. package/dist/vault.js.map +1 -1
  62. package/docker/README.md +8 -5
  63. package/docs/guide.md +165 -16
  64. package/package.json +8 -2
  65. package/spec/SPEC.md +40 -3
  66. package/spec/conformance/README.md +8 -1
  67. package/spec/conformance/cases.json +60 -1
  68. package/spec/conformance/expected.json +815 -7
  69. package/spec/detectors.json +1118 -222
  70. package/spec/detectors.schema.json +3 -1
package/docs/guide.md CHANGED
@@ -53,7 +53,7 @@ projects are not forced across the major version; upgrade explicitly with
53
53
  ### Set up in one command
54
54
 
55
55
  ```bash
56
- npx flare-redact init # the lines to paste for openai, @anthropic-ai/sdk, Sentry, pino, winston, express
56
+ npx flare-redact init # the lines to paste for openai, @anthropic-ai/sdk, ai, Sentry, pino, winston, express
57
57
  npx flare-redact init --hook # also stops any commit that adds a secret
58
58
  npx flare-redact init --ci # also writes .github/workflows/flare-redact.yml
59
59
  ```
@@ -145,6 +145,7 @@ Clone the repository and run these small applications locally:
145
145
  | Example | What it proves | Run |
146
146
  |---|---|---|
147
147
  | [`openai-privacy`](../examples/openai-privacy) | The model sees an opaque placeholder while the app receives the restored value | `npm --prefix examples/openai-privacy start` |
148
+ | [`ai-sdk`](../examples/ai-sdk) | The Vercel AI SDK middleware redacts prompts and tool results, and restores text, streams and tool calls | `npm --prefix examples/ai-sdk start` |
148
149
  | [`express-pino`](../examples/express-pino) | Express keeps the original request while Pino receives a safe snapshot | `npm --prefix examples/express-pino run smoke` |
149
150
  | [`universal-boundaries`](../examples/universal-boundaries) | Any SDK method is sanitized and cross-tool placeholder exfiltration is blocked | `npm --prefix examples/universal-boundaries start` |
150
151
  | [`flareflow-agent`](../examples/flareflow-agent) | An injected model can carry an opaque secret token but cannot restore it at an unauthorized sink or path | `npm --prefix examples/flareflow-agent start` |
@@ -168,11 +169,20 @@ dependencies of any kind.
168
169
  | | Install | Docs |
169
170
  |---|---|---|
170
171
  | **Go** | `go get github.com/flare-collection/flare-redact/sdk/go` | [`sdk/go`](../sdk/go) |
171
- | **Python** | `pip install "flare-redact @ git+https://github.com/flare-collection/flare-redact@v1.9.1#subdirectory=sdk/python"` | [`sdk/python`](../sdk/python) |
172
- | **Rust** | `flare-redact = { git = "https://github.com/flare-collection/flare-redact", tag = "v1.9.1" }` | [`sdk/rust`](../sdk/rust) |
172
+ | **Python** | `pip install flare-redact` | [`sdk/python`](../sdk/python) |
173
+ | **Rust** | `cargo add flare-redact` | [`sdk/rust`](../sdk/rust) |
173
174
 
174
- The Python and Rust engines are not published to PyPI and crates.io yet, so they
175
- install from this repository. The commands above are the ones that work today.
175
+ The Python and Rust engines are published to PyPI and crates.io starting with the
176
+ first release after 1.9.1. Until it lands, or to pin a tag, install them from
177
+ this repository:
178
+
179
+ ```bash
180
+ pip install "flare-redact @ git+https://github.com/flare-collection/flare-redact@v1.10.0#subdirectory=sdk/python"
181
+ ```
182
+
183
+ ```toml
184
+ flare-redact = { git = "https://github.com/flare-collection/flare-redact", tag = "v1.10.0" }
185
+ ```
176
186
 
177
187
  ```python
178
188
  from flare_redact import create_session
@@ -250,9 +260,12 @@ flare-redact gateway \
250
260
  ```
251
261
 
252
262
  Redaction uses a per-request vault, so `ada@example.com` leaves as
253
- `[FR_EMAIL_9f2c…]` and comes back as itself. For a streamed reply the restorer
254
- holds back the longest suffix that could still be the start of a placeholder, so
255
- a token split across two SSE frames is restored exactly once.
263
+ `[FR_EMAIL_9f2c…]` and comes back as itself. For a streamed reply the gateway
264
+ reads the JSON of each SSE event and restores every streamed field on its own
265
+ (`delta.content`, a tool call's `arguments`, `partial_json`), so a token split
266
+ across two events is restored exactly once. An original that lands in tool-call
267
+ arguments, or in an answer the request asked to be JSON, is escaped for that
268
+ JSON as well as for the event.
256
269
 
257
270
  The header that authenticates you *to* the vendor is not the secret being hidden
258
271
  *from* it: `Authorization` is forwarded untouched. Bodies and matched values are
@@ -360,9 +373,66 @@ your app gets → Sent to alice@corp.com. Card 4242 4242 4242 4242 wasn't sto
360
373
  `wrapAnthropic` does the same for `messages.create`, including the system prompt.
361
374
  Both wrappers redact complete message structures, including tool-call arguments.
362
375
  Streaming text, OpenAI tool arguments, and Anthropic partial JSON are restored
363
- even when a placeholder is split across chunks. There's a `redactPrompt(text)`
376
+ even when a placeholder is split across chunks. Inside tool arguments, partial
377
+ JSON and JSON-mode output (`response_format`), restored values are JSON-escaped,
378
+ so the JSON still parses and keeps its structure. There's a `redactPrompt(text)`
364
379
  too if you'd rather hold the vault yourself.
365
380
 
381
+ ### Every provider through the Vercel AI SDK
382
+
383
+ On the [Vercel AI SDK](https://ai-sdk.dev), one middleware covers every
384
+ provider it supports:
385
+
386
+ ```js
387
+ import { generateText, wrapLanguageModel } from 'ai';
388
+ import { openai } from '@ai-sdk/openai';
389
+ import { flareRedactMiddleware } from 'flare-redact/ai-sdk';
390
+
391
+ const model = wrapLanguageModel({
392
+ model: openai('gpt-4o'),
393
+ middleware: flareRedactMiddleware({ preset: 'llm' }),
394
+ });
395
+
396
+ const { text } = await generateText({ model, prompt: 'Email the invoice to alice@corp.com' });
397
+ ```
398
+
399
+ Swap `openai(...)` for `anthropic(...)`, `google(...)`, `bedrock(...)`,
400
+ `mistral(...)` or any other AI SDK provider; the middleware stays the same. It
401
+ works with AI SDK 5, 6 and 7, with `generateText`, `streamText`, structured
402
+ output and multi-step tool loops, and takes the same options as `wrapOpenAI`.
403
+
404
+ On each model call:
405
+
406
+ - System, user and assistant text, reasoning, tool-call inputs and tool results
407
+ are redacted to opaque placeholders before the provider sees them. Roles,
408
+ tool names and ids, and `providerOptions` (cache control, for example) are
409
+ left alone.
410
+ - Text, reasoning and tool calls in the result are restored, streamed or not,
411
+ including placeholders split across chunks. A value restored inside JSON (a
412
+ tool call's input, structured output) is escaped, so the JSON still parses.
413
+ - File and image parts pass through unchanged. If a document may hold personal
414
+ data, redact its text before you attach it.
415
+ - Raw provider chunks and the `request` and `response` bodies are left as they
416
+ were: they record what actually crossed the wire.
417
+
418
+ Each call gets its own vault, as with `wrapOpenAI`. Pass a session to keep one
419
+ vault for a whole conversation, so a value keeps the same placeholder in every
420
+ step and turn. The redacted history then stays identical from one call to the
421
+ next, which keeps provider prompt caching working:
422
+
423
+ ```js
424
+ import { createSession } from 'flare-redact/session';
425
+
426
+ const middleware = flareRedactMiddleware({ session: createSession({ preset: 'llm' }) });
427
+ ```
428
+
429
+ Like `wrapOpenAI`, the middleware restores any placeholder from the call into
430
+ any tool call before the AI SDK runs your tools. It does not stop a
431
+ prompt-injected model from moving a value from one tool to another; when tools
432
+ sit in different trust domains, use the scoped boundaries in
433
+ [Protect tool calls and MCP loops](#protect-tool-calls-and-mcp-loops) or
434
+ [FlareFlow](#enforce-information-flow-across-agent-tools).
435
+
366
436
  ## Ways to hide a value
367
437
 
368
438
  Pick a `mode` depending on whether you still need to *reason* about the data
@@ -422,6 +492,12 @@ the round trip. Default placeholders include 96 random bits instead of a global
422
492
  sequence number. Human-readable `[EMAIL_1]` counters remain available through
423
493
  `createVault({ placeholderStyle: 'readable' })` for trusted local workflows.
424
494
 
495
+ When a string being restored is a JSON object or array, such as tool-call
496
+ arguments or JSON-mode output, each original goes back JSON-escaped. The text
497
+ stays valid JSON with the same structure, whatever quotes, backslashes or
498
+ control characters the original holds. Any other string gets the original back
499
+ exactly as it was.
500
+
425
501
  The mapping is as sensitive as the original data. Encrypt it before persistence:
426
502
 
427
503
  ```js
@@ -952,6 +1028,23 @@ old finding, and people would learn to skip it. `--staged` reads the staged diff
952
1028
  so a commit is stopped only for what it introduces, and each finding points at
953
1029
  its line in the staged file. Skip the check once with `git commit --no-verify`.
954
1030
 
1031
+ Already using [pre-commit](https://pre-commit.com)? Add the hook to
1032
+ `.pre-commit-config.yaml` instead. It works in any repository, Node project or
1033
+ not, as long as Node 20 or newer is on the PATH:
1034
+
1035
+ ```yaml
1036
+ repos:
1037
+ - repo: https://github.com/flare-collection/flare-redact
1038
+ rev: v1.10.0
1039
+ hooks:
1040
+ - id: flare-redact # only the lines being added, like --staged
1041
+ ```
1042
+
1043
+ pre-commit builds the tagged release once and caches it. `flare-redact` reads
1044
+ the staged diff, so `pre-commit run --all-files` finds nothing for it to check.
1045
+ For that, and for pre-commit.ci, add `id: flare-redact-files`, which scans the
1046
+ whole of each file pre-commit passes.
1047
+
955
1048
  A scan leaves out assignments whose value is plainly code rather than a
956
1049
  secret: `token = process.env.TOKEN`, `password = os.getenv("DB_PASSWORD")`,
957
1050
  `secret = ${SECRET}`, `password: string`, `apiKey = config.apiKey`,
@@ -964,8 +1057,41 @@ reported. `--no-code-filter` turns it off. It applies to `--scan` and
964
1057
  `--staged` only: `redact()` keeps masking every such assignment, because
965
1058
  hiding too much in a log is safe and missing a secret is not.
966
1059
 
967
- In CI, `scan` from code, or `--scan` from the CLI (which exits non-zero on a
968
- hit). File scans report `file:line:column`, while machine-readable JSON and SARIF
1060
+ On GitHub, the action does the setup and reports each finding on the pull
1061
+ request:
1062
+
1063
+ ```yaml
1064
+ - uses: actions/checkout@v5
1065
+ - uses: flare-collection/flare-redact@v1
1066
+ with:
1067
+ exclude: package-lock.json
1068
+ ```
1069
+
1070
+ Each finding becomes an annotation at its line, the job summary gets a table of
1071
+ detectors and locations, and the step fails. Values are never printed. The
1072
+ action runs the npm release that matches the tag you pin (`@v1` follows the
1073
+ latest 1.x), on the runner, with Node 20 or newer (it installs Node 24 when the
1074
+ runner has none).
1075
+
1076
+ | Input | Default | What it does |
1077
+ | --- | --- | --- |
1078
+ | `path` | `.` | Files or directories to scan, separated by spaces or new lines |
1079
+ | `preset` | | `logs`, `llm`, `gdpr` or `strict` |
1080
+ | `exclude` | | Globs to skip, separated by spaces or new lines |
1081
+ | `args` | | More scan flags, such as `--min-confidence 0.9` or `--enable phone` |
1082
+ | `fail-on-findings` | `true` | Fail the step when anything is found |
1083
+ | `annotate` | `true` | Annotate each finding on the pull request |
1084
+ | `upload-sarif` | `false` | Send the SARIF report to GitHub code scanning |
1085
+ | `sarif-file` | runner temp | Where to write the SARIF report |
1086
+ | `version` | the pinned release | Another npm version, or a packed `.tgz` |
1087
+
1088
+ Outputs are `findings` (the count) and `sarif-file`. To see findings in the
1089
+ repository's Security tab, give the job `permissions: { contents: read,
1090
+ security-events: write }` and set `upload-sarif: true`; you may then want
1091
+ `annotate: false` to avoid seeing each finding twice.
1092
+
1093
+ Anywhere else, use `scan` from code, or `--scan` from the CLI (which exits
1094
+ non-zero on a hit). File scans report `file:line:column`, while machine-readable JSON and SARIF
969
1095
  reports never echo the matched secret value:
970
1096
 
971
1097
  ```yaml
@@ -974,7 +1100,7 @@ reports never echo the matched secret value:
974
1100
  with:
975
1101
  node-version: 24
976
1102
  - name: Scan project text files
977
- run: npx --yes --package flare-redact@1.9.1 flare-redact --scan . --exclude package-lock.json
1103
+ run: npx --yes --package flare-redact@1.10.0 flare-redact --scan . --exclude package-lock.json
978
1104
  ```
979
1105
 
980
1106
  The scan runs on the GitHub runner, reports safe file and source locations, and
@@ -1044,7 +1170,7 @@ On by default:
1044
1170
  | `aws_access_key` | AWS access key IDs (`AKIA…`, `ASIA…`) |
1045
1171
  | `aws_secret_key` | AWS secret access keys in assignments (`aws_secret_access_key=…`, `"secretAccessKey": …`) |
1046
1172
  | `github_token` | GitHub PATs and OAuth tokens (`ghp_…`, `github_pat_…`) |
1047
- | `gitlab_token` | GitLab PATs (`glpat-…`) |
1173
+ | `gitlab_token` | GitLab access, deploy, runner, pipeline trigger and CI job tokens (`glpat-…`, `gldt-…`, `glrt-…`), including routable tokens |
1048
1174
  | `slack_token` | Slack tokens (`xoxb-…`) |
1049
1175
  | `stripe_key` | Stripe secret / restricted keys (`sk_live_…`, `rk_…`) |
1050
1176
  | `anthropic_key` | Anthropic API keys (`sk-ant-…`) |
@@ -1063,12 +1189,17 @@ On by default:
1063
1189
  | `credit_card` | card numbers (Luhn-validated) |
1064
1190
  | `iban` | IBANs (mod-97 validated) |
1065
1191
  | `openrouter_key` / `huggingface_token` / `groq_key` / `xai_key` / `perplexity_key` / `replicate_token` | more AI provider keys |
1066
- | `discord_bot_token` / `discord_webhook` / `telegram_bot_token` | chat tokens and webhook URLs |
1192
+ | `aws_bedrock_key` / `langsmith_key` / `pinecone_key` / `tavily_key` | AI platform keys: Amazon Bedrock (`ABSK…`), LangSmith (`lsv2_…`), Pinecone (`pcsk_…`), Tavily (`tvly-…`) |
1193
+ | `discord_bot_token` / `discord_webhook` / `telegram_bot_token` / `slack_webhook` | chat tokens and webhook URLs |
1067
1194
  | `shopify_token` / `square_token` / `stripe_webhook_secret` | commerce secrets |
1068
1195
  | `digitalocean_token` / `azure_storage_key` / `vault_token` / `databricks_token` | cloud & infra secrets |
1069
- | `sentry_dsn` / `new_relic_key` | observability secrets |
1070
- | `airtable_pat` / `postman_key` / `linear_key` / `figma_token` / `notion_token` | SaaS workspace tokens |
1196
+ | `alibaba_access_key` / `google_oauth_secret` / `heroku_api_key` / `flyio_token` / `terraform_cloud_token` / `pulumi_token` / `planetscale_token` | more cloud, deploy and database credentials |
1197
+ | `pypi_token` / `rubygems_key` / `dockerhub_token` / `jfrog_token` | package and image registry tokens that can publish releases |
1198
+ | `onepassword_token` / `age_secret_key` | keys that unlock other secrets: 1Password service accounts (`ops_…`), age identities |
1199
+ | `sentry_dsn` / `sentry_auth_token` / `new_relic_key` / `grafana_token` / `dynatrace_token` | observability secrets |
1200
+ | `airtable_pat` / `postman_key` / `linear_key` / `figma_token` / `notion_token` / `atlassian_token` | SaaS workspace tokens |
1071
1201
  | `doppler_token` / `supabase_key` / `netlify_token` / `mailgun_key` | platform API keys |
1202
+ | `mailchimp_key` / `brevo_key` / `resend_key` | email and marketing API keys |
1072
1203
 
1073
1204
  Opt in with `enable`:
1074
1205
 
@@ -1129,6 +1260,20 @@ redact(text, { enable: ['tr', 'de'] }); // just Turkish and German
1129
1260
  | `au_tfn` | 🇦🇺 Australia (TFN) | weighted mod-11 |
1130
1261
  | `cn_resident_id` | 🇨🇳 China | ISO 7064 mod-11,2 |
1131
1262
  | `jp_my_number` | 🇯🇵 Japan (My Number) | weighted mod-11 |
1263
+ | `ro_cnp` | 🇷🇴 Romania (CNP) | weighted mod-11 and birth date |
1264
+ | `se_personnummer` | 🇸🇪 Sweden (personnummer, samordningsnummer) | Luhn and birth date |
1265
+ | `fi_hetu` | 🇫🇮 Finland (HETU) | mod-31 check character |
1266
+ | `no_fodselsnummer` | 🇳🇴 Norway (fødselsnummer, D- and H-numbers) | two mod-11 digits |
1267
+ | `be_national_number` | 🇧🇪 Belgium (national number, BIS) | 97 minus mod-97 |
1268
+ | `pt_nif` | 🇵🇹 Portugal (NIF of a person) | weighted mod-11 |
1269
+ | `za_id` | 🇿🇦 South Africa | Luhn and birth date |
1270
+ | `mx_curp` | 🇲🇽 Mexico (CURP) | weighted mod-10, state code |
1271
+ | `cl_rut` | 🇨🇱 Chile (RUT / RUN) | mod-11, K for 10 |
1272
+ | `ar_cuit` | 🇦🇷 Argentina (CUIL / CUIT of a person) | weighted mod-11 |
1273
+ | `sg_nric` | 🇸🇬 Singapore (NRIC / FIN) | weighted mod-11 check letter |
1274
+ | `il_teudat_zehut` | 🇮🇱 Israel (Teudat Zehut) | Luhn |
1275
+ | `gr_amka` | 🇬🇷 Greece (AMKA) | Luhn and birth date |
1276
+ | `uk_nino` | 🇬🇧 United Kingdom (National Insurance) | HMRC prefix and suffix rules (no checksum exists) |
1132
1277
 
1133
1278
  Every algorithm has its own tests against known-valid and known-invalid numbers,
1134
1279
  so enabling them won't turn your logs into a wall of `[REDACTED]`.
@@ -1193,6 +1338,10 @@ wrapOpenAI(client, opts?) // scrub prompts, restore replie
1193
1338
  wrapAnthropic(client, opts?) // same for messages.create + system
1194
1339
  redactPrompt(text, opts?): { text, vault }
1195
1340
 
1341
+ // from 'flare-redact/ai-sdk'
1342
+ flareRedactMiddleware(opts?) // Vercel AI SDK: wrapLanguageModel({ model, middleware })
1343
+ // opts.session keeps one vault across calls
1344
+
1196
1345
  // from 'flare-redact/tool'
1197
1346
  createScopedToolBoundary(opts?) // scope-safe model ↔ tool/MCP boundary
1198
1347
  createToolBoundary(opts?) // legacy single-trust-domain boundary
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flare-redact",
3
- "version": "1.9.1",
3
+ "version": "1.10.0",
4
4
  "description": "Keep secrets and PII out of logs, Sentry, LLM prompts and commits. Reads values, not field names. Zero dependencies.",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -21,6 +21,10 @@
21
21
  "types": "./dist/llm.d.ts",
22
22
  "default": "./dist/llm.js"
23
23
  },
24
+ "./ai-sdk": {
25
+ "types": "./dist/ai-sdk.d.ts",
26
+ "default": "./dist/ai-sdk.js"
27
+ },
24
28
  "./ml": {
25
29
  "types": "./dist/ml.d.ts",
26
30
  "default": "./dist/ml.js"
@@ -125,7 +129,7 @@
125
129
  "benchmark:agent": "npm run build && node bench/agent-flow.mjs",
126
130
  "benchmark:adversarial": "npm run build && node bench/adversarial-runtime.mjs",
127
131
  "benchmark:entities": "npm run build && node bench/entities.mjs",
128
- "prepublishOnly": "npm run build",
132
+ "prepack": "npm run build",
129
133
  "benchmark:graph": "npm run build && node bench/graph-vault.mjs",
130
134
  "build:playground": "npm run build && npx --yes esbuild dist/index.js --bundle --format=esm --minify --outfile=docs/playground/flare-redact.min.js"
131
135
  },
@@ -176,6 +180,8 @@
176
180
  "ai",
177
181
  "openai",
178
182
  "anthropic",
183
+ "vercel-ai-sdk",
184
+ "ai-sdk",
179
185
  "chatgpt",
180
186
  "claude",
181
187
  "prompt",
package/spec/SPEC.md CHANGED
@@ -64,7 +64,8 @@ A pattern **may** use:
64
64
  - character classes `[…]`, `[^…]`, ranges, and the escapes `\t \n \r \f \x0B \xHH \\ \. \* \+ \? \( \) \[ \] \{ \} \| \^ \$ \/ \-`
65
65
  - groups `(…)` (capturing) and `(?:…)` (non-capturing)
66
66
  - alternation `|`
67
- - quantifiers `* + ? {n} {n,} {n,m}` and their lazy forms `*? +? ?? {n,m}?`
67
+ - quantifiers `* + ? {n} {n,} {n,m}` and their lazy forms `*? +? ?? {n,m}?`; no count may exceed 1000,
68
+ which is the largest repetition Go's RE2 accepts
68
69
  - the two substitution tokens below
69
70
 
70
71
  A pattern **must not** use:
@@ -179,6 +180,19 @@ survives only if **all** validators return true.
179
180
  | `aba` | US routing 3-7-1 mod-10 |
180
181
  | `nhs` | UK weighted mod-11, rejects repeated digits |
181
182
  | `vin` | transliterated weighted mod-11, check character at position 9 |
183
+ | `cnp` | Romania, 13 digits, first digit 1–9; month 01–12, day 01–31; weights 2-7-9-1-4-6-3-5-8-2-7-9, mod 11, a remainder of 10 is written as 1 |
184
+ | `personnummer` | Sweden, separators `-` and `+` removed; a 12-digit value must start with 18, 19 or 20 and loses those two digits; 10 digits, month 01–12, day 01–31 or 61–91 (samordningsnummer), Luhn |
185
+ | `hetu` | Finland `DDMMYY`, century sign `-` `+` `A`–`F` `U`–`Y`, individual number ≥ 002, check character `0123456789ABCDEFHJKLMNPRSTUVWXY`[`DDMMYYNNN` mod 31]; upper case only |
186
+ | `fodselsnummer` | Norway, 11 digits; day 01–31 or 41–71 (D-number), month 01–12 or 41–52 (H-number); two mod-11 check digits, weights 3-7-6-1-8-9-4-5-2 and 5-4-3-2-7-6-5-4-3-2, a check of 10 is invalid |
187
+ | `be_national_number` | Belgium, 11 digits; month mod 20 ≤ 12 and month ≤ 52 (BIS numbers add 20 or 40), day unchecked; check = 97 − (first nine digits mod 97), or the same with a `2` prefixed (born from 2000) |
188
+ | `pt_nif` | Portugal, 9 digits starting 1, 2, 3 or 45 (a person); weights 9…2, check = ((11 − sum mod 11) mod 11) mod 10 |
189
+ | `za_id` | South Africa, 13 digits; month 01–12, day 01–31; citizenship digit (11th) 0–2; Luhn |
190
+ | `curp` | Mexico, 18 characters, upper case: 4 letters, `YYMMDD` (month 01–12, day 01–31), `H` or `M`, a state code, 3 consonants, a homoclave, a check digit; values 0–9, A–N = 10–23, O–Z = 25–36, weights 18…2, check = (10 − sum mod 10) mod 10 |
191
+ | `rut` | Chile, `.`, `-` and ASCII whitespace removed, upper-cased; 7–8 digits and a check character; weights 2…7 repeating from the right, 11 − (sum mod 11), with 11 → `0` and 10 → `K` |
192
+ | `cuit` | Argentina, 11 digits starting 20, 23, 24 or 27 (a person); weights 5-4-3-2-7-6-5-4-3-2; remainder 0 → 0, remainder 1 → 9, otherwise 11 − remainder |
193
+ | `nric` | Singapore `[STFG]` + 7 digits + letter, upper case; weights 2-7-6-5-4-3-2, plus 4 for T and G; letter from `JZIHGFEDCBA` (S, T) or `XWUTRQPNMLK` (F, G) at sum mod 11 |
194
+ | `amka` | Greece, 11 digits; `DDMMYY` with day 01–31 and month 01–12; Luhn |
195
+ | `uk_nino` | UK National Insurance number, spaces removed: prefix letters per HMRC (first not D F I Q U V, second not D F I O Q U V; never BG GB KN NK NT TN ZZ), 6 digits, suffix A–D; no checksum exists |
182
196
 
183
197
  Adding a validator name is a spec revision, not a pack change: an engine that
184
198
  does not know a name **must fail loudly** when loading the pack rather than
@@ -398,9 +412,32 @@ model without sending the data" work.
398
412
  - A generator that mints a duplicate placeholder for two different values is an
399
413
  error; silently merging them would restore the wrong secret.
400
414
 
415
+ **Restoring into JSON text.** Tool-call arguments and JSON-mode output are JSON
416
+ held in a string, and a placeholder in valid JSON can only sit inside a string
417
+ literal. A string being restored is a *JSON document* when, after any leading
418
+ JSON whitespace (space, tab, LF, CR), it starts with `{` or `[` and the whole
419
+ string parses as JSON. In a JSON document each original is inserted
420
+ **JSON-escaped**; every other string gets the original verbatim. Structured data
421
+ is restored one string at a time by the same rule. The escaped form is the
422
+ content of a JSON string literal:
423
+
424
+ | Original | Inserted as |
425
+ |---|---|
426
+ | `"` | `\"` |
427
+ | `\` | `\\` |
428
+ | U+0008, U+0009, U+000A, U+000C, U+000D | `\b`, `\t`, `\n`, `\f`, `\r` |
429
+ | any other code point below U+0020 | `\u00xx`, lowercase hex |
430
+ | a lone surrogate, where the host string can hold one | `\uxxxx`, lowercase hex |
431
+ | anything else | itself |
432
+
433
+ The document stays valid JSON, and a quote, backslash or control character in a
434
+ restored value cannot end its string and add or replace fields.
435
+
401
436
  Streaming restoration holds back the longest proper prefix of any placeholder that
402
437
  the emitted tail could still be starting, so a placeholder split across two chunks
403
- is still restored exactly once.
438
+ is still restored exactly once. A stream restorer also has a JSON mode, which
439
+ inserts the escaped form, for streams whose text is JSON: tool-call arguments,
440
+ partial tool input, and output the request asked to be JSON.
404
441
 
405
442
  ## 12. Limits and failure modes
406
443
 
@@ -448,7 +485,7 @@ purpose and listed here.
448
485
  2048-word English wordlist, which is a 14 KB payload every SDK would embed for
449
486
  one opt-in detector. Node keeps it; a future revision may add a `wordlists`
450
487
  section.
451
- 2. **Trailing boundaries on dash-terminated tokens are stricter.** `\bglpat-[A-Za-z0-9_-]{20}\b`
488
+ 2. **Trailing boundaries on dash-terminated tokens are stricter.** `\bxox[baprs]-[A-Za-z0-9-]{10,64}\b`
452
489
  in JavaScript requires a *word* character after a token ending in `-`, which
453
490
  truncates such tokens. FRS-1 uses `word_dash`, which does not.
454
491
  3. **`coordinates` accepts a leading minus after a word character.** The JavaScript
@@ -41,7 +41,10 @@ formatting change.
41
41
  accepts.
42
42
  - `checks` defaults to `["redact", "scan"]`; add `"vault"` for a round trip, and
43
43
  set `"vault": {"placeholderStyle": "readable"}` so the placeholders are
44
- deterministic.
44
+ deterministic. A `"reply"` inside `"vault"` is a value that uses those
45
+ placeholders, as a model would send it back; it is restored with the same
46
+ vault (see [SPEC.md §11](../SPEC.md#11-vaults-and-reversible-redaction) for
47
+ restoring into JSON text).
45
48
 
46
49
  A good case answers a question someone will actually ask. The corpus is
47
50
  deliberately full of negatives — a Luhn-invalid card, a random 12-digit run, a
@@ -53,6 +56,10 @@ gets turned off.
53
56
  - **No astral-plane characters.** Offsets are reported in the host language's
54
57
  natural string unit: UTF-16 code units in JavaScript, scalar values elsewhere.
55
58
  These coincide for everything below U+10000, and the corpus stays there.
59
+ - **No complete credential in the raw file.** A case that holds a whole token
60
+ writes one character of its prefix as a `\uXXXX` escape (`glpat\u002d…`).
61
+ Every JSON parser reads the plain character, so the engines see the real
62
+ token, while secret scanners and push protection do not flag the fixture.
56
63
  - **No wall-clock or randomness.** Vault cases use readable placeholders; keyed
57
64
  transforms use a fixed `transformSecret`.
58
65
  - **Confidence is compared at six decimal places**, which is finer than any
@@ -41,11 +41,45 @@
41
41
  { "name": "sentry/dsn", "input": "SENTRY_DSN=https://0123456789abcdef0123456789abcdef@o1.ingest.sentry.io/12345" },
42
42
  { "name": "doppler/token", "input": "dp.st.dev.abcdefghijklmnopqrstuvwxyz0123456789ABCD" },
43
43
  { "name": "postman/key", "input": "PMAK-0123456789abcdef01234567-0123456789abcdef0123456789abcdef01" },
44
+ { "name": "gitlab/routable-token", "input": "CI_TOKEN glpat\u002dabcdefghijklmnopqrstuvwxyz0.01abcdefg here" },
45
+ { "name": "gitlab/runner-token", "input": "runner glrt\u002dABCDEFGHIJKLMNOPQRST registered" },
46
+ { "name": "gitlab/deploy-token-negative", "input": "gldt-ABCDEFGHIJ is too short" },
47
+ { "name": "digitalocean/oauth-token", "input": "doo\u005fv1_0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" },
48
+ { "name": "slack/webhook", "input": "SLACK_WEBHOOK https://hooks.slack.com\u002fservices/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX" },
49
+ { "name": "google/oauth-secret", "input": "oauth GOCSPX\u002dabcdefghijklmnopqrstuvwxyz01" },
50
+ { "name": "aws/bedrock-key", "input": "A\u0042SKQmVkcm9ja0FQSUtleS1leGFtcGxlabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789AB" },
51
+ { "name": "langsmith/key", "input": "lsv2\u005fpt_0123456789abcdef0123456789abcdef_0123456789" },
52
+ { "name": "pinecone/key", "input": "pcsk\u005fabcde_abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZa" },
53
+ { "name": "tavily/key", "input": "tvly\u002ddev-abcdefghijklmnopqrstuvwxyz012345" },
54
+ { "name": "pypi/token", "input": "pypi\u002dAgEIcHlwaS5vcmcabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWX" },
55
+ { "name": "pypi/negative-no-macaroon", "input": "pypi-abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWX" },
56
+ { "name": "rubygems/key", "input": "rubygems\u005f0123456789abcdef0123456789abcdef0123456789abcdef" },
57
+ { "name": "dockerhub/pat", "input": "docker login -p dckr\u005fpat_abcdefghijklmnopqrstuvwxyz0" },
58
+ { "name": "jfrog/api-key", "input": "A\u004bCpabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefg" },
59
+ { "name": "atlassian/token", "input": "A\u0054ATT3xFfGF0abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJK=0A1B2C3D" },
60
+ { "name": "grafana/service-account", "input": "glsa\u005fabcdefghijklmnopqrstuvwxyz012345_0a1b2c3d" },
61
+ { "name": "sentry/user-token", "input": "sntryu\u005f0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" },
62
+ { "name": "dynatrace/token", "input": "dt0c01\u002eABCDEFGHIJKLMNOPQRSTUVWX.ABCDEFGHIJKLMNOPQRSTUVWXYZ234567ABCDEFGHIJKLMNOPQRSTUVWXYZ234567" },
63
+ { "name": "heroku/key", "input": "HRKU\u002dAAabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUV" },
64
+ { "name": "flyio/token", "input": "FlyV1 fo1\u005fabcdefghijklmnopqrstuvwxyz0123456789ABCDEFG" },
65
+ { "name": "planetscale/token", "input": "pscale\u005ftkn_abcdefghijklmnopqrstuvwxyz0123456789ABCDEF" },
66
+ { "name": "pulumi/token", "input": "PULUMI pul\u002d0123456789abcdef0123456789abcdef01234567" },
67
+ { "name": "terraform/token", "input": "abcdefghijklmn\u002eatlasv1.abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcd" },
68
+ { "name": "onepassword/token", "input": "op ops\u005feyJabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijkl" },
69
+ { "name": "age/secret-key", "input": "AGE\u002dSECRET-KEY-1QPZRY9X8GF2TVDW0S3JN54KHCE6MUA7LQPZRY9X8GF2TVDW0S3JN54KHCE" },
70
+ { "name": "alibaba/access-key", "input": "L\u0054AIabcdefghijklmnopqrst" },
71
+ { "name": "mailchimp/key", "input": "0123456789abcdef0123456789abcdef\u002dus21" },
72
+ { "name": "mailchimp/negative-region", "input": "0123456789abcdef0123456789abcdef-us-east-1" },
73
+ { "name": "brevo/key", "input": "xkeysib\u002d0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef-abcdefghijkmnopq" },
74
+ { "name": "resend/key", "input": "re\u005fabcdefgh_ijkmnopqrstuvwxyzABCDEFG" },
75
+ { "name": "resend/negative-identifier", "input": "re_compute_cache" },
44
76
 
45
77
  { "name": "jwt/basic", "input": "Authorization eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.dozjgNryP4J3jVmNHl0w5N_XgL0n3I9PlFUP0THsR8U" },
46
78
  { "name": "bearer/header", "input": "Authorization: Bearer abcdefghijklmnopqrstuvwx" },
47
79
  { "name": "basic/header", "input": "Authorization: Basic YWRtaW46aHVudGVyMg==" },
48
80
  { "name": "url/credentials", "input": "DATABASE_URL=postgres://app:s3cr3t-pass@db.internal:5432/main" },
81
+ { "name": "url/credentials-underscore-scheme", "input": "SQLALCHEMY_URL=oracle+cx_oracle://scott:tiger-pass@db.internal:1521/orcl" },
82
+ { "name": "url/credentials-long-scheme-run", "input": "a-b.a-b.a-b.a-b.a-b.a-b.a-b.a-b.a-b.a-b.a-b.a-b.a-b.a-b.a-b.a-b.a-b.a-b.ab://u:p@h then mysql+mysqldb://root:s3cret@localhost/app" },
49
83
  { "name": "private-key/pem", "input": "-----BEGIN RSA PRIVATE KEY-----\nMIIBOgIBAAJBAKj34GkxFhD90vcNLYLInFEX6Ppy1tPf9Cnzj4p4WGeKLs1Pt8Qu\n-----END RSA PRIVATE KEY-----" },
50
84
  { "name": "private-key/mismatched-footer", "input": "-----BEGIN RSA PRIVATE KEY-----\nMIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAq7BFUpkGp3+LQmlQ\n-----END CERTIFICATE-----\nnext line" },
51
85
  { "name": "private-key/truncated", "input": "log: -----BEGIN OPENSSH PRIVATE KEY-----\nMIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAq7BFUpkGp3+LQmlQ\nMIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAq7BFUpkGp3+LQmlQ" },
@@ -127,6 +161,27 @@
127
161
  { "name": "id/uk-nhs", "input": "NHS 943 476 5919", "options": { "enable": ["uk_nhs"] } },
128
162
  { "name": "id/vin", "input": "VIN 1HGBH41JXMN109186", "options": { "enable": ["vin"] } },
129
163
  { "name": "id/aba-routing", "input": "routing 021000021", "options": { "enable": ["aba_routing"] } },
164
+ { "name": "id/ro-cnp", "input": "CNP 1850101401238", "options": { "enable": ["ro"] } },
165
+ { "name": "id/se-personnummer", "input": "personnummer 850709-1232", "options": { "enable": ["se"] } },
166
+ { "name": "id/se-personnummer-12-digit", "input": "pnr 200505054569", "options": { "enable": ["se"] } },
167
+ { "name": "id/se-samordningsnummer", "input": "samordningsnummer 850769-1239", "options": { "enable": ["se"] } },
168
+ { "name": "id/fi-hetu", "input": "HETU 010185-123B", "options": { "enable": ["fi"] } },
169
+ { "name": "id/fi-hetu-2000s", "input": "HETU 150605A456H", "options": { "enable": ["fi"] } },
170
+ { "name": "id/no-fodselsnummer", "input": "fnr 010185 12366", "options": { "enable": ["no"] } },
171
+ { "name": "id/no-d-number", "input": "D-nummer 41018510187", "options": { "enable": ["no"] } },
172
+ { "name": "id/be-national-number", "input": "NN 85.01.01-123.87", "options": { "enable": ["be"] } },
173
+ { "name": "id/be-bis", "input": "BIS 85210112333", "options": { "enable": ["be"] } },
174
+ { "name": "id/pt-nif", "input": "NIF 123 456 789", "options": { "enable": ["pt"] } },
175
+ { "name": "id/za-id-outranks-card", "input": "ID 850101 5123 08 5", "options": { "enable": ["za"] } },
176
+ { "name": "id/mx-curp", "input": "CURP ABCD850101HDFBCD00", "options": { "enable": ["mx"] } },
177
+ { "name": "id/cl-rut", "input": "RUT 12.345.678-5", "options": { "enable": ["cl"] } },
178
+ { "name": "id/cl-rut-k", "input": "RUN 10000013-k", "options": { "enable": ["cl"] } },
179
+ { "name": "id/ar-cuit", "input": "CUIL 20-12345678-6", "options": { "enable": ["ar"] } },
180
+ { "name": "id/sg-nric", "input": "NRIC S1234567D, FIN G1234567X", "options": { "enable": ["sg"] } },
181
+ { "name": "id/il-teudat-zehut", "input": "TZ 12345678-2", "options": { "enable": ["il"] } },
182
+ { "name": "id/gr-amka", "input": "AMKA 01018512341", "options": { "enable": ["gr"] } },
183
+ { "name": "id/uk-nino", "input": "NINO AB 12 34 56 C", "options": { "enable": ["uk_nino"] } },
184
+ { "name": "id/negative-checksum-valid-near-misses", "input": "CNP 1851301401236 HETU 320185-123B AMKA 32018512346 CURP ABCD851301HDFBCD06 NRIC S1234567A NINO QQ 12 34 56 C", "options": { "enable": ["ro", "fi", "gr", "mx", "sg", "gb"] } },
130
185
  { "name": "id/negative-random-digits", "input": "sequence 123456789012 means nothing", "options": { "enable": ["pii", "id"] } },
131
186
 
132
187
  { "name": "crypto/eth-address", "input": "wallet 0x52908400098527886E0F7030069857D2E4169EE7", "options": { "enable": ["crypto"] } },
@@ -156,6 +211,10 @@
156
211
  { "name": "vault/round-trip", "input": "email ada@example.com and grace@example.org", "vault": { "placeholderStyle": "readable" }, "checks": ["vault"] },
157
212
  { "name": "vault/stable-placeholder", "input": "ada@example.com then ada@example.com again", "vault": { "placeholderStyle": "readable" }, "checks": ["vault"] },
158
213
  { "name": "vault/structured", "input": { "cc": ["grace@example.org"], "password": "hunter2", "to": "ada@example.com" }, "vault": { "placeholderStyle": "readable" }, "checks": ["vault"] },
159
- { "name": "vault/array-order", "input": ["ada@example.com", "grace@example.org", "ada@example.com"], "vault": { "placeholderStyle": "readable" }, "checks": ["vault"] }
214
+ { "name": "vault/array-order", "input": ["ada@example.com", "grace@example.org", "ada@example.com"], "vault": { "placeholderStyle": "readable" }, "checks": ["vault"] },
215
+ { "name": "vault/reply-json-arguments", "input": { "password": "x\",\"extra\":true,\"y\":\"\\\n\t\u0001", "user": "bob" }, "vault": { "placeholderStyle": "readable", "reply": { "arguments": "{\"password\":\"[SENSITIVE_KEY_1]\",\"remember\":false}", "name": "login" } }, "checks": ["vault"] },
216
+ { "name": "vault/reply-json-document", "input": "save Q\"uo\\te\nline\ttab\u0001end", "options": { "terms": ["Q\"uo\\te\nline\ttab\u0001end"] }, "vault": { "placeholderStyle": "readable", "reply": "\n [\"[CUSTOM_TERM_1]\", 1]" }, "checks": ["vault"] },
217
+ { "name": "vault/reply-json-structure-kept", "input": "call back https://user:pa\",\"extra\":true,\"note\":\"x@example.com/pay", "vault": { "placeholderStyle": "readable", "reply": "{\"amount\":10,\"callback\":\"[URL_CREDENTIALS_1]\"}" }, "checks": ["vault"] },
218
+ { "name": "vault/reply-other-strings-verbatim", "input": "save Q\"uo\\te\nline\ttab\u0001end", "options": { "terms": ["Q\"uo\\te\nline\ttab\u0001end"] }, "vault": { "placeholderStyle": "readable", "reply": { "leaf": { "note": "[CUSTOM_TERM_1]" }, "text": ["said \"[CUSTOM_TERM_1]\" twice", "{ not json [CUSTOM_TERM_1]", "[CUSTOM_TERM_1]"] } }, "checks": ["vault"] }
160
219
  ]
161
220
  }