flare-redact 0.8.0 → 0.9.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/CHANGELOG.md ADDED
@@ -0,0 +1,46 @@
1
+ # Changelog
2
+
3
+ ## 0.9.0 — 2026-07-23
4
+
5
+ ### Security
6
+
7
+ - Replace 32-bit FNV correlation tokens with keyed HMAC-SHA-256.
8
+ - Rename non-reversible shape preservation to `pseudonym`; retain `fpe` only as
9
+ a deprecated compatibility alias and stop describing it as encryption.
10
+ - Add deterministic type-consistent `surrogate` mode.
11
+ - Require `transformSecret` for hash, pseudonym, and surrogate modes.
12
+ - Use opaque 96-bit random vault placeholders by default.
13
+ - Add PBKDF2-SHA-256 + AES-256-GCM authenticated vault persistence.
14
+ - Make CLI vault files encrypted by default and reject plaintext maps unless
15
+ `--allow-plaintext-vault` is explicit.
16
+ - Add per-string input/finding limits and hostile-input benchmarks.
17
+
18
+ ### Detection and resilience
19
+
20
+ - Add risk and confidence to findings and SARIF output.
21
+ - Add weighted risk-aware overlap resolution.
22
+ - Add opt-in contextual person-name, street-address, and birth-date detectors.
23
+ - Add sync and async semantic-provider hooks for local NER models.
24
+ - Detect bracket-obfuscated email addresses, spaced AWS keys, and tokens split
25
+ with zero-width characters while preserving original character spans.
26
+ - Add reproducible latency and hostile-input scaling benchmarks.
27
+ - Change scan JSON to schema version 2.
28
+ - Make line/column calculation linear in input plus findings instead of rescanning
29
+ the prefix for every finding.
30
+
31
+ ### Migration
32
+
33
+ - Upgrade Node.js to version 20 or newer. Opaque vault placeholders and encrypted
34
+ vault persistence rely on the stable Web Crypto API.
35
+ - Set `transformSecret` in code, or `FLARE_REDACT_SECRET` for the CLI, when using
36
+ deterministic protected modes.
37
+ - Set `FLARE_REDACT_VAULT_PASSWORD` before CLI `--vault` or `--restore`.
38
+ - Use `createVault({ placeholderStyle: 'readable' })` only if legacy predictable
39
+ placeholders are required in a trusted local flow.
40
+ - Update scan-report consumers for schema version 2 and the `risk` and
41
+ `confidence` fields.
42
+
43
+ ## 0.8.0
44
+
45
+ - Add file-aware scan reports with line/column locations, safe JSON, and SARIF
46
+ output for CI and code-scanning integrations.
package/README.md CHANGED
@@ -15,7 +15,7 @@
15
15
  <img src="https://img.shields.io/npm/types/flare-redact.svg" alt="TypeScript">
16
16
  <img src="https://img.shields.io/badge/dependencies-0-brightgreen" alt="Zero dependencies">
17
17
  <img src="https://img.shields.io/badge/languages-24-4f46e5" alt="24 languages">
18
- <img src="https://img.shields.io/badge/detectors-50-4f46e5" alt="50 detectors">
18
+ <img src="https://img.shields.io/badge/detectors-56-4f46e5" alt="56 detectors">
19
19
  <img src="https://img.shields.io/badge/runtime-node%20%7C%20browser%20%7C%20edge-blue" alt="Runtimes">
20
20
  </p>
21
21
 
@@ -46,8 +46,8 @@ redact('User alice@corp.com paid with 4242 4242 4242 4242, token ghp_' + 'a'.rep
46
46
  Nothing to configure. No list of field paths to maintain. No native build step.
47
47
 
48
48
  > **The same problem now has a new address: your LLM calls.** Wrap your OpenAI or
49
- > Anthropic client and secrets are stripped from every prompt and restored in the
50
- > reply — the model never sees the real data, your app still gets the right answer.
49
+ > Anthropic client and detected secrets are stripped from prompts and restored in
50
+ > the reply — the model never sees those original values, while references survive.
51
51
  > [Jump to it ↓](#redact-prompts-before-they-reach-an-llm)
52
52
 
53
53
  <p align="center">
@@ -56,8 +56,8 @@ Nothing to configure. No list of field paths to maintain. No native build step.
56
56
 
57
57
  | | | |
58
58
  |---|---|---|
59
- | 🔍 **Content-aware** — reads values, not just field names | ♻️ **Reversible** — vault: redact → use → restore | 🎭 **Format-preserving** — emails stay email-shaped |
60
- | 🤖 **LLM-safe** — strips secrets before OpenAI/Anthropic | 🌍 **24 languages** — plus checksum-validated national IDs | 🛡️ **ReDoS-safe · 0 deps** — safe on untrusted input |
59
+ | 🔍 **Context-aware** — spans carry risk and confidence | 🔐 **Secure vaults** — opaque tokens, optional AES-GCM persistence | 🎭 **Useful test data** — keyed pseudonyms and typed surrogates |
60
+ | 🤖 **LLM boundary** — strips secrets before OpenAI/Anthropic | 🌍 **24-language secret vocabulary** — plus checksum-validated IDs | 🪶 **Zero runtime dependencies** — Node, browser, and edge |
61
61
 
62
62
  ## Contents
63
63
 
@@ -66,6 +66,7 @@ Nothing to configure. No list of field paths to maintain. No native build step.
66
66
  - [Redact prompts before they reach an LLM](#redact-prompts-before-they-reach-an-llm)
67
67
  - [Ways to hide a value](#ways-to-hide-a-value)
68
68
  - [Reversible redaction](#reversible-redaction)
69
+ - [Contextual and model-assisted PII](#contextual-and-model-assisted-pii)
69
70
  - [Build a private chat app](#build-a-private-chat-app)
70
71
  - [Your own words](#your-own-words)
71
72
  - [See what leaks, and why](#see-what-leaks-and-why)
@@ -77,9 +78,10 @@ Nothing to configure. No list of field paths to maintain. No native build step.
77
78
  - [Fail a build when a secret sneaks in](#fail-a-build-when-a-secret-sneaks-in)
78
79
  - [CLI](#cli)
79
80
  - [What it catches](#what-it-catches)
80
- - [Every language, every country](#every-language-every-country)
81
+ - [Multilingual secret vocabulary and IDs](#multilingual-secret-vocabulary-and-ids)
81
82
  - [Custom detectors & allowlists](#custom-detectors--allowlists)
82
83
  - [API](#api)
84
+ - [Security boundaries](#security-boundaries)
83
85
  - [Why not a field allowlist?](#why-not-a-field-allowlist)
84
86
 
85
87
  ## Install
@@ -88,7 +90,9 @@ Nothing to configure. No list of field paths to maintain. No native build step.
88
90
  npm install flare-redact
89
91
  ```
90
92
 
91
- Node 18+, and it runs in the browser and edge runtimes too — zero dependencies.
93
+ Node 20+, and it runs in the browser and edge runtimes too — zero dependencies.
94
+ Upgrading from 0.8? Read the [`0.9 migration notes`](CHANGELOG.md#090--2026-07-23)
95
+ before changing protected transform or vault behavior.
92
96
 
93
97
  ## Redact anything
94
98
 
@@ -117,9 +121,9 @@ redact({
117
121
 
118
122
  Your app sends user data to OpenAI or Anthropic. Somewhere in that prompt is a
119
123
  customer's email, an API key, or a card number — and now it's left your systems.
120
- Wrap the client once, and secrets are stripped from every prompt and put back in
121
- the reply. The model never sees the real values; your code still gets the right
122
- answer.
124
+ Wrap the client once, and detected secrets are stripped from prompts and put back
125
+ in the reply. The model never sees those original values; your code keeps the
126
+ references it needs.
123
127
 
124
128
  ```js
125
129
  import { wrapOpenAI } from 'flare-redact/llm';
@@ -134,7 +138,7 @@ const res = await openai.chat.completions.create({
134
138
 
135
139
  ```
136
140
  your app sends → Email the invoice to alice@corp.com, card 4242 4242 4242 4242
137
- the model sees → Email the invoice to [EMAIL_1], card [CREDIT_CARD_1]
141
+ the model sees → Email the invoice to [FR_EMAIL_7f2a…], card [FR_CREDIT_CARD_19be…]
138
142
  your app gets → Sent to alice@corp.com. Card 4242 4242 4242 4242 wasn't stored.
139
143
  ```
140
144
 
@@ -151,16 +155,27 @@ after it's hidden.
151
155
  ```js
152
156
  redact('bob@corp.com', { mode: 'mask' }); // 'b***@***' (default)
153
157
  redact('bob@corp.com', { mode: 'label' }); // '[REDACTED:email]'
154
- redact('bob@corp.com', { mode: 'hash' }); // 'email_f63d8d56' (deterministic)
155
- redact('bob@corp.com', { mode: 'fpe' }); // 'kqz@rwmp.dnu' (keeps the shape)
158
+
159
+ const protectedOptions = { transformSecret: process.env.FLARE_REDACT_SECRET };
160
+ redact('bob@corp.com', { ...protectedOptions, mode: 'hash' });
161
+ // 'email_3baf4d28d7c88317a…' — HMAC-SHA-256 fingerprint
162
+
163
+ redact('bob@corp.com', { ...protectedOptions, mode: 'pseudonym' });
164
+ // 'kqz@rwmp.dnu' — keyed, deterministic, keeps character classes
165
+
166
+ redact('bob@corp.com', { ...protectedOptions, mode: 'surrogate' });
167
+ // 'user_93a78c61e204@example.invalid' — type-consistent synthetic value
156
168
  ```
157
169
 
158
- `hash` is the useful one for support work: the same input always hashes to the
159
- same token, so you can still tell that two log lines came from the same user —
160
- without ever storing who that user is. `fpe` (format-preserving) keeps the
161
- *shape* — an email stays email-shaped, a card stays card-shaped — which is what
162
- you want for realistic-but-safe test data. Both are deterministic; add `hashSalt`
163
- to make the mapping per-service.
170
+ Protected deterministic modes require `transformSecret`; they never silently
171
+ fall back to a public unsalted fingerprint. `hash` is useful for correlation,
172
+ `pseudonym` retains the original character shape, and `surrogate` emits typed
173
+ synthetic values such as reserved-domain emails and Luhn-valid card numbers.
174
+ Use a separate secret per environment or correlation domain.
175
+
176
+ `pseudonym` is deliberately **not** described as format-preserving encryption.
177
+ It is non-reversible pseudonymization, not NIST FF1. The old `fpe` name remains
178
+ as a compatibility alias but is deprecated.
164
179
 
165
180
  Or replace everything with one fixed string:
166
181
 
@@ -180,24 +195,90 @@ import { createVault } from 'flare-redact';
180
195
 
181
196
  const vault = createVault();
182
197
  const safe = vault.redact('charge bob@corp.com on card 4242 4242 4242 4242');
183
- // 'charge [EMAIL_1] on card [CREDIT_CARD_1]'
198
+ // 'charge [FR_EMAIL_7f2ad4…] on card [FR_CREDIT_CARD_19be63…]'
184
199
 
185
200
  vault.restore(safe);
186
201
  // 'charge bob@corp.com on card 4242 4242 4242 4242'
187
202
  ```
188
203
 
189
- The same value always gets the same placeholder, so references survive the round
190
- trip. Works on objects too, and `restore()` also takes a plain placeholder→value
191
- map if you persisted one.
204
+ The same value gets the same placeholder inside one vault, so references survive
205
+ the round trip. Default placeholders include 96 random bits instead of a global
206
+ sequence number. Human-readable `[EMAIL_1]` counters remain available through
207
+ `createVault({ placeholderStyle: 'readable' })` for trusted local workflows.
208
+
209
+ The mapping is as sensitive as the original data. Encrypt it before persistence:
210
+
211
+ ```js
212
+ import { sealVault, openVault, restore } from 'flare-redact';
213
+
214
+ const encrypted = await sealVault(vault, process.env.FLARE_REDACT_VAULT_PASSWORD);
215
+ await fs.writeFile('session.vault.json', JSON.stringify(encrypted), { mode: 0o600 });
216
+
217
+ const entries = await openVault(encrypted, process.env.FLARE_REDACT_VAULT_PASSWORD);
218
+ restore(safe, new Map(entries));
219
+ ```
220
+
221
+ Sealed vaults use PBKDF2-SHA-256 with a fresh salt and AES-256-GCM with a fresh
222
+ nonce. Wrong passwords and modified files fail closed.
223
+
224
+ From the CLI, `--vault` and `--restore` use encrypted files by default. Passwords
225
+ come from `FLARE_REDACT_VAULT_PASSWORD` (or the variable named by
226
+ `--vault-password-env`) so they do not appear in shell history:
227
+
228
+ ```bash
229
+ export FLARE_REDACT_VAULT_PASSWORD='use-a-secret-manager-in-production'
230
+ flare-redact --vault session.vault.json < input.txt > safe.txt
231
+ flare-redact --restore session.vault.json < safe.txt > restored.txt
232
+ ```
233
+
234
+ ## Contextual and model-assisted PII
235
+
236
+ Structured identifiers and credentials are best handled by deterministic rules
237
+ and checksum validators. Names and addresses need context, so three conservative
238
+ detectors are opt-in:
239
+
240
+ ```js
241
+ const findings = scan(
242
+ 'Customer name: Alice Example; address: 120 Cedar Street; DOB: 1990-04-23',
243
+ { enable: ['contextual'] },
244
+ );
245
+
246
+ // person_name, street_address, date_of_birth
247
+ // each finding includes risk, confidence, and the exact sensitive span
248
+ ```
249
+
250
+ For broader multilingual free-text PII, connect a local model without coupling
251
+ the zero-dependency core to one ML runtime:
252
+
253
+ ```js
254
+ const policy = {
255
+ semanticProvider: {
256
+ async detect(text) {
257
+ return [{
258
+ detector: 'person_model', label: 'Person',
259
+ why: 'Local multilingual NER result.',
260
+ start: 12, end: 25, confidence: 0.94, risk: 'high',
261
+ }];
262
+ },
263
+ },
264
+ minConfidence: 0.8,
265
+ };
266
+
267
+ const safe = await redactAsync(input, policy);
268
+ ```
269
+
270
+ Semantic and deterministic spans enter the same overlap arbitration. Higher-risk,
271
+ higher-priority, and better-validated findings win instead of whichever regular
272
+ expression happens to run first.
192
273
 
193
274
  ## Build a private chat app
194
275
 
195
276
  If you're building a chat interface — over your own local model or any API — a
196
277
  **session** is the drop-in layer. One session holds one vault, so a value keeps
197
278
  the same placeholder across every turn: mask the user's message on the way in,
198
- restore the model's reply on the way out. It's model-agnostic, synchronous, and
199
- fast enough that the cost vanishes next to inference (a 13 KB message redacts in
200
- ~0.3 ms).
279
+ restore the model's reply on the way out. It's model-agnostic and synchronous.
280
+ Run `npm run benchmark` on your own target runtime instead of relying on a
281
+ hardware-independent latency claim.
201
282
 
202
283
  ```js
203
284
  import { createSession } from 'flare-redact';
@@ -221,8 +302,8 @@ process(out.flush());
221
302
  ```
222
303
 
223
304
  `session.redactMessages([{ role, content }])` masks a whole chat array at once,
224
- and `session.reset()` starts a fresh conversation. The model never sees the real
225
- data; your app still works end to end.
305
+ and `session.reset()` starts a fresh conversation. Detected original values stay
306
+ local while your app keeps a reversible reference.
226
307
 
227
308
  ## Your own words
228
309
 
@@ -239,7 +320,7 @@ redact('Launch Project Zeus with Falcon', {
239
320
 
240
321
  // reversible — send to a model, get it back
241
322
  const vault = createVault({ terms: ['Project Zeus'] });
242
- const safe = vault.redact('ship Project Zeus'); // 'ship [CUSTOM_TERM_1]'
323
+ const safe = vault.redact('ship Project Zeus'); // 'ship [FR_CUSTOM_TERM_a17c…]'
243
324
  vault.restore(safe); // 'ship Project Zeus'
244
325
  ```
245
326
 
@@ -247,7 +328,8 @@ The same works from the CLI, including a full round-trip — mask, send the safe
247
328
  text anywhere, then restore what comes back:
248
329
 
249
330
  ```bash
250
- # add words inline or from a file, and write the mapping to a vault file
331
+ # add words inline or from a file, and write an encrypted vault
332
+ export FLARE_REDACT_VAULT_PASSWORD='read-this-from-your-secret-manager'
251
333
  flare-redact --term "Project Zeus" --terms codenames.txt --vault map.json < in > safe
252
334
 
253
335
  # later, restore the originals from that map
@@ -361,19 +443,19 @@ process.stdin.pipe(redactStream()).pipe(process.stdout);
361
443
 
362
444
  ## Anonymize a dataset for staging
363
445
 
364
- Point it at a JSON or CSV dump with `--mode fpe` and you get a copy that's safe
365
- to hand to staging or a test suite. Format-preserving means an email stays
366
- email-shaped and a card stays card-shaped; deterministic means the same value
367
- maps the same way in every row — so foreign keys and joins still line up.
446
+ Point it at a JSON or CSV dump with `--mode surrogate` and you get deterministic,
447
+ typed synthetic values. The same input maps the same way in every row under one
448
+ key, so joins survive without calling the transformation encryption or anonymity.
368
449
 
369
450
  ```bash
370
- flare-redact --csv --mode fpe < customers.csv > customers.safe.csv
451
+ export FLARE_REDACT_SECRET='read-this-from-your-secret-manager'
452
+ flare-redact --csv --mode surrogate < customers.csv > customers.safe.csv
371
453
  ```
372
454
 
373
455
  ```
374
- Alice,alice@corp.com,4242 4242 4242 4242 Alice,lkjjg@vfld.adz,7042 5270 7797 8929
375
- Bob,bob@corp.com,5555 5555 5555 4444 → Bob,yay@vjxl.fpe,0888 2706 6232 0279
376
- Alice,alice@corp.com,4242 4242 4242 4242 Alice,lkjjg@vfld.adz,7042 5270 7797 8929
456
+ Alice,alice@corp.com,4242 4242 4242 4242 Alice,user_93a78c61e204@example.invalid,7042 5270 7797 8927
457
+ Bob,bob@corp.com,5555 5555 5555 4444 → Bob,user_441ae72c0901@example.invalid,0888 2706 6232 0274
458
+ Alice,alice@corp.com,4242 4242 4242 4242 Alice,user_93a78c61e204@example.invalid,7042 5270 7797 8927
377
459
  ```
378
460
 
379
461
  `redactCsv(text, opts)` is available from `flare-redact/csv` for the same thing
@@ -415,8 +497,8 @@ npm install -g flare-redact
415
497
 
416
498
  ```bash
417
499
  tail -f app.log | flare-redact # stream redacted logs
418
- flare-redact --json --mode hash < event.json # deep-redact a JSON payload
419
- flare-redact --csv --mode fpe < dump.csv # anonymize a dataset for staging
500
+ FLARE_REDACT_SECRET=… flare-redact --json --mode hash < event.json
501
+ FLARE_REDACT_SECRET=… flare-redact --csv --mode surrogate < dump.csv
420
502
  flare-redact --scan config.env # list findings + why (exit 1 if any)
421
503
  flare-redact --scan --format json .env app.log # safe machine-readable report
422
504
  flare-redact --sarif .env > results.sarif # GitHub code-scanning report
@@ -448,6 +530,7 @@ On by default:
448
530
  | `url_credentials` | passwords inside connection strings |
449
531
  | `generic_assignment` | `password=`, `api_key: …`, `secret=…` (any language) |
450
532
  | `email` | email addresses |
533
+ | `obfuscated_email` | bracket-obfuscated emails such as `name [at] host [dot] tld` |
451
534
  | `credit_card` | card numbers (Luhn-validated) |
452
535
  | `iban` | IBANs (mod-97 validated) |
453
536
  | `discord_bot_token` / `telegram_bot_token` | chat bot tokens |
@@ -469,7 +552,7 @@ Opt in with `enable`:
469
552
  Plus object values whose **key name** is sensitive (`password`, `token`,
470
553
  `authorization`, `cookie`, `cvv`, …) are masked regardless of content.
471
554
 
472
- ## Every language, every country
555
+ ## Multilingual secret vocabulary and IDs
473
556
 
474
557
  Secrets like API keys and card numbers don't care what language your app is in.
475
558
  Neither does this — but the word-based checks do, so words like *password*,
@@ -535,14 +618,19 @@ redact(text, {
535
618
 
536
619
  ```ts
537
620
  redact<T>(input: T, opts?): T // masked copy, same shape
621
+ redactAsync<T>(input: T, opts?): Promise<T> // supports async local NER providers
538
622
  scan(input, opts?): Finding[] // findings + why, input untouched
623
+ scanAsync(input, opts?): Promise<Finding[]> // supports async local NER providers
539
624
  isClean(input, opts?): boolean // any secrets at all?
540
- summary(input, opts?): { total, byDetector } // counts per detector
625
+ isCleanAsync(input, opts?): Promise<boolean>
626
+ summary(input, opts?): { total, byDetector, byRisk }
541
627
  createRedactor(opts) / definePolicy(opts) // one policy: redact, scan, vault(), wrapConsole, options
542
628
  wrapConsole(opts?, console?): () => void // patch console.*, returns restore
543
629
 
544
630
  createVault(opts?): Vault // reversible: redact / restore / entries
545
631
  restore(input, vaultOrMap): T // put originals back
632
+ sealVault(vaultOrEntries, password): Promise<SealedVaultV1>
633
+ openVault(envelope, password): Promise<Array<[placeholder, original]>>
546
634
 
547
635
  // adapters — each takes the same options object
548
636
  pinoRedact(opts?) // 'flare-redact/pino' → { formatters: { log } }
@@ -563,7 +651,8 @@ redactStream(opts?): Transform // line-wise stream redaction
563
651
  // opts
564
652
  // {
565
653
  // only?, enable?, disable?, custom?, // which detectors run
566
- // mode?: 'mask' | 'label' | 'hash' | 'fpe', hashSalt?, mask?,
654
+ // mode?: 'mask' | 'label' | 'hash' | 'pseudonym' | 'surrogate',
655
+ // transformSecret?, mask?, minConfidence?, semanticProvider?, limits?,
567
656
  // redactKeys?: boolean | RegExp | string[],
568
657
  // allow?: RegExp | string[],
569
658
  // terms?: string[] | { term: replacement }, termsCaseSensitive?,
@@ -579,10 +668,29 @@ you *remembered* to name. The leak is always the field you forgot — the free-t
579
668
  message, the nested third-party payload, the string someone concatenated by hand.
580
669
  flare-redact scans the actual values, so it doesn't depend on your memory.
581
670
 
582
- And the patterns it scans with are **bounded and ReDoS-safe** — no nested
583
- quantifiers, no `(a+)+` blow-ups. You can point it at attacker-controlled input
584
- and it stays linear, the same principle behind its sibling
585
- [flare-regex](https://github.com/umudhasanli/flare-regex).
671
+ Built-in patterns are reviewed for bounded structure, exercised by an
672
+ adversarial runtime suite, and protected by per-string input and finding limits.
673
+ JavaScript RegExp does not provide a formal linear-time guarantee, however, and
674
+ arbitrary custom detectors are trusted code. Run the included benchmarks on your
675
+ own runtime instead of treating a badge as a security proof:
676
+
677
+ ```bash
678
+ npm run benchmark
679
+ npm run benchmark:adversarial
680
+ ```
681
+
682
+ ## Security boundaries
683
+
684
+ - Detection is best-effort; a clean scan is not proof that data contains no PII.
685
+ - `pseudonym` is keyed, deterministic pseudonymization — not NIST FF1 encryption.
686
+ - A vault map is sensitive; persist only the authenticated encrypted envelope.
687
+ - Restoring a placeholder intentionally reveals its original locally. Do not
688
+ forward restored model output to another untrusted sink automatically.
689
+ - The 24-language badge describes secret-key vocabulary, not general multilingual
690
+ named-entity recognition. Use a local `semanticProvider` for that task.
691
+
692
+ Encrypted vaults do not protect a compromised host or secrets already resident
693
+ in process memory. Deterministic transforms reveal when two inputs are equal.
586
694
 
587
695
  ## License
588
696
 
package/SECURITY.md ADDED
@@ -0,0 +1,26 @@
1
+ # Security
2
+
3
+ If you've found a detector bypass, a built-in pattern that can be made to
4
+ backtrack, a vault confidentiality/authentication issue, a placeholder collision,
5
+ or another security impact, report it privately instead of opening a public
6
+ issue. Use synthetic or revoked values in the reproduction.
7
+
8
+ Use GitHub's private advisory form:
9
+ **[Report a vulnerability](https://github.com/umudhasanli/flare-redact/security/advisories/new)**
10
+
11
+ I'll acknowledge within a few days and keep you in the loop on a fix. Once it's
12
+ patched and released, I'm glad to credit you — unless you'd rather stay
13
+ anonymous, which is completely fine.
14
+
15
+ Supported versions: the latest released version on npm. Please make sure you can
16
+ reproduce on that before reporting.
17
+
18
+ ## Security scope
19
+
20
+ Detection is best-effort and cannot prove that input is free of PII. Built-in
21
+ patterns are reviewed and adversarially benchmarked, but custom regular
22
+ expressions are trusted code because JavaScript RegExp has no general linear-time
23
+ guarantee. Encrypted vaults protect persisted maps, not a compromised host,
24
+ untrusted code running in the same process, or keys already present in process
25
+ memory. Restoring a placeholder intentionally reveals its original value, and
26
+ deterministic transforms intentionally reveal equality between matching inputs.
@@ -0,0 +1,23 @@
1
+ import { performance } from 'node:perf_hooks';
2
+ import { scan } from '../dist/index.js';
3
+
4
+ const lengths = [1_000, 10_000, 100_000];
5
+ if (process.env.FLARE_BENCH_INCLUDE_MIB === '1') lengths.push(1_000_000);
6
+ const cases = {
7
+ repeatedAscii: (n) => 'a'.repeat(n) + '!',
8
+ tokenLike: (n) => 'A'.repeat(n) + '=',
9
+ separators: (n) => '1-'.repeat(Math.floor(n / 2)),
10
+ unicode: (n) => '密'.repeat(n),
11
+ };
12
+
13
+ const results = [];
14
+ for (const [name, build] of Object.entries(cases)) {
15
+ for (const length of lengths) {
16
+ const input = build(length);
17
+ const start = performance.now();
18
+ const findings = scan(input);
19
+ results.push({ name, length: input.length, durationMs: performance.now() - start, findings: findings.length });
20
+ }
21
+ }
22
+
23
+ process.stdout.write(JSON.stringify({ schemaVersion: 1, results }, null, 2) + '\n');
@@ -0,0 +1,36 @@
1
+ import { performance } from 'node:perf_hooks';
2
+ import { scan } from '../dist/index.js';
3
+
4
+ const sizes = [1_000, 10_000, 100_000];
5
+ if (process.env.FLARE_BENCH_INCLUDE_MIB === '1') sizes.push(1_000_000);
6
+ const runs = Number(process.env.FLARE_BENCH_RUNS ?? 10);
7
+ const warmups = Number(process.env.FLARE_BENCH_WARMUPS ?? 3);
8
+
9
+ function percentile(values, p) {
10
+ const sorted = [...values].sort((a, b) => a - b);
11
+ return sorted[Math.min(sorted.length - 1, Math.floor(sorted.length * p))];
12
+ }
13
+
14
+ const results = [];
15
+ for (const size of sizes) {
16
+ const fragment = 'INFO request completed status=200 user=alice@example.com duration=12ms\n';
17
+ const input = fragment.repeat(Math.ceil(size / fragment.length)).slice(0, size);
18
+ for (let i = 0; i < warmups; i++) scan(input);
19
+ const samples = [];
20
+ for (let i = 0; i < runs; i++) {
21
+ const start = performance.now();
22
+ scan(input);
23
+ samples.push(performance.now() - start);
24
+ }
25
+ results.push({
26
+ bytes: Buffer.byteLength(input),
27
+ runs,
28
+ p50Ms: percentile(samples, 0.5),
29
+ p95Ms: percentile(samples, 0.95),
30
+ p99Ms: percentile(samples, 0.99),
31
+ throughputMiBPerSecond: (Buffer.byteLength(input) / 1024 / 1024) / (percentile(samples, 0.5) / 1000),
32
+ rssBytes: process.memoryUsage().rss,
33
+ });
34
+ }
35
+
36
+ process.stdout.write(JSON.stringify({ schemaVersion: 1, node: process.version, platform: process.platform, arch: process.arch, results }, null, 2) + '\n');
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
2
  import { main } from '../dist/cli.js';
3
- process.exit(main(process.argv.slice(2)));
3
+ process.exit(await main(process.argv.slice(2)));
package/dist/cli.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare function main(argv: string[]): number;
1
+ export declare function main(argv: string[]): Promise<number>;
2
2
  //# sourceMappingURL=cli.d.ts.map
package/dist/cli.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AA2NA,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAmE3C"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAmRA,wBAAsB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAyH1D"}