flare-redact 1.4.1 → 1.5.1
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 +130 -0
- package/README.md +134 -2
- package/SECURITY.md +36 -0
- package/bin/flare-gateway.mjs +6 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +17 -61
- package/dist/cli.js.map +1 -1
- package/dist/detectors.d.ts +17 -0
- package/dist/detectors.d.ts.map +1 -1
- package/dist/detectors.js.map +1 -1
- package/dist/engine.d.ts +5 -0
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +50 -7
- package/dist/engine.js.map +1 -1
- package/dist/gateway/body.d.ts +90 -0
- package/dist/gateway/body.d.ts.map +1 -0
- package/dist/gateway/body.js +185 -0
- package/dist/gateway/body.js.map +1 -0
- package/dist/gateway/cli.d.ts +26 -0
- package/dist/gateway/cli.d.ts.map +1 -0
- package/dist/gateway/cli.js +237 -0
- package/dist/gateway/cli.js.map +1 -0
- package/dist/gateway/config.d.ts +110 -0
- package/dist/gateway/config.d.ts.map +1 -0
- package/dist/gateway/config.js +212 -0
- package/dist/gateway/config.js.map +1 -0
- package/dist/gateway/index.d.ts +21 -0
- package/dist/gateway/index.d.ts.map +1 -0
- package/dist/gateway/index.js +21 -0
- package/dist/gateway/index.js.map +1 -0
- package/dist/gateway/runtime.d.ts +80 -0
- package/dist/gateway/runtime.d.ts.map +1 -0
- package/dist/gateway/runtime.js +0 -0
- package/dist/gateway/runtime.js.map +1 -0
- package/dist/gateway/server.d.ts +37 -0
- package/dist/gateway/server.d.ts.map +1 -0
- package/dist/gateway/server.js +560 -0
- package/dist/gateway/server.js.map +1 -0
- package/dist/help.d.ts +32 -0
- package/dist/help.d.ts.map +1 -0
- package/dist/help.js +423 -0
- package/dist/help.js.map +1 -0
- package/dist/pack.d.ts +88 -0
- package/dist/pack.d.ts.map +1 -0
- package/dist/pack.js +350 -0
- package/dist/pack.js.map +1 -0
- package/docker/Dockerfile +47 -0
- package/docker/README.md +219 -0
- package/docker/docker-compose.yml +55 -0
- package/docker/flare-gateway.example.json +48 -0
- package/package.json +27 -7
- package/spec/SPEC.md +469 -0
- package/spec/conformance/README.md +60 -0
- package/spec/conformance/cases.json +149 -0
- package/spec/conformance/expected.json +1683 -0
- package/spec/detectors.json +1812 -0
- package/spec/detectors.schema.json +196 -0
package/dist/help.js
ADDED
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CLI's help system.
|
|
3
|
+
*
|
|
4
|
+
* `--help` prints the summary. `help <topic>` prints the part you actually
|
|
5
|
+
* needed, because a flag list tells you a flag exists and nothing about when to
|
|
6
|
+
* reach for it. Every topic here is written from the behaviour in this
|
|
7
|
+
* repository; if one disagrees with the code, the topic is the bug.
|
|
8
|
+
*/
|
|
9
|
+
import { DETECTORS } from './index.js';
|
|
10
|
+
export const HELP = `flare-redact — hide secrets & PII before they hit a log
|
|
11
|
+
|
|
12
|
+
USAGE
|
|
13
|
+
flare-redact [options] [files...] stdin if no files
|
|
14
|
+
flare-redact gateway [options] run the redaction sidecar proxy
|
|
15
|
+
flare-redact help [topic] explain a topic in depth
|
|
16
|
+
|
|
17
|
+
OPTIONS
|
|
18
|
+
--scan list what would be redacted, and why (input unchanged)
|
|
19
|
+
--format <f> scan output: pretty | json | sarif (default: pretty)
|
|
20
|
+
--sarif shorthand for --scan --format sarif
|
|
21
|
+
--summary print a count of findings per detector
|
|
22
|
+
--json parse input as JSON and redact recursively
|
|
23
|
+
--csv parse input as CSV and redact every cell
|
|
24
|
+
--mode <m> mask | label | hash | pseudonym | surrogate
|
|
25
|
+
(fpe is a deprecated alias for pseudonym)
|
|
26
|
+
--secret-env <n> read the transform key from env var <n>
|
|
27
|
+
(default: FLARE_REDACT_SECRET)
|
|
28
|
+
--hash-salt <s> deprecated; prefer --secret-env
|
|
29
|
+
--min-confidence <n>
|
|
30
|
+
drop findings below this confidence (0-1)
|
|
31
|
+
--refine-confidence
|
|
32
|
+
use the learned classifier to refine confidence for
|
|
33
|
+
generic detectors (fewer false positives on UUIDs,
|
|
34
|
+
hashes, and slugs); pairs with --min-confidence
|
|
35
|
+
--include-values include raw matched values in --scan output
|
|
36
|
+
(unsafe for logs and reports)
|
|
37
|
+
--only <ids> use only these detectors (comma-separated)
|
|
38
|
+
--enable <ids> turn on extra detectors (e.g. ipv4,high_entropy)
|
|
39
|
+
--disable <ids> turn off detectors (e.g. email)
|
|
40
|
+
--mask <str> replace every secret with this string
|
|
41
|
+
--allow <vals> never redact these exact values (comma-separated)
|
|
42
|
+
--exclude <glob> skip matching paths during directory scans (repeatable)
|
|
43
|
+
--max-file-size <size>
|
|
44
|
+
largest directory-discovered file to scan (default: 1mb)
|
|
45
|
+
accepts bytes or kb/mb/gb suffixes
|
|
46
|
+
--no-default-excludes
|
|
47
|
+
also walk .git, .hg, .svn, node_modules, and vendor
|
|
48
|
+
--term <word> also catch this exact word/phrase (repeatable)
|
|
49
|
+
--terms <file> also catch every word/phrase in this file (one per line)
|
|
50
|
+
--vault <file> reversible: write an AES-GCM encrypted map to <file>
|
|
51
|
+
--restore <file> restore using an encrypted map written by --vault
|
|
52
|
+
--vault-password-env <n>
|
|
53
|
+
vault password env var (default: FLARE_REDACT_VAULT_PASSWORD)
|
|
54
|
+
--allow-plaintext-vault
|
|
55
|
+
explicitly allow reading a legacy plaintext vault
|
|
56
|
+
--list show all detectors and exit
|
|
57
|
+
-h, --help show this help
|
|
58
|
+
-v, --version show version
|
|
59
|
+
|
|
60
|
+
SUBCOMMANDS
|
|
61
|
+
gateway run a reverse proxy that redacts request bodies and
|
|
62
|
+
restores the originals in the reply — no code changes
|
|
63
|
+
in the calling application. See: flare-redact gateway help
|
|
64
|
+
help explain a topic. Run 'flare-redact help topics' for the
|
|
65
|
+
index, or 'flare-redact help <detector>' for one detector.
|
|
66
|
+
|
|
67
|
+
EXAMPLES
|
|
68
|
+
tail -f app.log | flare-redact
|
|
69
|
+
flare-redact --scan config.env
|
|
70
|
+
flare-redact --scan .
|
|
71
|
+
flare-redact --scan . --exclude 'fixtures/**' --max-file-size 2mb
|
|
72
|
+
flare-redact --scan --format json .env app.log
|
|
73
|
+
flare-redact --sarif .env > flare-redact.sarif
|
|
74
|
+
flare-redact --json --mode hash < event.json
|
|
75
|
+
flare-redact --enable high_entropy,ipv4 < app.log
|
|
76
|
+
flare-redact --scan --enable high_entropy --refine-confidence --min-confidence 0.5 app.log
|
|
77
|
+
|
|
78
|
+
Stuck? 'flare-redact help topics' lists everything this help can explain.
|
|
79
|
+
`;
|
|
80
|
+
const TOPIC_LIST = [
|
|
81
|
+
{
|
|
82
|
+
name: 'detectors',
|
|
83
|
+
summary: 'choosing what gets redacted, by id or tag',
|
|
84
|
+
body: `DETECTORS — choosing what gets redacted
|
|
85
|
+
|
|
86
|
+
'flare-redact --list' prints every detector: a filled circle is on by default, a
|
|
87
|
+
hollow one is off until you ask for it.
|
|
88
|
+
|
|
89
|
+
Three flags select, and they are applied in that order:
|
|
90
|
+
|
|
91
|
+
--only <ids> ignore the defaults; run exactly these
|
|
92
|
+
--enable <ids> add to the defaults
|
|
93
|
+
--disable <ids> remove from the result
|
|
94
|
+
|
|
95
|
+
Each accepts detector ids and tags interchangeably, comma-separated. Tags let you
|
|
96
|
+
say what you mean without listing thirty ids:
|
|
97
|
+
|
|
98
|
+
secret, pii, finance, network, crypto, email, vehicle, contextual, obfuscated
|
|
99
|
+
and country tags: us, gb, de, fr, es, it, nl, pl, tr, ca, au, br, in, cn, jp, id
|
|
100
|
+
|
|
101
|
+
flare-redact --enable pii app.log every PII detector
|
|
102
|
+
flare-redact --only secret .env secrets only, nothing else
|
|
103
|
+
flare-redact --disable email,ipv4 app.log defaults minus two
|
|
104
|
+
|
|
105
|
+
Contextual detectors (names, addresses, dates of birth) are off by default and
|
|
106
|
+
tagged 'contextual'. They read surrounding words to decide, so they are the ones
|
|
107
|
+
most worth reviewing with --scan before you turn them on in production.
|
|
108
|
+
|
|
109
|
+
'flare-redact help <detector-id>' explains a single detector.
|
|
110
|
+
|
|
111
|
+
Custom values that no detector knows about:
|
|
112
|
+
|
|
113
|
+
--term <word> catch this exact word or phrase, repeatable
|
|
114
|
+
--terms <file> catch every line of a file
|
|
115
|
+
--allow <vals> never redact these exact values`,
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
name: 'modes',
|
|
119
|
+
summary: 'mask, label, hash, pseudonym, surrogate — and which to pick',
|
|
120
|
+
body: `MODES — what replaces a matched value
|
|
121
|
+
|
|
122
|
+
--mode mask the default. Partial, shape-preserving: a***@***, sk-***
|
|
123
|
+
--mode label the detector's name: [EMAIL], [OPENAI_KEY]
|
|
124
|
+
--mode hash keyed HMAC-SHA-256. Same input, same output, so you can
|
|
125
|
+
still count and join on it. Requires a key.
|
|
126
|
+
--mode pseudonym a fake value of the same shape. Requires a key.
|
|
127
|
+
--mode surrogate a typed synthetic value — a card number that still passes
|
|
128
|
+
Luhn, a date that is still a date. Requires a key.
|
|
129
|
+
|
|
130
|
+
--mask <str> ignore all of the above and write a fixed string
|
|
131
|
+
|
|
132
|
+
hash, pseudonym and surrogate are keyed, and the key never goes on the command
|
|
133
|
+
line. Put it in an environment variable:
|
|
134
|
+
|
|
135
|
+
export FLARE_REDACT_SECRET='…'
|
|
136
|
+
flare-redact --mode hash app.log
|
|
137
|
+
|
|
138
|
+
Use --secret-env <NAME> to read a different variable. --hash-salt still works and
|
|
139
|
+
is deprecated; it names the same thing badly.
|
|
140
|
+
|
|
141
|
+
'fpe' is accepted as an alias for 'pseudonym' and warns. It was the wrong word:
|
|
142
|
+
none of this is format-preserving encryption, and nothing here is reversible
|
|
143
|
+
without a vault — see 'flare-redact help vault'.`,
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
name: 'vault',
|
|
147
|
+
summary: 'reversible redaction: get the originals back',
|
|
148
|
+
body: `VAULT — redaction you can undo
|
|
149
|
+
|
|
150
|
+
A mode replaces a value and forgets it. A vault replaces it with a stable
|
|
151
|
+
placeholder and remembers the mapping, so the same secret is always the same
|
|
152
|
+
placeholder and the text can be turned back into the original later.
|
|
153
|
+
|
|
154
|
+
export FLARE_REDACT_VAULT_PASSWORD='…'
|
|
155
|
+
flare-redact --vault map.json < app.log > safe.log # redact, save the map
|
|
156
|
+
flare-redact --restore map.json < safe.log # put the originals back
|
|
157
|
+
|
|
158
|
+
The map on disk is not plaintext: PBKDF2-SHA-256 derives a key from the password
|
|
159
|
+
and the file is an authenticated AES-256-GCM envelope. Lose the password and the
|
|
160
|
+
map is gone. The password comes from an environment variable, never a flag —
|
|
161
|
+
use --vault-password-env <NAME> to point at a different one.
|
|
162
|
+
|
|
163
|
+
Placeholders are opaque 96-bit random tokens by default, so a placeholder leaks
|
|
164
|
+
nothing about the value behind it.
|
|
165
|
+
|
|
166
|
+
A vault written by an older version in plaintext still loads, but only if you say
|
|
167
|
+
so explicitly with --allow-plaintext-vault.
|
|
168
|
+
|
|
169
|
+
In code this is createVault() / restore(), and the gateway uses one per request
|
|
170
|
+
so placeholders never cross between callers.`,
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
name: 'scan',
|
|
174
|
+
summary: 'find secrets without changing anything, and fail CI on them',
|
|
175
|
+
body: `SCAN — report, do not rewrite
|
|
176
|
+
|
|
177
|
+
flare-redact --scan config.env what would be redacted, and why
|
|
178
|
+
flare-redact --scan . walk a whole project
|
|
179
|
+
flare-redact --summary app.log just the counts, per detector
|
|
180
|
+
|
|
181
|
+
--scan never prints the matched value unless you pass --include-values, which is
|
|
182
|
+
unsafe for anything you keep. The report carries the detector, the reason, the
|
|
183
|
+
file and the position.
|
|
184
|
+
|
|
185
|
+
Output formats:
|
|
186
|
+
|
|
187
|
+
--format pretty human reading, the default
|
|
188
|
+
--format json machine reading
|
|
189
|
+
--format sarif GitHub code scanning and anything else that speaks SARIF
|
|
190
|
+
--sarif shorthand for --scan --format sarif
|
|
191
|
+
|
|
192
|
+
Exit codes make it a CI gate:
|
|
193
|
+
|
|
194
|
+
0 nothing found
|
|
195
|
+
1 findings (scan mode only)
|
|
196
|
+
2 the command itself failed — bad flag, unreadable file, invalid JSON
|
|
197
|
+
|
|
198
|
+
# fail the build if a secret is committed
|
|
199
|
+
npx --yes flare-redact --scan . --exclude package-lock.json
|
|
200
|
+
|
|
201
|
+
Too noisy? Generic detectors like high_entropy match anything that looks random.
|
|
202
|
+
--refine-confidence runs the learned classifier over them and --min-confidence
|
|
203
|
+
drops the weak ones:
|
|
204
|
+
|
|
205
|
+
flare-redact --scan --enable high_entropy --refine-confidence --min-confidence 0.5 .`,
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
name: 'files',
|
|
209
|
+
summary: 'scanning directories: what is walked, what is skipped',
|
|
210
|
+
body: `FILES — what a directory scan actually reads
|
|
211
|
+
|
|
212
|
+
Give --scan a directory and it walks it. Three things are skipped without being
|
|
213
|
+
asked, because scanning them is noise or a hazard:
|
|
214
|
+
|
|
215
|
+
- .git, .hg, .svn, node_modules and vendor. Pass --no-default-excludes to walk
|
|
216
|
+
them anyway.
|
|
217
|
+
- files that look binary
|
|
218
|
+
- files larger than --max-file-size (default 1mb; accepts 512kb, 2mb, 1gb)
|
|
219
|
+
- symlinks are not followed
|
|
220
|
+
|
|
221
|
+
--exclude <glob> skip more paths, repeatable:
|
|
222
|
+
|
|
223
|
+
flare-redact --scan . --exclude 'fixtures/**' --exclude '*.min.js'
|
|
224
|
+
|
|
225
|
+
The json report counts what was skipped and why, so a scan that finds nothing
|
|
226
|
+
cannot quietly mean a scan that read nothing.`,
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
name: 'gateway',
|
|
230
|
+
summary: 'the sidecar proxy: redact without touching application code',
|
|
231
|
+
body: `GATEWAY — redaction without a code change
|
|
232
|
+
|
|
233
|
+
The library needs you to call it. The gateway does not: it is a reverse proxy
|
|
234
|
+
that redacts request bodies on the way out and restores the originals in the
|
|
235
|
+
reply, so an application integrates by changing one base URL.
|
|
236
|
+
|
|
237
|
+
flare-redact gateway --upstream https://api.openai.com --enable pii
|
|
238
|
+
|
|
239
|
+
# then, in the application — nothing else changes
|
|
240
|
+
export OPENAI_BASE_URL=http://127.0.0.1:8787/v1
|
|
241
|
+
|
|
242
|
+
Streamed responses are restored incrementally, so a placeholder split across two
|
|
243
|
+
SSE frames still comes back whole.
|
|
244
|
+
|
|
245
|
+
It is also a redaction service for languages without a native engine:
|
|
246
|
+
POST /v1/redact, POST /v1/scan, GET /v1/detectors and server-side /v1/sessions,
|
|
247
|
+
plus /healthz, /readyz and Prometheus /metrics. Those are the only paths the
|
|
248
|
+
gateway answers itself — everything else under /v1 is proxied to your upstream.
|
|
249
|
+
|
|
250
|
+
A container image ships in the repository under docker/.
|
|
251
|
+
|
|
252
|
+
Full flag list: flare-redact gateway help`,
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
name: 'library',
|
|
256
|
+
summary: 'using it from JavaScript and TypeScript',
|
|
257
|
+
body: `LIBRARY — the JavaScript and TypeScript API
|
|
258
|
+
|
|
259
|
+
import { redact, scan, compilePolicy, createVault } from 'flare-redact';
|
|
260
|
+
|
|
261
|
+
redact('mail ada@example.com') // 'mail a***@***'
|
|
262
|
+
scan(value) // findings, no rewriting
|
|
263
|
+
compilePolicy(options) // resolve options once, reuse everywhere
|
|
264
|
+
|
|
265
|
+
redact() takes any value, not just strings: objects, arrays and nested
|
|
266
|
+
structures are walked and only the leaves are rewritten.
|
|
267
|
+
|
|
268
|
+
Adapters live behind subpath imports, so you pay for what you import:
|
|
269
|
+
|
|
270
|
+
flare-redact/pino flare-redact/winston log transports
|
|
271
|
+
flare-redact/http flare-redact/fetch HTTP layers
|
|
272
|
+
flare-redact/llm flare-redact/session prompts and conversations
|
|
273
|
+
flare-redact/tool MCP and multi-tool agent boundaries
|
|
274
|
+
flare-redact/stream flare-redact/csv streams and tabular data
|
|
275
|
+
flare-redact/middleware framework middleware
|
|
276
|
+
flare-redact/ml the learned confidence classifier
|
|
277
|
+
flare-redact/pack load an FRS-1 detector pack as ordinary detectors
|
|
278
|
+
flare-redact/gateway embed the sidecar in your own process
|
|
279
|
+
|
|
280
|
+
The package has no runtime dependencies. Node 20 or newer; Bun and Deno are
|
|
281
|
+
covered by CI.`,
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
name: 'sdks',
|
|
285
|
+
summary: 'the Python, Go and Rust engines — installed separately',
|
|
286
|
+
body: `SDKS — the same redactor in four languages
|
|
287
|
+
|
|
288
|
+
Python, Go and Rust have their own native engines. They are separate packages:
|
|
289
|
+
installing flare-redact from npm gives you the JavaScript engine and nothing
|
|
290
|
+
else, and it pulls no dependencies of any kind.
|
|
291
|
+
|
|
292
|
+
Node npm install flare-redact
|
|
293
|
+
|
|
294
|
+
Go go get github.com/flare-collection/flare-redact/sdk/go
|
|
295
|
+
|
|
296
|
+
Python pip install "flare-redact @ \\
|
|
297
|
+
git+https://github.com/flare-collection/flare-redact@v1.5.1#subdirectory=sdk/python"
|
|
298
|
+
|
|
299
|
+
Rust flare-redact = { git = "https://github.com/flare-collection/flare-redact", \\
|
|
300
|
+
tag = "v1.5.1" }
|
|
301
|
+
|
|
302
|
+
The Python and Rust engines are not on PyPI or crates.io yet, so they install
|
|
303
|
+
from the repository. The commands above are the ones that work today.
|
|
304
|
+
|
|
305
|
+
They are not ports that drift. All four implement FRS-1, the specification in
|
|
306
|
+
spec/SPEC.md, and all four run the same conformance corpus in spec/conformance/
|
|
307
|
+
in their own test suites — so the same input and the same options produce the
|
|
308
|
+
same output whichever engine you use.
|
|
309
|
+
|
|
310
|
+
If you cannot add a dependency at all, the gateway gives every language an HTTP
|
|
311
|
+
endpoint instead: flare-redact help gateway`,
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
name: 'env',
|
|
315
|
+
summary: 'every environment variable this tool reads',
|
|
316
|
+
body: `ENVIRONMENT
|
|
317
|
+
|
|
318
|
+
CLI:
|
|
319
|
+
FLARE_REDACT_SECRET key for hash, pseudonym and surrogate modes
|
|
320
|
+
(override the name with --secret-env)
|
|
321
|
+
FLARE_REDACT_VAULT_PASSWORD password for an encrypted vault file
|
|
322
|
+
(override the name with --vault-password-env)
|
|
323
|
+
|
|
324
|
+
Gateway:
|
|
325
|
+
FLARE_UPSTREAM origin to forward to
|
|
326
|
+
FLARE_GATEWAY_HOST bind address (default 127.0.0.1)
|
|
327
|
+
FLARE_GATEWAY_PORT bind port (default 8787)
|
|
328
|
+
FLARE_GATEWAY_TOKEN bearer token required by the /v1 API
|
|
329
|
+
FLARE_GATEWAY_MAX_BODY_BYTES request body cap
|
|
330
|
+
FLARE_GATEWAY_TIMEOUT_MS upstream timeout
|
|
331
|
+
FLARE_GATEWAY_SESSION_TTL_MS how long a server-side vault lives
|
|
332
|
+
FLARE_GATEWAY_LOG silent | info | debug
|
|
333
|
+
FLARE_REDACT_ONLY / _ENABLE / _DISABLE / _MODE / _SECRET
|
|
334
|
+
the policy, for containers
|
|
335
|
+
|
|
336
|
+
Secrets are read from the environment and never from flags, because a flag ends
|
|
337
|
+
up in shell history and in the process list.`,
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
name: 'exit-codes',
|
|
341
|
+
summary: 'what the process returns, and when',
|
|
342
|
+
body: `EXIT CODES
|
|
343
|
+
|
|
344
|
+
0 success. In --scan, it also means nothing was found.
|
|
345
|
+
1 --scan found at least one thing. This is what fails a CI job.
|
|
346
|
+
2 the command failed: an unknown flag, a file that could not be read,
|
|
347
|
+
input that was not valid JSON, a bad vault password.
|
|
348
|
+
|
|
349
|
+
Redaction that finds nothing still exits 0 and prints the input unchanged, so
|
|
350
|
+
flare-redact is safe to leave in a pipeline permanently.`,
|
|
351
|
+
},
|
|
352
|
+
];
|
|
353
|
+
export const TOPICS = TOPIC_LIST;
|
|
354
|
+
/** The topic index, as printed by `help topics`. */
|
|
355
|
+
export function topicIndex() {
|
|
356
|
+
const width = Math.max(...TOPICS.map((topic) => topic.name.length));
|
|
357
|
+
const lines = TOPICS.map((topic) => ` ${topic.name.padEnd(width)} ${topic.summary}`);
|
|
358
|
+
return `HELP TOPICS
|
|
359
|
+
|
|
360
|
+
${lines.join('\n')}
|
|
361
|
+
|
|
362
|
+
flare-redact help <topic> read one of these
|
|
363
|
+
flare-redact help <detector> explain a single detector, e.g. 'help email'
|
|
364
|
+
flare-redact --list every detector, with defaults marked
|
|
365
|
+
`;
|
|
366
|
+
}
|
|
367
|
+
/** One detector, rendered as its own help page. */
|
|
368
|
+
function detectorHelp(id) {
|
|
369
|
+
const detector = DETECTORS.find((candidate) => candidate.id === id);
|
|
370
|
+
if (!detector)
|
|
371
|
+
return undefined;
|
|
372
|
+
const tags = detector.tags?.length ? detector.tags.join(', ') : 'none';
|
|
373
|
+
const state = detector.default
|
|
374
|
+
? 'on by default'
|
|
375
|
+
: `off by default — turn it on with --enable ${detector.id}`;
|
|
376
|
+
return `DETECTOR ${detector.id}
|
|
377
|
+
|
|
378
|
+
${detector.label}
|
|
379
|
+
|
|
380
|
+
${detector.why}
|
|
381
|
+
|
|
382
|
+
State ${state}
|
|
383
|
+
Tags ${tags}
|
|
384
|
+
|
|
385
|
+
flare-redact --only ${detector.id} <file> run just this one
|
|
386
|
+
flare-redact --disable ${detector.id} <file> run everything except this one
|
|
387
|
+
`;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Suggest the nearest topic or detector for something we do not recognise.
|
|
391
|
+
* Prefix and substring matching only — a typo table would be more machinery
|
|
392
|
+
* than the problem deserves.
|
|
393
|
+
*/
|
|
394
|
+
function nearest(query) {
|
|
395
|
+
const needle = query.toLowerCase();
|
|
396
|
+
const names = [...TOPICS.map((topic) => topic.name), ...DETECTORS.map((detector) => detector.id)];
|
|
397
|
+
// Either direction: "vaults" should find "vault", and "vau" should too.
|
|
398
|
+
return names.filter((name) => name.includes(needle) || needle.includes(name)).slice(0, 5);
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Resolve `help [topic]`. Returns the text and the exit code rather than
|
|
402
|
+
* writing, so the caller decides between stdout and stderr and the tests can
|
|
403
|
+
* read it back.
|
|
404
|
+
*/
|
|
405
|
+
export function renderHelp(topic) {
|
|
406
|
+
if (!topic)
|
|
407
|
+
return { text: HELP, code: 0 };
|
|
408
|
+
const name = topic.toLowerCase();
|
|
409
|
+
if (name === 'topics' || name === 'help')
|
|
410
|
+
return { text: topicIndex(), code: 0 };
|
|
411
|
+
const found = TOPICS.find((candidate) => candidate.name === name);
|
|
412
|
+
if (found)
|
|
413
|
+
return { text: `${found.body}\n`, code: 0 };
|
|
414
|
+
const detector = detectorHelp(topic);
|
|
415
|
+
if (detector)
|
|
416
|
+
return { text: detector, code: 0 };
|
|
417
|
+
const suggestions = nearest(name);
|
|
418
|
+
const hint = suggestions.length
|
|
419
|
+
? `Did you mean: ${suggestions.join(', ')}?\n\n`
|
|
420
|
+
: '';
|
|
421
|
+
return { text: `No help for "${topic}".\n\n${hint}${topicIndex()}`, code: 2 };
|
|
422
|
+
}
|
|
423
|
+
//# sourceMappingURL=help.js.map
|
package/dist/help.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"help.js","sourceRoot":"","sources":["../src/help.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAWvC,MAAM,CAAC,MAAM,IAAI,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqEnB,CAAC;AAEF,MAAM,UAAU,GAAyB;IACvC;QACE,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,2CAA2C;QACpD,IAAI,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oDA+B0C;KACjD;IACD;QACE,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,6DAA6D;QACtE,IAAI,EAAE;;;;;;;;;;;;;;;;;;;;;;;iDAuBuC;KAC9C;IACD;QACE,IAAI,EAAE,OAAO;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 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FRS-1 detector packs.
|
|
3
|
+
*
|
|
4
|
+
* A pack is a JSON description of a detector set, written in a restricted
|
|
5
|
+
* pattern subset that compiles to the same automaton in JavaScript, Python, Go
|
|
6
|
+
* and Rust. Loading one here turns it into ordinary `Detector` objects, so a
|
|
7
|
+
* pack behaves exactly like a built-in detector — including in overlap
|
|
8
|
+
* resolution, `enable`/`disable`, vaults and every adapter.
|
|
9
|
+
*
|
|
10
|
+
* import { loadPack } from 'flare-redact/pack';
|
|
11
|
+
* import { redact } from 'flare-redact';
|
|
12
|
+
*
|
|
13
|
+
* const pack = loadPack(JSON.parse(await readFile('detectors/acme.json', 'utf8')));
|
|
14
|
+
* redact(text, { detectors: pack.detectors });
|
|
15
|
+
*
|
|
16
|
+
* The loader is strict on purpose. A pack that uses a construct this engine
|
|
17
|
+
* cannot execute exactly as `spec/SPEC.md` describes — a lookahead, a `\d` whose
|
|
18
|
+
* meaning differs between languages, a checksum this build does not know — fails
|
|
19
|
+
* to load. Failing open is how a redactor leaks.
|
|
20
|
+
*/
|
|
21
|
+
import { type Detector } from './detectors.js';
|
|
22
|
+
import { FlareRedactError, type Risk } from './engine.js';
|
|
23
|
+
export declare const SPEC_REVISION = "FRS-1";
|
|
24
|
+
export interface PackDocument {
|
|
25
|
+
spec: string;
|
|
26
|
+
id: string;
|
|
27
|
+
version: string;
|
|
28
|
+
title?: string;
|
|
29
|
+
description?: string;
|
|
30
|
+
license?: string;
|
|
31
|
+
confidenceModel?: {
|
|
32
|
+
version: number;
|
|
33
|
+
features: string[];
|
|
34
|
+
weights: number[];
|
|
35
|
+
bias: number;
|
|
36
|
+
};
|
|
37
|
+
detectors: PackDetector[];
|
|
38
|
+
}
|
|
39
|
+
export interface PackDetector {
|
|
40
|
+
id: string;
|
|
41
|
+
label: string;
|
|
42
|
+
why: string;
|
|
43
|
+
pattern: string;
|
|
44
|
+
flags?: string;
|
|
45
|
+
capture?: number;
|
|
46
|
+
boundary?: {
|
|
47
|
+
before?: string;
|
|
48
|
+
after?: string;
|
|
49
|
+
};
|
|
50
|
+
reject?: string[];
|
|
51
|
+
validators?: Array<Record<string, unknown> & {
|
|
52
|
+
name: string;
|
|
53
|
+
}>;
|
|
54
|
+
mask: Record<string, unknown> & {
|
|
55
|
+
type: string;
|
|
56
|
+
};
|
|
57
|
+
default: boolean;
|
|
58
|
+
tags?: string[];
|
|
59
|
+
risk: Risk;
|
|
60
|
+
priority?: number;
|
|
61
|
+
confidence: number;
|
|
62
|
+
refine?: boolean;
|
|
63
|
+
prefilter?: string[];
|
|
64
|
+
context?: {
|
|
65
|
+
positive?: string;
|
|
66
|
+
negative?: string;
|
|
67
|
+
window?: number;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export interface Pack {
|
|
71
|
+
id: string;
|
|
72
|
+
version: string;
|
|
73
|
+
title: string;
|
|
74
|
+
detectors: Detector[];
|
|
75
|
+
byId: Map<string, Detector>;
|
|
76
|
+
confidenceModel?: PackDocument['confidenceModel'];
|
|
77
|
+
}
|
|
78
|
+
export declare class PackError extends FlareRedactError {
|
|
79
|
+
constructor(message: string);
|
|
80
|
+
}
|
|
81
|
+
/** Neighbour characters a captured span may not touch. See `spec/SPEC.md` §3.1. */
|
|
82
|
+
export declare const BOUNDARY_CLASSES: Readonly<Record<string, ReadonlySet<string>>>;
|
|
83
|
+
/**
|
|
84
|
+
* Compile an FRS-1 pack document into detectors this engine can run.
|
|
85
|
+
* Throws {@link PackError} for anything it cannot honour exactly.
|
|
86
|
+
*/
|
|
87
|
+
export declare function loadPack(document: PackDocument): Pack;
|
|
88
|
+
//# sourceMappingURL=pack.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pack.d.ts","sourceRoot":"","sources":["../src/pack.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAKL,KAAK,QAAQ,EACd,MAAM,gBAAgB,CAA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