flare-redact 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +130 -9
- package/dist/cli.js +2 -2
- package/dist/detectors.d.ts +7 -0
- package/dist/detectors.d.ts.map +1 -1
- package/dist/detectors.js +34 -0
- package/dist/detectors.js.map +1 -1
- package/dist/engine.d.ts +36 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +105 -0
- package/dist/engine.js.map +1 -0
- package/dist/http.d.ts +34 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +36 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +16 -26
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -104
- package/dist/index.js.map +1 -1
- package/dist/llm.d.ts +57 -0
- package/dist/llm.d.ts.map +1 -0
- package/dist/llm.js +141 -0
- package/dist/llm.js.map +1 -0
- package/dist/pino.d.ts +18 -0
- package/dist/pino.d.ts.map +1 -0
- package/dist/pino.js +22 -0
- package/dist/pino.js.map +1 -0
- package/dist/vault.d.ts +25 -0
- package/dist/vault.d.ts.map +1 -0
- package/dist/vault.js +103 -0
- package/dist/vault.js.map +1 -0
- package/dist/winston.d.ts +16 -0
- package/dist/winston.d.ts.map +1 -0
- package/dist/winston.js +23 -0
- package/dist/winston.js.map +1 -0
- package/package.json +32 -3
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<h1 align="center">flare-redact</h1>
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
|
-
<b>Hide secrets & PII in logs and text — before they leak.</b>
|
|
8
|
+
<b>Hide secrets & PII in logs, prompts, and text — before they leak.</b>
|
|
9
9
|
</p>
|
|
10
10
|
|
|
11
11
|
<p align="center">
|
|
@@ -37,13 +37,21 @@ redact('User alice@corp.com paid with 4242 4242 4242 4242, token ghp_' + 'a'.rep
|
|
|
37
37
|
|
|
38
38
|
Nothing to configure. No list of field paths to maintain. No native build step.
|
|
39
39
|
|
|
40
|
+
> **The same problem now has a new address: your LLM calls.** Wrap your OpenAI or
|
|
41
|
+
> Anthropic client and secrets are stripped from every prompt and restored in the
|
|
42
|
+
> reply — the model never sees the real data, your app still gets the right answer.
|
|
43
|
+
> [Jump to it ↓](#redact-prompts-before-they-reach-an-llm)
|
|
44
|
+
|
|
40
45
|
## Contents
|
|
41
46
|
|
|
42
47
|
- [Install](#install)
|
|
43
48
|
- [Redact anything](#redact-anything)
|
|
44
|
-
- [
|
|
49
|
+
- [Redact prompts before they reach an LLM](#redact-prompts-before-they-reach-an-llm)
|
|
50
|
+
- [Ways to hide a value](#ways-to-hide-a-value)
|
|
51
|
+
- [Reversible redaction](#reversible-redaction)
|
|
45
52
|
- [See what leaks, and why](#see-what-leaks-and-why)
|
|
46
53
|
- [Guard your logger in one line](#guard-your-logger-in-one-line)
|
|
54
|
+
- [One policy, everywhere](#one-policy-everywhere)
|
|
47
55
|
- [Streams](#streams)
|
|
48
56
|
- [Fail a build when a secret sneaks in](#fail-a-build-when-a-secret-sneaks-in)
|
|
49
57
|
- [CLI](#cli)
|
|
@@ -83,7 +91,37 @@ redact({
|
|
|
83
91
|
// }
|
|
84
92
|
```
|
|
85
93
|
|
|
86
|
-
##
|
|
94
|
+
## Redact prompts before they reach an LLM
|
|
95
|
+
|
|
96
|
+
Your app sends user data to OpenAI or Anthropic. Somewhere in that prompt is a
|
|
97
|
+
customer's email, an API key, or a card number — and now it's left your systems.
|
|
98
|
+
Wrap the client once, and secrets are stripped from every prompt and put back in
|
|
99
|
+
the reply. The model never sees the real values; your code still gets the right
|
|
100
|
+
answer.
|
|
101
|
+
|
|
102
|
+
```js
|
|
103
|
+
import { wrapOpenAI } from 'flare-redact/llm';
|
|
104
|
+
|
|
105
|
+
const openai = wrapOpenAI(new OpenAI());
|
|
106
|
+
|
|
107
|
+
const res = await openai.chat.completions.create({
|
|
108
|
+
model: 'gpt-4o',
|
|
109
|
+
messages: [{ role: 'user', content: 'Email the invoice to alice@corp.com, card 4242 4242 4242 4242' }],
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
your app sends → Email the invoice to alice@corp.com, card 4242 4242 4242 4242
|
|
115
|
+
the model sees → Email the invoice to [EMAIL_1], card [CREDIT_CARD_1]
|
|
116
|
+
your app gets → Sent to alice@corp.com. Card 4242 4242 4242 4242 wasn't stored.
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
`wrapAnthropic` does the same for `messages.create`, including the system prompt.
|
|
120
|
+
Both handle streaming — placeholders are restored even when one is split across
|
|
121
|
+
chunks. There's a `redactPrompt(text)` too if you'd rather hold the vault
|
|
122
|
+
yourself.
|
|
123
|
+
|
|
124
|
+
## Ways to hide a value
|
|
87
125
|
|
|
88
126
|
Pick a `mode` depending on whether you still need to *reason* about the data
|
|
89
127
|
after it's hidden.
|
|
@@ -91,13 +129,16 @@ after it's hidden.
|
|
|
91
129
|
```js
|
|
92
130
|
redact('bob@corp.com', { mode: 'mask' }); // 'b***@***' (default)
|
|
93
131
|
redact('bob@corp.com', { mode: 'label' }); // '[REDACTED:email]'
|
|
94
|
-
redact('bob@corp.com', { mode: 'hash' }); // 'email_f63d8d56'
|
|
132
|
+
redact('bob@corp.com', { mode: 'hash' }); // 'email_f63d8d56' (deterministic)
|
|
133
|
+
redact('bob@corp.com', { mode: 'fpe' }); // 'kqz@rwmp.dnu' (keeps the shape)
|
|
95
134
|
```
|
|
96
135
|
|
|
97
136
|
`hash` is the useful one for support work: the same input always hashes to the
|
|
98
137
|
same token, so you can still tell that two log lines came from the same user —
|
|
99
|
-
without ever storing who that user is.
|
|
100
|
-
|
|
138
|
+
without ever storing who that user is. `fpe` (format-preserving) keeps the
|
|
139
|
+
*shape* — an email stays email-shaped, a card stays card-shaped — which is what
|
|
140
|
+
you want for realistic-but-safe test data. Both are deterministic; add `hashSalt`
|
|
141
|
+
to make the mapping per-service.
|
|
101
142
|
|
|
102
143
|
Or replace everything with one fixed string:
|
|
103
144
|
|
|
@@ -106,6 +147,27 @@ redact(payload, { mask: '█' });
|
|
|
106
147
|
redact(payload, { mask: ({ detector }) => `<${detector.id}>` });
|
|
107
148
|
```
|
|
108
149
|
|
|
150
|
+
## Reversible redaction
|
|
151
|
+
|
|
152
|
+
When you need the originals back — the LLM case above, or handing data to a
|
|
153
|
+
system you don't trust and getting it back — use a vault. It swaps each secret
|
|
154
|
+
for a stable placeholder and remembers the mapping.
|
|
155
|
+
|
|
156
|
+
```js
|
|
157
|
+
import { createVault } from 'flare-redact';
|
|
158
|
+
|
|
159
|
+
const vault = createVault();
|
|
160
|
+
const safe = vault.redact('charge bob@corp.com on card 4242 4242 4242 4242');
|
|
161
|
+
// 'charge [EMAIL_1] on card [CREDIT_CARD_1]'
|
|
162
|
+
|
|
163
|
+
vault.restore(safe);
|
|
164
|
+
// 'charge bob@corp.com on card 4242 4242 4242 4242'
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
The same value always gets the same placeholder, so references survive the round
|
|
168
|
+
trip. Works on objects too, and `restore()` also takes a plain placeholder→value
|
|
169
|
+
map if you persisted one.
|
|
170
|
+
|
|
109
171
|
## See what leaks, and why
|
|
110
172
|
|
|
111
173
|
`scan()` finds secrets without changing the input, and explains every hit in
|
|
@@ -157,6 +219,49 @@ const safe = createRedactor({ enable: ['high_entropy'] });
|
|
|
157
219
|
logger.info(safe.redact({ event: 'checkout', user }));
|
|
158
220
|
```
|
|
159
221
|
|
|
222
|
+
## One policy, everywhere
|
|
223
|
+
|
|
224
|
+
Define what "sensitive" means once, and apply it at every layer — your app, your
|
|
225
|
+
logger, your HTTP boundary, your LLM calls. Every adapter takes the same options
|
|
226
|
+
object, so a secret is masked the same way across the whole system.
|
|
227
|
+
|
|
228
|
+
```js
|
|
229
|
+
import { definePolicy } from 'flare-redact';
|
|
230
|
+
const policy = { enable: ['high_entropy'], allow: ['status@acme.com'] };
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
**pino** — reads the values, not a list of field paths you have to maintain:
|
|
234
|
+
|
|
235
|
+
```js
|
|
236
|
+
import pino from 'pino';
|
|
237
|
+
import { pinoRedact } from 'flare-redact/pino';
|
|
238
|
+
|
|
239
|
+
const log = pino(pinoRedact(policy));
|
|
240
|
+
log.info({ user: 'bob@corp.com' }); // → {"user":"b***@***"}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
**winston** — a format that redacts every field, symbol metadata left intact:
|
|
244
|
+
|
|
245
|
+
```js
|
|
246
|
+
import winston from 'winston';
|
|
247
|
+
import { winstonRedact } from 'flare-redact/winston';
|
|
248
|
+
|
|
249
|
+
winston.format.combine(winston.format(winstonRedact(policy))(), winston.format.json());
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
**HTTP** — a safe-to-log snapshot of a request; the live request is untouched:
|
|
253
|
+
|
|
254
|
+
```js
|
|
255
|
+
import { httpRedactor } from 'flare-redact/http';
|
|
256
|
+
|
|
257
|
+
app.use(httpRedactor(policy));
|
|
258
|
+
app.use((req, _res, next) => { logger.info(req.redacted()); next(); });
|
|
259
|
+
// Authorization and Cookie headers, and any secret in the body or query, are masked.
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
Same `policy` object flows into `flare-redact/llm`, `wrapConsole`, `createVault`,
|
|
263
|
+
and `redactStream` too.
|
|
264
|
+
|
|
160
265
|
## Streams
|
|
161
266
|
|
|
162
267
|
Pipe any log stream through it — secrets are masked line by line, even when one
|
|
@@ -255,14 +360,30 @@ redact<T>(input: T, opts?): T // masked copy, same shape
|
|
|
255
360
|
scan(input, opts?): Finding[] // findings + why, input untouched
|
|
256
361
|
isClean(input, opts?): boolean // any secrets at all?
|
|
257
362
|
summary(input, opts?): { total, byDetector } // counts per detector
|
|
258
|
-
createRedactor(opts):
|
|
363
|
+
createRedactor(opts) / definePolicy(opts) // one policy: redact, scan, vault(), wrapConsole, options
|
|
259
364
|
wrapConsole(opts?, console?): () => void // patch console.*, returns restore
|
|
260
|
-
|
|
365
|
+
|
|
366
|
+
createVault(opts?): Vault // reversible: redact / restore / entries
|
|
367
|
+
restore(input, vaultOrMap): T // put originals back
|
|
368
|
+
|
|
369
|
+
// adapters — each takes the same options object
|
|
370
|
+
pinoRedact(opts?) // 'flare-redact/pino' → { formatters: { log } }
|
|
371
|
+
winstonRedact(opts?) // 'flare-redact/winston' → a format transform
|
|
372
|
+
redactHttp(req, opts?) // 'flare-redact/http' → safe-to-log request snapshot
|
|
373
|
+
httpRedactor(opts?) // 'flare-redact/http' → Express/Connect middleware
|
|
374
|
+
|
|
375
|
+
// from 'flare-redact/llm'
|
|
376
|
+
wrapOpenAI(client, opts?) // scrub prompts, restore replies (+streaming)
|
|
377
|
+
wrapAnthropic(client, opts?) // same for messages.create + system
|
|
378
|
+
redactPrompt(text, opts?): { text, vault }
|
|
379
|
+
|
|
380
|
+
// from 'flare-redact/stream'
|
|
381
|
+
redactStream(opts?): Transform // line-wise stream redaction
|
|
261
382
|
|
|
262
383
|
// opts
|
|
263
384
|
// {
|
|
264
385
|
// only?, enable?, disable?, custom?, // which detectors run
|
|
265
|
-
// mode?: 'mask' | 'label' | 'hash', hashSalt?, mask?,
|
|
386
|
+
// mode?: 'mask' | 'label' | 'hash' | 'fpe', hashSalt?, mask?,
|
|
266
387
|
// redactKeys?: boolean | RegExp | string[],
|
|
267
388
|
// allow?: RegExp | string[],
|
|
268
389
|
// }
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { redact, scan, summary, DETECTORS } from './index.js';
|
|
3
|
-
const VERSION = '0.
|
|
3
|
+
const VERSION = '0.4.0';
|
|
4
4
|
const HELP = `flare-redact — hide secrets & PII before they hit a log
|
|
5
5
|
|
|
6
6
|
USAGE
|
|
@@ -10,7 +10,7 @@ OPTIONS
|
|
|
10
10
|
--scan list what would be redacted, and why (input unchanged)
|
|
11
11
|
--summary print a count of findings per detector
|
|
12
12
|
--json parse input as JSON and redact recursively
|
|
13
|
-
--mode <m> mask | label | hash
|
|
13
|
+
--mode <m> mask | label | hash | fpe (default: mask)
|
|
14
14
|
--hash-salt <s> salt for --mode hash
|
|
15
15
|
--only <ids> use only these detectors (comma-separated)
|
|
16
16
|
--enable <ids> turn on extra detectors (e.g. ipv4,high_entropy)
|
package/dist/detectors.d.ts
CHANGED
|
@@ -12,6 +12,13 @@ export declare function keepLast(n: number): (v: string) => string;
|
|
|
12
12
|
export declare function luhn(value: string): boolean;
|
|
13
13
|
export declare function entropy(s: string): number;
|
|
14
14
|
export declare function fnv1a(s: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Format-preserving pseudonym: same length and character classes as the input,
|
|
17
|
+
* so an email stays email-shaped and a card stays card-shaped. Deterministic —
|
|
18
|
+
* the same value (and salt) always maps to the same output, which keeps joins
|
|
19
|
+
* and references intact across a dataset.
|
|
20
|
+
*/
|
|
21
|
+
export declare function fpe(value: string, salt?: string): string;
|
|
15
22
|
export declare const SENSITIVE_KEY_RE: RegExp;
|
|
16
23
|
export declare const SENSITIVE_KEY_DETECTOR: Detector;
|
|
17
24
|
export declare const DETECTORS: Detector[];
|
package/dist/detectors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detectors.d.ts","sourceRoot":"","sources":["../src/detectors.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IACtC,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IACjC,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,IAC1B,GAAG,MAAM,KAAG,MAAM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AK,GAAG,MAAM,CAWpD;AAED,eAAO,MAAM,gBAAgB,QAC2K,CAAC;AAEzM,eAAO,MAAM,sBAAsB,EAAE,QAOpC,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,QAAQ,EAqM/B,CAAC"}
|
package/dist/detectors.js
CHANGED
|
@@ -46,6 +46,40 @@ export function fnv1a(s) {
|
|
|
46
46
|
}
|
|
47
47
|
return (h >>> 0).toString(16).padStart(8, '0');
|
|
48
48
|
}
|
|
49
|
+
function mulberry32(seed) {
|
|
50
|
+
let a = seed >>> 0;
|
|
51
|
+
return () => {
|
|
52
|
+
a = (a + 0x6d2b79f5) | 0;
|
|
53
|
+
let t = Math.imul(a ^ (a >>> 15), 1 | a);
|
|
54
|
+
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
|
55
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const FPE_DIGITS = '0123456789';
|
|
59
|
+
const FPE_LOWER = 'abcdefghijklmnopqrstuvwxyz';
|
|
60
|
+
const FPE_UPPER = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
61
|
+
/**
|
|
62
|
+
* Format-preserving pseudonym: same length and character classes as the input,
|
|
63
|
+
* so an email stays email-shaped and a card stays card-shaped. Deterministic —
|
|
64
|
+
* the same value (and salt) always maps to the same output, which keeps joins
|
|
65
|
+
* and references intact across a dataset.
|
|
66
|
+
*/
|
|
67
|
+
export function fpe(value, salt = '') {
|
|
68
|
+
const seed = parseInt(fnv1a(salt + value), 16) >>> 0;
|
|
69
|
+
const rand = mulberry32(seed || 1);
|
|
70
|
+
let out = '';
|
|
71
|
+
for (const ch of value) {
|
|
72
|
+
if (ch >= '0' && ch <= '9')
|
|
73
|
+
out += FPE_DIGITS[Math.floor(rand() * 10)];
|
|
74
|
+
else if (ch >= 'a' && ch <= 'z')
|
|
75
|
+
out += FPE_LOWER[Math.floor(rand() * 26)];
|
|
76
|
+
else if (ch >= 'A' && ch <= 'Z')
|
|
77
|
+
out += FPE_UPPER[Math.floor(rand() * 26)];
|
|
78
|
+
else
|
|
79
|
+
out += ch;
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
49
83
|
export const SENSITIVE_KEY_RE = /^(?:pass(?:word|wd)?|secret|token|api[_-]?key|access[_-]?key|client[_-]?secret|private[_-]?key|auth(?:orization)?|cookie|session[_-]?id|refresh[_-]?token|credit[_-]?card|card[_-]?number|cvv|ssn)$/i;
|
|
50
84
|
export const SENSITIVE_KEY_DETECTOR = {
|
|
51
85
|
id: 'sensitive_key',
|
package/dist/detectors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detectors.js","sourceRoot":"","sources":["../src/detectors.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,UAAU,CAAC,CAAS;IAClC,OAAO,CAAC,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;AAChF,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,CAAS;IAChC,OAAO,CAAC,CAAS,EAAU,EAAE;QAC3B,MAAM,MAAM,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACpC,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9B,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC/D,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;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EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,GAAG;QAClC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC;QACnB,OAAO,EAAE,KAAK;KACf;CACF,CAAC"}
|
package/dist/engine.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type Detector } from './detectors.js';
|
|
2
|
+
export type Mode = 'mask' | 'label' | 'hash' | 'fpe';
|
|
3
|
+
export interface Finding {
|
|
4
|
+
detector: string;
|
|
5
|
+
label: string;
|
|
6
|
+
why: string;
|
|
7
|
+
value: string;
|
|
8
|
+
start?: number;
|
|
9
|
+
end?: number;
|
|
10
|
+
path?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface RedactOptions {
|
|
13
|
+
only?: string[];
|
|
14
|
+
enable?: string[];
|
|
15
|
+
disable?: string[];
|
|
16
|
+
custom?: Detector[];
|
|
17
|
+
mode?: Mode;
|
|
18
|
+
mask?: string | ((f: {
|
|
19
|
+
value: string;
|
|
20
|
+
detector: Detector;
|
|
21
|
+
}) => string);
|
|
22
|
+
hashSalt?: string;
|
|
23
|
+
redactKeys?: boolean | RegExp | string[];
|
|
24
|
+
allow?: RegExp | string[];
|
|
25
|
+
}
|
|
26
|
+
export interface Hit extends Finding {
|
|
27
|
+
det: Detector;
|
|
28
|
+
}
|
|
29
|
+
export type Replace = (value: string, det: Detector) => string;
|
|
30
|
+
export declare function resolveDetectors(opts: RedactOptions): Detector[];
|
|
31
|
+
export declare function keyMatcher(opts: RedactOptions): (key: string) => boolean;
|
|
32
|
+
export declare function allowMatcher(opts: RedactOptions): (value: string) => boolean;
|
|
33
|
+
export declare function makeReplacer(opts: RedactOptions): Replace;
|
|
34
|
+
export declare function scanString(text: string, dets: Detector[], allow: (v: string) => boolean): Hit[];
|
|
35
|
+
export declare function redactString(text: string, dets: Detector[], allow: (v: string) => boolean, replace: Replace): string;
|
|
36
|
+
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|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G,QAAQ,EAAE,CAWhE;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,aAAa,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CASxE;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,aAAa,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAM5E;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAUzD;AAMD,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,QAAQ,EAAE,EAChB,KAAK,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,OAAO,GAC5B,GAAG,EAAE,CAkCP;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,QAAQ,EAAE,EAChB,KAAK,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,OAAO,EAC7B,OAAO,EAAE,OAAO,GACf,MAAM,CAWR"}
|
package/dist/engine.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { DETECTORS, fnv1a, fpe, SENSITIVE_KEY_RE } from './detectors.js';
|
|
2
|
+
export function resolveDetectors(opts) {
|
|
3
|
+
const all = opts.custom?.length ? [...DETECTORS, ...opts.custom] : DETECTORS;
|
|
4
|
+
if (opts.only?.length) {
|
|
5
|
+
const byId = new Map(all.map((d) => [d.id, d]));
|
|
6
|
+
return opts.only.map((id) => byId.get(id)).filter((d) => !!d);
|
|
7
|
+
}
|
|
8
|
+
const disabled = opts.disable?.length ? new Set(opts.disable) : null;
|
|
9
|
+
const enabled = opts.enable?.length ? new Set(opts.enable) : null;
|
|
10
|
+
return all.filter((d) => (d.default || enabled?.has(d.id)) && !disabled?.has(d.id));
|
|
11
|
+
}
|
|
12
|
+
export function keyMatcher(opts) {
|
|
13
|
+
const rk = opts.redactKeys;
|
|
14
|
+
if (rk === false)
|
|
15
|
+
return () => false;
|
|
16
|
+
if (rk instanceof RegExp)
|
|
17
|
+
return (k) => rk.test(k);
|
|
18
|
+
if (Array.isArray(rk)) {
|
|
19
|
+
const set = new Set(rk.map((s) => s.toLowerCase()));
|
|
20
|
+
return (k) => set.has(k.toLowerCase());
|
|
21
|
+
}
|
|
22
|
+
return (k) => SENSITIVE_KEY_RE.test(k);
|
|
23
|
+
}
|
|
24
|
+
export function allowMatcher(opts) {
|
|
25
|
+
const a = opts.allow;
|
|
26
|
+
if (!a)
|
|
27
|
+
return () => false;
|
|
28
|
+
if (a instanceof RegExp)
|
|
29
|
+
return (v) => a.test(v);
|
|
30
|
+
const set = new Set(a);
|
|
31
|
+
return (v) => set.has(v);
|
|
32
|
+
}
|
|
33
|
+
export function makeReplacer(opts) {
|
|
34
|
+
const salt = opts.hashSalt ?? '';
|
|
35
|
+
const mask = opts.mask;
|
|
36
|
+
const mode = opts.mode ?? 'mask';
|
|
37
|
+
if (typeof mask === 'string')
|
|
38
|
+
return () => mask;
|
|
39
|
+
if (typeof mask === 'function')
|
|
40
|
+
return (value, det) => mask({ value, detector: det });
|
|
41
|
+
if (mode === 'label')
|
|
42
|
+
return (_value, det) => `[REDACTED:${det.id}]`;
|
|
43
|
+
if (mode === 'hash')
|
|
44
|
+
return (value, det) => `${det.id}_${fnv1a(salt + value)}`;
|
|
45
|
+
if (mode === 'fpe')
|
|
46
|
+
return (value) => fpe(value, salt);
|
|
47
|
+
return (value, det) => (det.mask ? det.mask(value) : '***');
|
|
48
|
+
}
|
|
49
|
+
function withGlobal(re) {
|
|
50
|
+
return re.flags.includes('g') ? re : new RegExp(re.source, re.flags + 'g');
|
|
51
|
+
}
|
|
52
|
+
export function scanString(text, dets, allow) {
|
|
53
|
+
const hits = [];
|
|
54
|
+
for (const det of dets) {
|
|
55
|
+
const re = withGlobal(det.pattern);
|
|
56
|
+
re.lastIndex = 0;
|
|
57
|
+
let m;
|
|
58
|
+
while ((m = re.exec(text)) !== null) {
|
|
59
|
+
if (m.index === re.lastIndex)
|
|
60
|
+
re.lastIndex++;
|
|
61
|
+
const value = m[0];
|
|
62
|
+
if (!value)
|
|
63
|
+
continue;
|
|
64
|
+
if (det.validate && !det.validate(value))
|
|
65
|
+
continue;
|
|
66
|
+
if (allow(value))
|
|
67
|
+
continue;
|
|
68
|
+
hits.push({
|
|
69
|
+
detector: det.id,
|
|
70
|
+
label: det.label,
|
|
71
|
+
why: det.why,
|
|
72
|
+
value,
|
|
73
|
+
start: m.index,
|
|
74
|
+
end: m.index + value.length,
|
|
75
|
+
det,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (hits.length < 2)
|
|
80
|
+
return hits;
|
|
81
|
+
hits.sort((a, b) => a.start - b.start || b.end - b.start - (a.end - a.start));
|
|
82
|
+
const kept = [];
|
|
83
|
+
let lastEnd = -1;
|
|
84
|
+
for (const h of hits) {
|
|
85
|
+
if (h.start >= lastEnd) {
|
|
86
|
+
kept.push(h);
|
|
87
|
+
lastEnd = h.end;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return kept;
|
|
91
|
+
}
|
|
92
|
+
export function redactString(text, dets, allow, replace) {
|
|
93
|
+
const hits = scanString(text, dets, allow);
|
|
94
|
+
if (!hits.length)
|
|
95
|
+
return text;
|
|
96
|
+
let out = '';
|
|
97
|
+
let cursor = 0;
|
|
98
|
+
for (const h of hits) {
|
|
99
|
+
out += text.slice(cursor, h.start);
|
|
100
|
+
out += replace(h.value, h.det);
|
|
101
|
+
cursor = h.end;
|
|
102
|
+
}
|
|
103
|
+
return out + text.slice(cursor);
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,gBAAgB,EAAiB,MAAM,gBAAgB,CAAC;AAgCxF,MAAM,UAAU,gBAAgB,CAAC,IAAmB;IAClD,M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IAAI,OAAO,EAAE,CAAC;YACxB,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACb,OAAO,GAAG,CAAC,CAAC,GAAI,CAAC;QACnB,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,YAAY,CAC1B,IAAY,EACZ,IAAgB,EAChB,KAA6B,EAC7B,OAAgB;IAEhB,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IAC3C,IAAI,CAAC,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IAC9B,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;QACrB,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;QACnC,GAAG,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;QAC/B,MAAM,GAAG,CAAC,CAAC,GAAI,CAAC;IAClB,CAAC;IACD,OAAO,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAClC,CAAC"}
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type RedactOptions } from './index.js';
|
|
2
|
+
export interface HttpRequestLike {
|
|
3
|
+
method?: string;
|
|
4
|
+
url?: string;
|
|
5
|
+
originalUrl?: string;
|
|
6
|
+
headers?: Record<string, unknown>;
|
|
7
|
+
query?: unknown;
|
|
8
|
+
params?: unknown;
|
|
9
|
+
body?: unknown;
|
|
10
|
+
}
|
|
11
|
+
export interface RedactedRequest {
|
|
12
|
+
method?: string;
|
|
13
|
+
url?: string;
|
|
14
|
+
headers: unknown;
|
|
15
|
+
query: unknown;
|
|
16
|
+
params: unknown;
|
|
17
|
+
body: unknown;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A safe-to-log snapshot of a request. Authorization/Cookie headers, and any
|
|
21
|
+
* secret or PII in the query, params, or body, are masked — while ordinary
|
|
22
|
+
* fields (content-type, path, method) are left readable.
|
|
23
|
+
*/
|
|
24
|
+
export declare function redactHttp(req: HttpRequestLike, opts?: RedactOptions): RedactedRequest;
|
|
25
|
+
/**
|
|
26
|
+
* Connect/Express middleware. It doesn't touch the live request; it attaches
|
|
27
|
+
* `req.redacted()`, which returns a masked snapshot for your logger. Mount it
|
|
28
|
+
* after your body parser so `body` is populated.
|
|
29
|
+
*
|
|
30
|
+
* app.use(httpRedactor());
|
|
31
|
+
* app.use((req, _res, next) => { logger.info(req.redacted()); next(); });
|
|
32
|
+
*/
|
|
33
|
+
export declare function httpRedactor(opts?: RedactOptions): (req: HttpRequestLike, _res: unknown, next: () => void) => void;
|
|
34
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAExD,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;CACf;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,eAAe,EAAE,IAAI,GAAE,aAAkB,GAAG,eAAe,CAS1F;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,IAAI,GAAE,aAAkB,IAC3C,KAAK,eAAe,EAAE,MAAM,OAAO,EAAE,MAAM,MAAM,IAAI,KAAG,IAAI,CASrE"}
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { redact } from './index.js';
|
|
2
|
+
/**
|
|
3
|
+
* A safe-to-log snapshot of a request. Authorization/Cookie headers, and any
|
|
4
|
+
* secret or PII in the query, params, or body, are masked — while ordinary
|
|
5
|
+
* fields (content-type, path, method) are left readable.
|
|
6
|
+
*/
|
|
7
|
+
export function redactHttp(req, opts = {}) {
|
|
8
|
+
return {
|
|
9
|
+
method: req.method,
|
|
10
|
+
url: req.originalUrl ?? req.url,
|
|
11
|
+
headers: redact(req.headers ?? {}, opts),
|
|
12
|
+
query: redact(req.query, opts),
|
|
13
|
+
params: redact(req.params, opts),
|
|
14
|
+
body: redact(req.body, opts),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Connect/Express middleware. It doesn't touch the live request; it attaches
|
|
19
|
+
* `req.redacted()`, which returns a masked snapshot for your logger. Mount it
|
|
20
|
+
* after your body parser so `body` is populated.
|
|
21
|
+
*
|
|
22
|
+
* app.use(httpRedactor());
|
|
23
|
+
* app.use((req, _res, next) => { logger.info(req.redacted()); next(); });
|
|
24
|
+
*/
|
|
25
|
+
export function httpRedactor(opts = {}) {
|
|
26
|
+
return (req, _res, next) => {
|
|
27
|
+
Object.defineProperty(req, 'redacted', {
|
|
28
|
+
value: () => redactHttp(req, opts),
|
|
29
|
+
enumerable: false,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true,
|
|
32
|
+
});
|
|
33
|
+
next();
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=http.js.map
|
package/dist/http.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAsB,MAAM,YAAY,CAAC;AAqBxD;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,GAAoB,EAAE,OAAsB,EAAE;IACvE,OAAO;QACL,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,GAAG,EAAE,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,GAAG;QAC/B,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,OAAO,IAAI,EAAE,EAAE,IAAI,CAAC;QACxC,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC;QAC9B,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC;QAChC,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC;KAC7B,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,OAAsB,EAAE;IACnD,OAAO,CAAC,GAAoB,EAAE,IAAa,EAAE,IAAgB,EAAQ,EAAE;QACrE,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,UAAU,EAAE;YACrC,KAAK,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC;YAClC,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,IAAI;YAClB,QAAQ,EAAE,IAAI;SACf,CAAC,CAAC;QACH,IAAI,EAAE,CAAC;IACT,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,29 +1,8 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export {
|
|
3
|
-
export type
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
label: string;
|
|
7
|
-
why: string;
|
|
8
|
-
value: string;
|
|
9
|
-
start?: number;
|
|
10
|
-
end?: number;
|
|
11
|
-
path?: string;
|
|
12
|
-
}
|
|
13
|
-
export interface RedactOptions {
|
|
14
|
-
only?: string[];
|
|
15
|
-
enable?: string[];
|
|
16
|
-
disable?: string[];
|
|
17
|
-
custom?: Detector[];
|
|
18
|
-
mode?: Mode;
|
|
19
|
-
mask?: string | ((f: {
|
|
20
|
-
value: string;
|
|
21
|
-
detector: Detector;
|
|
22
|
-
}) => string);
|
|
23
|
-
hashSalt?: string;
|
|
24
|
-
redactKeys?: boolean | RegExp | string[];
|
|
25
|
-
allow?: RegExp | string[];
|
|
26
|
-
}
|
|
1
|
+
import { type RedactOptions, type Finding } from './engine.js';
|
|
2
|
+
export type { Mode, Finding, RedactOptions } from './engine.js';
|
|
3
|
+
export type { Detector } from './detectors.js';
|
|
4
|
+
export { DETECTORS, SENSITIVE_KEY_RE, keepPrefix, keepLast, luhn, entropy, fnv1a, fpe, } from './detectors.js';
|
|
5
|
+
export { createVault, restore, buildRestore, type Vault, type VaultOptions } from './vault.js';
|
|
27
6
|
export declare function redact<T>(input: T, opts?: RedactOptions): T;
|
|
28
7
|
export declare function scan(input: unknown, opts?: RedactOptions): Finding[];
|
|
29
8
|
export declare function isClean(input: unknown, opts?: RedactOptions): boolean;
|
|
@@ -31,7 +10,14 @@ export declare function summary(input: unknown, opts?: RedactOptions): {
|
|
|
31
10
|
total: number;
|
|
32
11
|
byDetector: Record<string, number>;
|
|
33
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Bind one set of options into a policy you reuse everywhere — in code, on a
|
|
15
|
+
* logger, in HTTP, in front of an LLM. `options` is the same object every
|
|
16
|
+
* adapter (`flare-redact/pino`, `/winston`, `/http`, `/llm`) accepts, so a
|
|
17
|
+
* secret is masked the same way across your whole system.
|
|
18
|
+
*/
|
|
34
19
|
export declare function createRedactor(opts?: RedactOptions): {
|
|
20
|
+
options: RedactOptions;
|
|
35
21
|
redact: <T>(input: T) => T;
|
|
36
22
|
scan: (input: unknown) => Finding[];
|
|
37
23
|
isClean: (input: unknown) => boolean;
|
|
@@ -39,6 +25,10 @@ export declare function createRedactor(opts?: RedactOptions): {
|
|
|
39
25
|
total: number;
|
|
40
26
|
byDetector: Record<string, number>;
|
|
41
27
|
};
|
|
28
|
+
vault: () => import("./vault.js").Vault;
|
|
29
|
+
wrapConsole: (target?: Console) => () => void;
|
|
42
30
|
};
|
|
31
|
+
/** Alias for {@link createRedactor}, read as "define the masking policy once". */
|
|
32
|
+
export declare const definePolicy: typeof createRedactor;
|
|
43
33
|
export declare function wrapConsole(opts?: RedactOptions, target?: Console): () => void;
|
|
44
34
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAOL,KAAK,aAAa,EAClB,KAAK,OAAO,EAEb,MAAM,aAAa,CAAC;AAErB,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAChE,YAAY,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,UAAU,EACV,QAAQ,EACR,IAAI,EACJ,OAAO,EACP,KAAK,EACL,GAAG,GACJ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,KAAK,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/F,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,GAAE,aAAkB,GAAG,CAAC,CAwB/D;AAED,wBAAgB,IAAI,CAAC,KAAK,EA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