flare-redact 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Umud Hasanli
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,285 @@
1
+ <p align="center">
2
+ <img src="assets/flare-redact.svg" alt="flare-redact" width="200">
3
+ </p>
4
+
5
+ <h1 align="center">flare-redact</h1>
6
+
7
+ <p align="center">
8
+ <b>Hide secrets & PII in logs and text — before they leak.</b>
9
+ </p>
10
+
11
+ <p align="center">
12
+ <a href="https://www.npmjs.com/package/flare-redact"><img src="https://img.shields.io/npm/v/flare-redact.svg" alt="npm"></a>
13
+ <a href="https://github.com/umudhasanli/flare-redact/actions/workflows/ci.yml"><img src="https://github.com/umudhasanli/flare-redact/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
14
+ <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="MIT License"></a>
15
+ <img src="https://img.shields.io/badge/dependencies-0-brightgreen" alt="Zero dependencies">
16
+ <img src="https://img.shields.io/badge/runtime-node%20%7C%20browser%20%7C%20edge-blue" alt="Runtimes">
17
+ </p>
18
+
19
+ ---
20
+
21
+ Every leaked secret has the same origin story: someone logged an object, and a
22
+ password, token, or API key was sitting inside it. The code looked innocent —
23
+ `logger.info({ user })` — but `user` carried a session token, and now it's in
24
+ your log aggregator, your error tracker, and three vendors' systems forever.
25
+
26
+ **flare-redact** is one function you wrap around that data. It reads the *content*,
27
+ not just the field names, so it catches the AWS key someone pasted into a free-text
28
+ `note`, the JWT in an `Authorization` header, the card number in a stack trace — and
29
+ masks them, keeping just enough of a hint to stay debuggable.
30
+
31
+ ```js
32
+ import { redact } from 'flare-redact';
33
+
34
+ redact('User alice@corp.com paid with 4242 4242 4242 4242, token ghp_' + 'a'.repeat(36));
35
+ // → 'User a***@*** paid with **** **** **** 4242, token ghp_***'
36
+ ```
37
+
38
+ Nothing to configure. No list of field paths to maintain. No native build step.
39
+
40
+ ## Contents
41
+
42
+ - [Install](#install)
43
+ - [Redact anything](#redact-anything)
44
+ - [Three ways to hide a value](#three-ways-to-hide-a-value)
45
+ - [See what leaks, and why](#see-what-leaks-and-why)
46
+ - [Guard your logger in one line](#guard-your-logger-in-one-line)
47
+ - [Streams](#streams)
48
+ - [Fail a build when a secret sneaks in](#fail-a-build-when-a-secret-sneaks-in)
49
+ - [CLI](#cli)
50
+ - [What it catches](#what-it-catches)
51
+ - [Custom detectors & allowlists](#custom-detectors--allowlists)
52
+ - [API](#api)
53
+ - [Why not a field allowlist?](#why-not-a-field-allowlist)
54
+
55
+ ## Install
56
+
57
+ ```bash
58
+ npm install flare-redact
59
+ ```
60
+
61
+ Node 18+, and it runs in the browser and edge runtimes too — zero dependencies.
62
+
63
+ ## Redact anything
64
+
65
+ Strings, arrays, and objects, recursively. The shape you pass in is the shape you
66
+ get back.
67
+
68
+ ```js
69
+ import { redact } from 'flare-redact';
70
+
71
+ redact({
72
+ user: 'bob@corp.com',
73
+ password: 'hunter2',
74
+ tokens: ['ghp_' + 'b'.repeat(36)],
75
+ note: 'my aws key is AKIAIOSFODNN7EXAMPLE',
76
+ });
77
+ // →
78
+ // {
79
+ // user: 'b***@***',
80
+ // password: '***', // sensitive field name
81
+ // tokens: ['ghp_***'],
82
+ // note: 'my aws key is AKIA***', // found inside free text
83
+ // }
84
+ ```
85
+
86
+ ## Three ways to hide a value
87
+
88
+ Pick a `mode` depending on whether you still need to *reason* about the data
89
+ after it's hidden.
90
+
91
+ ```js
92
+ redact('bob@corp.com', { mode: 'mask' }); // 'b***@***' (default)
93
+ redact('bob@corp.com', { mode: 'label' }); // '[REDACTED:email]'
94
+ redact('bob@corp.com', { mode: 'hash' }); // 'email_f63d8d56'
95
+ ```
96
+
97
+ `hash` is the useful one for support work: the same input always hashes to the
98
+ same token, so you can still tell that two log lines came from the same user —
99
+ without ever storing who that user is. Add `hashSalt` to make the tokens
100
+ per-service.
101
+
102
+ Or replace everything with one fixed string:
103
+
104
+ ```js
105
+ redact(payload, { mask: '█' });
106
+ redact(payload, { mask: ({ detector }) => `<${detector.id}>` });
107
+ ```
108
+
109
+ ## See what leaks, and why
110
+
111
+ `scan()` finds secrets without changing the input, and explains every hit in
112
+ plain English — handy for alerts, dashboards, and understanding *why* something
113
+ matched.
114
+
115
+ ```js
116
+ import { scan } from 'flare-redact';
117
+
118
+ scan('deploy with password=hunter2 and AKIAIOSFODNN7EXAMPLE');
119
+ // →
120
+ // [
121
+ // { detector: 'generic_assignment', label: 'Assigned secret',
122
+ // why: 'A value assigned to a sensitive-looking field name…', start: 12, … },
123
+ // { detector: 'aws_access_key', label: 'AWS access key ID',
124
+ // why: 'Pairs with a secret key to control cloud resources and billing.', start: 33, … },
125
+ // ]
126
+ ```
127
+
128
+ Need just the shape of it?
129
+
130
+ ```js
131
+ import { isClean, summary } from 'flare-redact';
132
+
133
+ isClean(payload); // → false
134
+ summary(payload); // → { total: 3, byDetector: { email: 1, github_token: 1, sensitive_key: 1 } }
135
+ ```
136
+
137
+ ## Guard your logger in one line
138
+
139
+ `wrapConsole` patches `console.*` so every argument is redacted on the way out,
140
+ and hands you a function to undo it.
141
+
142
+ ```js
143
+ import { wrapConsole } from 'flare-redact';
144
+
145
+ const restore = wrapConsole();
146
+ console.log('session', { user: 'bob@x.io', token: 'ghp_…' });
147
+ // session { user: 'b***@***', token: 'ghp_***' }
148
+ restore();
149
+ ```
150
+
151
+ Prefer to be explicit? Bind your options once and reuse it:
152
+
153
+ ```js
154
+ import { createRedactor } from 'flare-redact';
155
+
156
+ const safe = createRedactor({ enable: ['high_entropy'] });
157
+ logger.info(safe.redact({ event: 'checkout', user }));
158
+ ```
159
+
160
+ ## Streams
161
+
162
+ Pipe any log stream through it — secrets are masked line by line, even when one
163
+ is split across chunks.
164
+
165
+ ```js
166
+ import { redactStream } from 'flare-redact/stream';
167
+
168
+ process.stdin.pipe(redactStream()).pipe(process.stdout);
169
+ ```
170
+
171
+ ## Fail a build when a secret sneaks in
172
+
173
+ `scan` from code, or `--scan` from the CLI (which exits non-zero on a hit):
174
+
175
+ ```yaml
176
+ - run: git ls-files '*.env*' '*.log' '*.json' | xargs npx flare-redact --scan
177
+ ```
178
+
179
+ ## CLI
180
+
181
+ ```bash
182
+ npm install -g flare-redact
183
+ ```
184
+
185
+ ```bash
186
+ tail -f app.log | flare-redact # stream redacted logs
187
+ flare-redact --json --mode hash < event.json # deep-redact a JSON payload
188
+ flare-redact --scan config.env # list findings + why (exit 1 if any)
189
+ flare-redact --summary --json < event.json # counts per detector
190
+ flare-redact --enable high_entropy < app.log # also catch unknown-format keys
191
+ flare-redact --list # show every detector
192
+ ```
193
+
194
+ ## What it catches
195
+
196
+ On by default:
197
+
198
+ | Detector | Finds |
199
+ |---|---|
200
+ | `private_key` | PEM private key blocks (RSA/EC/OpenSSH/PGP) |
201
+ | `aws_access_key` | AWS access key IDs (`AKIA…`, `ASIA…`) |
202
+ | `github_token` | GitHub PATs and OAuth tokens (`ghp_…`, `github_pat_…`) |
203
+ | `gitlab_token` | GitLab PATs (`glpat-…`) |
204
+ | `slack_token` | Slack tokens (`xoxb-…`) |
205
+ | `stripe_key` | Stripe secret / restricted keys (`sk_live_…`, `rk_…`) |
206
+ | `openai_key` | OpenAI API keys (`sk-…`) |
207
+ | `google_api_key` | Google API keys (`AIza…`) |
208
+ | `sendgrid_key` | SendGrid API keys (`SG.…`) |
209
+ | `twilio_key` | Twilio SIDs / keys (`AC…`, `SK…`) |
210
+ | `npm_token` | npm tokens (`npm_…`) |
211
+ | `jwt` | JSON Web Tokens |
212
+ | `bearer_token` | `Authorization: Bearer …` |
213
+ | `basic_auth` | `Authorization: Basic …` |
214
+ | `url_credentials` | passwords inside connection strings |
215
+ | `generic_assignment` | `password=`, `api_key: …`, `secret=…` |
216
+ | `email` | email addresses |
217
+ | `credit_card` | card numbers (Luhn-validated) |
218
+
219
+ Opt in with `enable`:
220
+
221
+ | Detector | Finds |
222
+ |---|---|
223
+ | `high_entropy` | long random-looking tokens of *any* format (entropy-based) |
224
+ | `phone` | E.164 phone numbers |
225
+ | `ssn` | US Social Security numbers |
226
+ | `ipv4` / `ipv6` | IP addresses |
227
+ | `mac_address` | MAC addresses |
228
+
229
+ Plus object values whose **key name** is sensitive (`password`, `token`,
230
+ `authorization`, `cookie`, `cvv`, …) are masked regardless of content.
231
+
232
+ ## Custom detectors & allowlists
233
+
234
+ Teach it your own secrets, and tell it what to leave alone:
235
+
236
+ ```js
237
+ redact(text, {
238
+ custom: [{
239
+ id: 'internal_ticket',
240
+ label: 'Internal ticket',
241
+ why: 'Leaks internal issue-tracker IDs.',
242
+ pattern: /\bACME-\d{4,6}\b/g,
243
+ mask: () => '[TICKET]',
244
+ default: true,
245
+ }],
246
+ allow: ['support@acme.com'], // never redact these exact values
247
+ redactKeys: ['ssn', 'dob'], // extra sensitive object keys
248
+ });
249
+ ```
250
+
251
+ ## API
252
+
253
+ ```ts
254
+ redact<T>(input: T, opts?): T // masked copy, same shape
255
+ scan(input, opts?): Finding[] // findings + why, input untouched
256
+ isClean(input, opts?): boolean // any secrets at all?
257
+ summary(input, opts?): { total, byDetector } // counts per detector
258
+ createRedactor(opts): { redact, scan, isClean, summary }
259
+ wrapConsole(opts?, console?): () => void // patch console.*, returns restore
260
+ redactStream(opts?): Transform // from 'flare-redact/stream'
261
+
262
+ // opts
263
+ // {
264
+ // only?, enable?, disable?, custom?, // which detectors run
265
+ // mode?: 'mask' | 'label' | 'hash', hashSalt?, mask?,
266
+ // redactKeys?: boolean | RegExp | string[],
267
+ // allow?: RegExp | string[],
268
+ // }
269
+ ```
270
+
271
+ ## Why not a field allowlist?
272
+
273
+ Path-based redactors (like naming fields in a logger config) only hide the fields
274
+ you *remembered* to name. The leak is always the field you forgot — the free-text
275
+ message, the nested third-party payload, the string someone concatenated by hand.
276
+ flare-redact scans the actual values, so it doesn't depend on your memory.
277
+
278
+ And the patterns it scans with are **bounded and ReDoS-safe** — no nested
279
+ quantifiers, no `(a+)+` blow-ups. You can point it at attacker-controlled input
280
+ and it stays linear, the same principle behind its sibling
281
+ [flare-regex](https://github.com/umudhasanli/flare-regex).
282
+
283
+ ## License
284
+
285
+ MIT © Umud Hasanli
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { main } from '../dist/cli.js';
3
+ process.exit(main(process.argv.slice(2)));
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare function main(argv: string[]): number;
2
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAmGA,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CA0C3C"}
package/dist/cli.js ADDED
@@ -0,0 +1,167 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { redact, scan, summary, DETECTORS } from './index.js';
3
+ const VERSION = '0.2.0';
4
+ const HELP = `flare-redact — hide secrets & PII before they hit a log
5
+
6
+ USAGE
7
+ flare-redact [options] [files...] stdin if no files
8
+
9
+ OPTIONS
10
+ --scan list what would be redacted, and why (input unchanged)
11
+ --summary print a count of findings per detector
12
+ --json parse input as JSON and redact recursively
13
+ --mode <m> mask | label | hash (default: mask)
14
+ --hash-salt <s> salt for --mode hash
15
+ --only <ids> use only these detectors (comma-separated)
16
+ --enable <ids> turn on extra detectors (e.g. ipv4,high_entropy)
17
+ --disable <ids> turn off detectors (e.g. email)
18
+ --mask <str> replace every secret with this string
19
+ --allow <vals> never redact these exact values (comma-separated)
20
+ --list show all detectors and exit
21
+ -h, --help show this help
22
+ -v, --version show version
23
+
24
+ EXAMPLES
25
+ tail -f app.log | flare-redact
26
+ flare-redact --scan config.env
27
+ flare-redact --json --mode hash < event.json
28
+ flare-redact --enable high_entropy,ipv4 < app.log
29
+ `;
30
+ function csv(s) {
31
+ return s ? s.split(',').map((x) => x.trim()).filter(Boolean) : [];
32
+ }
33
+ function parseArgs(argv) {
34
+ const opts = {};
35
+ const files = [];
36
+ let scanMode = false;
37
+ let summaryMode = false;
38
+ let jsonMode = false;
39
+ let showHelp = false;
40
+ let showVersion = false;
41
+ let listMode = false;
42
+ for (let i = 0; i < argv.length; i++) {
43
+ const a = argv[i];
44
+ switch (a) {
45
+ case '--scan':
46
+ scanMode = true;
47
+ break;
48
+ case '--summary':
49
+ summaryMode = true;
50
+ break;
51
+ case '--json':
52
+ jsonMode = true;
53
+ break;
54
+ case '--list':
55
+ listMode = true;
56
+ break;
57
+ case '-h':
58
+ case '--help':
59
+ showHelp = true;
60
+ break;
61
+ case '-v':
62
+ case '--version':
63
+ showVersion = true;
64
+ break;
65
+ case '--only':
66
+ opts.only = csv(argv[++i]);
67
+ break;
68
+ case '--enable':
69
+ opts.enable = csv(argv[++i]);
70
+ break;
71
+ case '--disable':
72
+ opts.disable = csv(argv[++i]);
73
+ break;
74
+ case '--allow':
75
+ opts.allow = csv(argv[++i]);
76
+ break;
77
+ case '--mask':
78
+ opts.mask = argv[++i];
79
+ break;
80
+ case '--mode':
81
+ opts.mode = argv[++i];
82
+ break;
83
+ case '--hash-salt':
84
+ opts.hashSalt = argv[++i];
85
+ break;
86
+ default:
87
+ if (a.startsWith('-'))
88
+ throw new Error(`unknown option: ${a}`);
89
+ files.push(a);
90
+ }
91
+ }
92
+ return { opts, files, scanMode, summaryMode, jsonMode, showHelp, showVersion, listMode };
93
+ }
94
+ function readStdin() {
95
+ try {
96
+ return readFileSync(0, 'utf8');
97
+ }
98
+ catch {
99
+ return '';
100
+ }
101
+ }
102
+ function formatFindings(findings) {
103
+ if (!findings.length)
104
+ return 'No secrets found.';
105
+ const lines = findings.map((f) => {
106
+ const where = f.path ? ` @ ${f.path}` : f.start !== undefined ? ` @ ${f.start}` : '';
107
+ return `⚠ ${f.label} (${f.detector})${where}\n ${f.why}`;
108
+ });
109
+ const noun = findings.length === 1 ? 'finding' : 'findings';
110
+ return `${findings.length} ${noun}:\n\n${lines.join('\n\n')}`;
111
+ }
112
+ export function main(argv) {
113
+ let parsed;
114
+ try {
115
+ parsed = parseArgs(argv);
116
+ }
117
+ catch (e) {
118
+ process.stderr.write(`${e.message}\n\n${HELP}`);
119
+ return 2;
120
+ }
121
+ const { opts, files, scanMode, summaryMode, jsonMode, showHelp, showVersion, listMode } = parsed;
122
+ if (showHelp) {
123
+ process.stdout.write(HELP);
124
+ return 0;
125
+ }
126
+ if (showVersion) {
127
+ process.stdout.write(`${VERSION}\n`);
128
+ return 0;
129
+ }
130
+ if (listMode) {
131
+ for (const d of DETECTORS) {
132
+ process.stdout.write(`${d.default ? '●' : '○'} ${d.id.padEnd(20)} ${d.label} — ${d.why}\n`);
133
+ }
134
+ return 0;
135
+ }
136
+ const raw = files.length ? files.map((f) => readFileSync(f, 'utf8')).join('\n') : readStdin();
137
+ const data = jsonMode ? tryParse(raw) : raw;
138
+ if (jsonMode && data === PARSE_ERROR)
139
+ return 2;
140
+ if (summaryMode) {
141
+ const s = summary(data, opts);
142
+ process.stdout.write(JSON.stringify(s, null, 2) + '\n');
143
+ return s.total ? 1 : 0;
144
+ }
145
+ if (scanMode) {
146
+ const findings = scan(data, opts);
147
+ process.stdout.write(formatFindings(findings) + '\n');
148
+ return findings.length ? 1 : 0;
149
+ }
150
+ if (jsonMode) {
151
+ process.stdout.write(JSON.stringify(redact(data, opts), null, 2) + '\n');
152
+ return 0;
153
+ }
154
+ process.stdout.write(redact(raw, opts));
155
+ return 0;
156
+ }
157
+ const PARSE_ERROR = Symbol('parse-error');
158
+ function tryParse(raw) {
159
+ try {
160
+ return JSON.parse(raw);
161
+ }
162
+ catch (e) {
163
+ process.stderr.write(`invalid JSON: ${e.message}\n`);
164
+ return PARSE_ERROR;
165
+ }
166
+ }
167
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAA+C,MAAM,YAAY,CAAC;AAE3G,MAAM,OAAO,GAAG,OAAO,CAAC;AAExB,MAAM,IAAI,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;CAyBZ,CAAC;AAaF,SAAS,GAAG,CAAC,CAAqB;IAChC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACpE,CAAC;AAED,SAAS,SAAS,CAAC,IAAc;IAC/B,MAAM,IAAI,GAAkB,EAAE,CAAC;IAC/B,MAAM,KAAK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,CAAC;IAED,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;QACzE,OAAO,CAAC,CAAC;IACX,CAAC;IAED,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;IACxC,OAAO,CAAC,CAAC;AACX,CAAC;AAED,MAAM,WAAW,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;AAE1C,SAAS,QAAQ,CAAC,GAAW;IAC3B,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,iBAAkB,CAAW,CAAC,OAAO,IAAI,CAAC,CAAC;QAChE,OAAO,WAAW,CAAC;IACrB,CAAC;AACH,CAAC"}
@@ -0,0 +1,18 @@
1
+ export interface Detector {
2
+ id: string;
3
+ label: string;
4
+ why: string;
5
+ pattern: RegExp;
6
+ validate?: (match: string) => boolean;
7
+ mask?: (match: string) => string;
8
+ default: boolean;
9
+ }
10
+ export declare function keepPrefix(n: number): (v: string) => string;
11
+ export declare function keepLast(n: number): (v: string) => string;
12
+ export declare function luhn(value: string): boolean;
13
+ export declare function entropy(s: string): number;
14
+ export declare function fnv1a(s: string): string;
15
+ export declare const SENSITIVE_KEY_RE: RegExp;
16
+ export declare const SENSITIVE_KEY_DETECTOR: Detector;
17
+ export declare const DETECTORS: Detector[];
18
+ //# sourceMappingURL=detectors.d.ts.map
@@ -0,0 +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,CAC3B;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,IACxB,GAAG,MAAM,KAAG,MAAM,CAM3B;AAED,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAY3C;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CASzC;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAOvC;AAED,eAAO,MAAM,gBAAgB,QAC2K,CAAC;AAEzM,eAAO,MAAM,sBAAsB,EAAE,QAOpC,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,QAAQ,EAqM/B,CAAC"}
@@ -0,0 +1,254 @@
1
+ export function keepPrefix(n) {
2
+ return (v) => (v.length <= n ? '***' : v.slice(0, n) + '***');
3
+ }
4
+ export function keepLast(n) {
5
+ return (v) => {
6
+ const digits = v.replace(/\D/g, '');
7
+ const tail = digits.slice(-n);
8
+ const groups = Math.max(0, Math.ceil((digits.length - n) / 4));
9
+ return ('**** '.repeat(groups) + tail).trim();
10
+ };
11
+ }
12
+ export function luhn(value) {
13
+ const digits = value.replace(/\D/g, '');
14
+ if (digits.length < 13 || digits.length > 19)
15
+ return false;
16
+ let sum = 0;
17
+ let alt = false;
18
+ for (let i = digits.length - 1; i >= 0; i--) {
19
+ let d = digits.charCodeAt(i) - 48;
20
+ if (alt) {
21
+ d *= 2;
22
+ if (d > 9)
23
+ d -= 9;
24
+ }
25
+ sum += d;
26
+ alt = !alt;
27
+ }
28
+ return sum % 10 === 0;
29
+ }
30
+ export function entropy(s) {
31
+ const freq = new Map();
32
+ for (const ch of s)
33
+ freq.set(ch, (freq.get(ch) ?? 0) + 1);
34
+ let e = 0;
35
+ for (const n of freq.values()) {
36
+ const p = n / s.length;
37
+ e -= p * Math.log2(p);
38
+ }
39
+ return e;
40
+ }
41
+ export function fnv1a(s) {
42
+ let h = 0x811c9dc5;
43
+ for (let i = 0; i < s.length; i++) {
44
+ h ^= s.charCodeAt(i);
45
+ h = Math.imul(h, 0x01000193);
46
+ }
47
+ return (h >>> 0).toString(16).padStart(8, '0');
48
+ }
49
+ 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
+ export const SENSITIVE_KEY_DETECTOR = {
51
+ id: 'sensitive_key',
52
+ label: 'Sensitive field',
53
+ why: 'A value stored under a field name that is sensitive by convention.',
54
+ pattern: /(?!)/,
55
+ mask: () => '***',
56
+ default: true,
57
+ };
58
+ export const DETECTORS = [
59
+ {
60
+ id: 'private_key',
61
+ label: 'Private key',
62
+ why: 'A PEM private key is a full cryptographic identity — whoever holds it is you.',
63
+ pattern: /-----BEGIN (?:RSA |EC |DSA |OPENSSH |PGP |ENCRYPTED )?PRIVATE KEY-----[\s\S]*?-----END (?:RSA |EC |DSA |OPENSSH |PGP |ENCRYPTED )?PRIVATE KEY-----/g,
64
+ mask: () => '[REDACTED PRIVATE KEY]',
65
+ default: true,
66
+ },
67
+ {
68
+ id: 'aws_access_key',
69
+ label: 'AWS access key ID',
70
+ why: 'Pairs with a secret key to control cloud resources and billing.',
71
+ pattern: /\b(?:AKIA|ASIA|AGPA|AIDA|AROA|ANPA|ANVA)[A-Z0-9]{16}\b/g,
72
+ mask: keepPrefix(4),
73
+ default: true,
74
+ },
75
+ {
76
+ id: 'github_token',
77
+ label: 'GitHub token',
78
+ why: 'Grants access to repositories and account actions.',
79
+ pattern: /\b(?:gh[posur]_[A-Za-z0-9]{36}|github_pat_[A-Za-z0-9_]{82})\b/g,
80
+ mask: keepPrefix(4),
81
+ default: true,
82
+ },
83
+ {
84
+ id: 'gitlab_token',
85
+ label: 'GitLab token',
86
+ why: 'A GitLab personal access token grants API and repo access.',
87
+ pattern: /\bglpat-[A-Za-z0-9_-]{20}\b/g,
88
+ mask: keepPrefix(6),
89
+ default: true,
90
+ },
91
+ {
92
+ id: 'slack_token',
93
+ label: 'Slack token',
94
+ why: 'Lets the holder read and post as your workspace app.',
95
+ pattern: /\bxox[baprs]-[A-Za-z0-9-]{10,64}\b/g,
96
+ mask: keepPrefix(5),
97
+ default: true,
98
+ },
99
+ {
100
+ id: 'stripe_key',
101
+ label: 'Stripe secret key',
102
+ why: 'A live secret or restricted key can move real money.',
103
+ pattern: /\b(?:sk|rk)_(?:live|test)_[A-Za-z0-9]{16,64}\b/g,
104
+ mask: (v) => v.slice(0, v.indexOf('_', v.indexOf('_') + 1) + 1) + '***',
105
+ default: true,
106
+ },
107
+ {
108
+ id: 'openai_key',
109
+ label: 'OpenAI API key',
110
+ why: 'Bills against your account and reaches your models and data.',
111
+ pattern: /\bsk-(?:proj-)?[A-Za-z0-9_-]{20,64}\b/g,
112
+ mask: keepPrefix(3),
113
+ default: true,
114
+ },
115
+ {
116
+ id: 'google_api_key',
117
+ label: 'Google API key',
118
+ why: 'Grants access to enabled Google Cloud APIs on your project.',
119
+ pattern: /\bAIza[0-9A-Za-z_-]{35}\b/g,
120
+ mask: keepPrefix(4),
121
+ default: true,
122
+ },
123
+ {
124
+ id: 'sendgrid_key',
125
+ label: 'SendGrid API key',
126
+ why: 'Can send mail as your domain and read templates.',
127
+ pattern: /\bSG\.[A-Za-z0-9_-]{16,32}\.[A-Za-z0-9_-]{16,64}\b/g,
128
+ mask: keepPrefix(3),
129
+ default: true,
130
+ },
131
+ {
132
+ id: 'twilio_key',
133
+ label: 'Twilio SID / key',
134
+ why: 'Can send messages and place calls billed to your account.',
135
+ pattern: /\b(?:AC|SK)[a-f0-9]{32}\b/g,
136
+ mask: keepPrefix(4),
137
+ default: true,
138
+ },
139
+ {
140
+ id: 'npm_token',
141
+ label: 'npm token',
142
+ why: 'Can publish packages to your npm account.',
143
+ pattern: /\bnpm_[A-Za-z0-9]{36}\b/g,
144
+ mask: keepPrefix(4),
145
+ default: true,
146
+ },
147
+ {
148
+ id: 'jwt',
149
+ label: 'JSON Web Token',
150
+ why: 'Often a live session or bearer credential — decode it and you may be signed in.',
151
+ pattern: /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{4,}\b/g,
152
+ mask: () => '[REDACTED JWT]',
153
+ default: true,
154
+ },
155
+ {
156
+ id: 'bearer_token',
157
+ label: 'Bearer token',
158
+ why: 'A bearer token in an Authorization header is a live credential.',
159
+ pattern: /\bBearer\s+[A-Za-z0-9._~+/-]{8,}={0,2}/g,
160
+ mask: () => 'Bearer ***',
161
+ default: true,
162
+ },
163
+ {
164
+ id: 'basic_auth',
165
+ label: 'Basic auth header',
166
+ why: 'Base64 in a Basic header decodes straight back to user:password.',
167
+ pattern: /\bBasic\s+[A-Za-z0-9+/]{8,}={0,2}/g,
168
+ mask: () => 'Basic ***',
169
+ default: true,
170
+ },
171
+ {
172
+ id: 'url_credentials',
173
+ label: 'Credentials in URL',
174
+ why: 'A username:password baked into a connection string leaks the password.',
175
+ pattern: /\b[a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^:@\s/]+:[^@\s/]+@/g,
176
+ mask: (m) => m.replace(/:([^:@\s/]+)@$/, ':***@'),
177
+ default: true,
178
+ },
179
+ {
180
+ id: 'generic_assignment',
181
+ label: 'Assigned secret',
182
+ why: 'A value assigned to a sensitive-looking field name (password=…, api_key: …).',
183
+ pattern: /\b(?:pass(?:word|wd)?|secret|token|api[_-]?key|access[_-]?key|client[_-]?secret|auth)\b["'\s]*[:=]\s*["']?([^\s"',;]{4,})["']?/gi,
184
+ mask: (m) => m.replace(/([:=]\s*["']?)([^\s"',;]{4,})(["']?)\s*$/, '$1***$3'),
185
+ default: true,
186
+ },
187
+ {
188
+ id: 'email',
189
+ label: 'Email address',
190
+ why: 'Personal data that usually does not belong in logs.',
191
+ pattern: /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,24}\b/g,
192
+ mask: (m) => (m[0] ?? '') + '***@***',
193
+ default: true,
194
+ },
195
+ {
196
+ id: 'credit_card',
197
+ label: 'Payment card number',
198
+ why: 'A card number in logs is a PCI-DSS violation.',
199
+ pattern: /\b\d(?:[ -]?\d){12,18}\b/g,
200
+ validate: luhn,
201
+ mask: keepLast(4),
202
+ default: true,
203
+ },
204
+ {
205
+ id: 'phone',
206
+ label: 'Phone number',
207
+ why: 'An E.164 phone number is personal data.',
208
+ pattern: /\+[1-9]\d{7,14}\b/g,
209
+ mask: (m) => m.slice(0, 3) + '***',
210
+ default: false,
211
+ },
212
+ {
213
+ id: 'ssn',
214
+ label: 'US Social Security number',
215
+ why: 'A national identifier — high-value PII.',
216
+ pattern: /\b\d{3}-\d{2}-\d{4}\b/g,
217
+ mask: () => '***-**-****',
218
+ default: false,
219
+ },
220
+ {
221
+ id: 'ipv4',
222
+ label: 'IPv4 address',
223
+ why: 'Can be personal data or reveal internal infrastructure.',
224
+ pattern: /\b(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)\b/g,
225
+ mask: () => '***.***.***.***',
226
+ default: false,
227
+ },
228
+ {
229
+ id: 'ipv6',
230
+ label: 'IPv6 address',
231
+ why: 'Can be personal data or reveal internal infrastructure.',
232
+ pattern: /\b(?:[A-Fa-f0-9]{1,4}:){2,7}[A-Fa-f0-9]{1,4}\b/g,
233
+ mask: () => '[REDACTED IPv6]',
234
+ default: false,
235
+ },
236
+ {
237
+ id: 'mac_address',
238
+ label: 'MAC address',
239
+ why: 'A hardware address that can identify a device.',
240
+ pattern: /\b(?:[A-Fa-f0-9]{2}:){5}[A-Fa-f0-9]{2}\b/g,
241
+ mask: () => '**:**:**:**:**:**',
242
+ default: false,
243
+ },
244
+ {
245
+ id: 'high_entropy',
246
+ label: 'High-entropy string',
247
+ why: 'A long random-looking token — likely a key even if its format is unknown.',
248
+ pattern: /\b[A-Za-z0-9+/=_-]{20,80}\b/g,
249
+ validate: (v) => entropy(v) >= 3.5,
250
+ mask: keepPrefix(4),
251
+ default: false,
252
+ },
253
+ ];
254
+ //# sourceMappingURL=detectors.js.map
@@ -0,0 +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;IAChD,CAAC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AAE,wEAAwE;QACjF,IAAI,EAAE,GAAG,EAAE,CAAC,iBAAiB;QAC7B,OAAO,EAAE,KAAK;KACf;IACD;QACE,EAAE,EAAE,MAAM;QACV,KAAK,EAAE,cAAc;QACrB,GAAG,EAAE,yDAAyD;QAC9D,OAAO,EAAE,iDAAiD;QAC1D,IAAI,EAAE,GAAG,EAAE,CAAC,iBAAiB;QAC7B,OAAO,EAAE,KAAK;KACf;IACD;QACE,EAAE,EAAE,aAAa;QACjB,KAAK,EAAE,aAAa;QACpB,GAAG,EAAE,gDAAgD;QACrD,OAAO,EAAE,2CAA2C;QACpD,IAAI,EAAE,GAAG,EAAE,CAAC,mBAAmB;QAC/B,OAAO,EAAE,KAAK;KACf;IACD;QACE,EAAE,EAAE,cAAc;QAClB,KAAK,EAAE,qBAAqB;QAC5B,GAAG,EAAE,2EAA2E;QAChF,OAAO,EAAE,8BAA8B;QACvC,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,GAAG;QAClC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC;QACnB,OAAO,EAAE,KAAK;KACf;CACF,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { type Detector } from './detectors.js';
2
+ export { DETECTORS, SENSITIVE_KEY_RE, keepPrefix, keepLast, luhn, entropy, fnv1a, type Detector, } from './detectors.js';
3
+ export type Mode = 'mask' | 'label' | 'hash';
4
+ export interface Finding {
5
+ detector: string;
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
+ }
27
+ export declare function redact<T>(input: T, opts?: RedactOptions): T;
28
+ export declare function scan(input: unknown, opts?: RedactOptions): Finding[];
29
+ export declare function isClean(input: unknown, opts?: RedactOptions): boolean;
30
+ export declare function summary(input: unknown, opts?: RedactOptions): {
31
+ total: number;
32
+ byDetector: Record<string, number>;
33
+ };
34
+ export declare function createRedactor(opts?: RedactOptions): {
35
+ redact: <T>(input: T) => T;
36
+ scan: (input: unknown) => Finding[];
37
+ isClean: (input: unknown) => boolean;
38
+ summary: (input: unknown) => {
39
+ total: number;
40
+ byDetector: Record<string, number>;
41
+ };
42
+ };
43
+ export declare function wrapConsole(opts?: RedactOptions, target?: Console): () => void;
44
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,QAAQ,EACd,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,UAAU,EACV,QAAQ,EACR,IAAI,EACJ,OAAO,EACP,KAAK,EACL,KAAK,QAAQ,GACd,MAAM,gBAAgB,CAAC;AAExB,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AAE7C,MAAM,WAAW,OAAO;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC;IACpB,IAAI,CAAC,EAA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ropy, fnv1a, } from './detectors.js';
3
+ function resolveDetectors(opts) {
4
+ const all = [...DETECTORS, ...(opts.custom ?? [])];
5
+ if (opts.only?.length) {
6
+ const byId = new Map(all.map((d) => [d.id, d]));
7
+ return opts.only.map((id) => byId.get(id)).filter((d) => !!d);
8
+ }
9
+ const disabled = new Set(opts.disable ?? []);
10
+ const enabled = new Set(opts.enable ?? []);
11
+ return all.filter((d) => (d.default || enabled.has(d.id)) && !disabled.has(d.id));
12
+ }
13
+ function keyMatcher(opts) {
14
+ const rk = opts.redactKeys;
15
+ if (rk === false)
16
+ return () => false;
17
+ if (rk instanceof RegExp)
18
+ return (k) => rk.test(k);
19
+ if (Array.isArray(rk)) {
20
+ const set = new Set(rk.map((s) => s.toLowerCase()));
21
+ return (k) => set.has(k.toLowerCase());
22
+ }
23
+ return (k) => SENSITIVE_KEY_RE.test(k);
24
+ }
25
+ function allowMatcher(opts) {
26
+ const a = opts.allow;
27
+ if (!a)
28
+ return () => false;
29
+ if (a instanceof RegExp)
30
+ return (v) => a.test(v);
31
+ const set = new Set(a);
32
+ return (v) => set.has(v);
33
+ }
34
+ function makeReplacer(opts) {
35
+ const salt = opts.hashSalt ?? '';
36
+ const mask = opts.mask;
37
+ const mode = opts.mode ?? 'mask';
38
+ return (value, det) => {
39
+ if (typeof mask === 'string')
40
+ return mask;
41
+ if (typeof mask === 'function')
42
+ return mask({ value, detector: det });
43
+ if (mode === 'label')
44
+ return `[REDACTED:${det.id}]`;
45
+ if (mode === 'hash')
46
+ return `${det.id}_${fnv1a(salt + value)}`;
47
+ return det.mask ? det.mask(value) : '***';
48
+ };
49
+ }
50
+ function withGlobal(re) {
51
+ return re.flags.includes('g') ? re : new RegExp(re.source, re.flags + 'g');
52
+ }
53
+ function scanString(text, dets, allow) {
54
+ const hits = [];
55
+ for (const det of dets) {
56
+ const re = withGlobal(det.pattern);
57
+ re.lastIndex = 0;
58
+ let m;
59
+ while ((m = re.exec(text)) !== null) {
60
+ if (m.index === re.lastIndex)
61
+ re.lastIndex++;
62
+ const value = m[0];
63
+ if (!value)
64
+ continue;
65
+ if (det.validate && !det.validate(value))
66
+ continue;
67
+ if (allow(value))
68
+ continue;
69
+ hits.push({
70
+ detector: det.id,
71
+ label: det.label,
72
+ why: det.why,
73
+ value,
74
+ start: m.index,
75
+ end: m.index + value.length,
76
+ det,
77
+ });
78
+ }
79
+ }
80
+ hits.sort((a, b) => a.start - b.start || b.end - b.start - (a.end - a.start));
81
+ const kept = [];
82
+ let lastEnd = -1;
83
+ for (const h of hits) {
84
+ if (h.start >= lastEnd) {
85
+ kept.push(h);
86
+ lastEnd = h.end;
87
+ }
88
+ }
89
+ return kept;
90
+ }
91
+ function redactString(text, dets, allow, replace) {
92
+ const hits = scanString(text, dets, allow);
93
+ if (!hits.length)
94
+ return text;
95
+ let out = '';
96
+ let cursor = 0;
97
+ for (const h of hits) {
98
+ out += text.slice(cursor, h.start);
99
+ out += replace(h.value, h.det);
100
+ cursor = h.end;
101
+ }
102
+ return out + text.slice(cursor);
103
+ }
104
+ export function redact(input, opts = {}) {
105
+ const dets = resolveDetectors(opts);
106
+ const allow = allowMatcher(opts);
107
+ const replace = makeReplacer(opts);
108
+ const matchKey = keyMatcher(opts);
109
+ const walk = (value) => {
110
+ if (typeof value === 'string')
111
+ return redactString(value, dets, allow, replace);
112
+ if (Array.isArray(value))
113
+ return value.map(walk);
114
+ if (value && typeof value === 'object') {
115
+ const out = {};
116
+ for (const [k, v] of Object.entries(value)) {
117
+ if (typeof v === 'string' && matchKey(k) && !allow(v)) {
118
+ out[k] = replace(v, SENSITIVE_KEY_DETECTOR);
119
+ }
120
+ else {
121
+ out[k] = walk(v);
122
+ }
123
+ }
124
+ return out;
125
+ }
126
+ return value;
127
+ };
128
+ return walk(input);
129
+ }
130
+ export function scan(input, opts = {}) {
131
+ const dets = resolveDetectors(opts);
132
+ const allow = allowMatcher(opts);
133
+ const matchKey = keyMatcher(opts);
134
+ const out = [];
135
+ const push = (h, path) => {
136
+ const { det, ...f } = h;
137
+ out.push(path ? { ...f, path } : f);
138
+ };
139
+ const walk = (value, path) => {
140
+ if (typeof value === 'string') {
141
+ for (const h of scanString(value, dets, allow))
142
+ push(h, path || undefined);
143
+ }
144
+ else if (Array.isArray(value)) {
145
+ value.forEach((v, i) => walk(v, `${path}[${i}]`));
146
+ }
147
+ else if (value && typeof value === 'object') {
148
+ for (const [k, v] of Object.entries(value)) {
149
+ const child = path ? `${path}.${k}` : k;
150
+ if (typeof v === 'string' && matchKey(k) && !allow(v)) {
151
+ out.push({
152
+ detector: 'sensitive_key',
153
+ label: 'Sensitive field',
154
+ why: `Value stored under a sensitive field name ("${k}").`,
155
+ value: v,
156
+ path: child,
157
+ });
158
+ }
159
+ else {
160
+ walk(v, child);
161
+ }
162
+ }
163
+ }
164
+ };
165
+ walk(input, '');
166
+ return out;
167
+ }
168
+ export function isClean(input, opts = {}) {
169
+ return scan(input, opts).length === 0;
170
+ }
171
+ export function summary(input, opts = {}) {
172
+ const byDetector = {};
173
+ const findings = scan(input, opts);
174
+ for (const f of findings)
175
+ byDetector[f.detector] = (byDetector[f.detector] ?? 0) + 1;
176
+ return { total: findings.length, byDetector };
177
+ }
178
+ export function createRedactor(opts = {}) {
179
+ return {
180
+ redact: (input) => redact(input, opts),
181
+ scan: (input) => scan(input, opts),
182
+ isClean: (input) => isClean(input, opts),
183
+ summary: (input) => summary(input, opts),
184
+ };
185
+ }
186
+ export function wrapConsole(opts = {}, target = console) {
187
+ const sink = target;
188
+ const methods = ['log', 'info', 'warn', 'error', 'debug'];
189
+ const original = new Map();
190
+ for (const name of methods) {
191
+ const fn = sink[name].bind(target);
192
+ original.set(name, fn);
193
+ sink[name] = (...args) => fn(...args.map((a) => redact(a, opts)));
194
+ }
195
+ return () => {
196
+ for (const [name, fn] of original)
197
+ sink[name] = fn;
198
+ };
199
+ }
200
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts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QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACvB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAe,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IAC/E,CAAC;IACD,OAAO,GAAG,EAAE;QACV,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,QAAQ;YAAE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;IACrD,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { Transform } from 'node:stream';
2
+ import { type RedactOptions } from './index.js';
3
+ export declare function redactStream(opts?: RedactOptions): Transform;
4
+ //# sourceMappingURL=stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAU,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAExD,wBAAgB,YAAY,CAAC,IAAI,GAAE,aAAkB,GAAG,SAAS,CAgBhE"}
package/dist/stream.js ADDED
@@ -0,0 +1,20 @@
1
+ import { Transform } from 'node:stream';
2
+ import { redact } from './index.js';
3
+ export function redactStream(opts = {}) {
4
+ let carry = '';
5
+ const flushLines = (text, final) => {
6
+ const parts = (carry + text).split('\n');
7
+ carry = final ? '' : parts.pop() ?? '';
8
+ return parts.map((line) => redact(line, opts)).join('\n');
9
+ };
10
+ return new Transform({
11
+ transform(chunk, _enc, cb) {
12
+ const out = flushLines(chunk.toString(), false);
13
+ cb(null, out.length ? out + '\n' : '');
14
+ },
15
+ flush(cb) {
16
+ cb(null, carry ? redact(carry, opts) : '');
17
+ },
18
+ });
19
+ }
20
+ //# sourceMappingURL=stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.js","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,MAAM,EAAsB,MAAM,YAAY,CAAC;AAExD,MAAM,UAAU,YAAY,CAAC,OAAsB,EAAE;IACnD,IAAI,KAAK,GAAG,EAAE,CAAC;IACf,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,KAAc,EAAU,EAAE;QAC1D,MAAM,KAAK,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACzC,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;QACvC,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5D,CAAC,CAAC;IACF,OAAO,IAAI,SAAS,CAAC;QACnB,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YACvB,MAAM,GAAG,GAAG,UAAU,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,KAAK,CAAC,CAAC;YAChD,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACzC,CAAC;QACD,KAAK,CAAC,EAAE;YACN,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAC7C,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
package/package.json ADDED
@@ -0,0 +1,100 @@
1
+ {
2
+ "name": "flare-redact",
3
+ "version": "0.2.0",
4
+ "description": "Hide secrets & PII in logs and text before they leak. Zero dependencies, ReDoS-safe patterns, tells you what it found and why.",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "./stream": {
15
+ "types": "./dist/stream.d.ts",
16
+ "default": "./dist/stream.js"
17
+ }
18
+ },
19
+ "bin": {
20
+ "flare-redact": "bin/flare-redact.mjs"
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "bin",
25
+ "README.md",
26
+ "LICENSE"
27
+ ],
28
+ "scripts": {
29
+ "build": "tsc",
30
+ "test": "npm run build && node --test",
31
+ "prepublishOnly": "npm run build"
32
+ },
33
+ "keywords": [
34
+ "redact",
35
+ "redaction",
36
+ "redactor",
37
+ "secrets",
38
+ "secret",
39
+ "secret-detection",
40
+ "secret-scanning",
41
+ "pii",
42
+ "pii-redaction",
43
+ "mask",
44
+ "masking",
45
+ "data-masking",
46
+ "sanitize",
47
+ "sanitization",
48
+ "scrub",
49
+ "anonymize",
50
+ "pseudonymize",
51
+ "obfuscate",
52
+ "censor",
53
+ "log",
54
+ "logs",
55
+ "logging",
56
+ "logger",
57
+ "log-redaction",
58
+ "security",
59
+ "privacy",
60
+ "sensitive-data",
61
+ "dlp",
62
+ "gdpr",
63
+ "pci",
64
+ "pci-dss",
65
+ "compliance",
66
+ "api-key",
67
+ "apikey",
68
+ "token",
69
+ "jwt",
70
+ "credentials",
71
+ "password",
72
+ "redos",
73
+ "zero-dependency",
74
+ "typescript",
75
+ "cli"
76
+ ],
77
+ "author": {
78
+ "name": "Umud Hasanli",
79
+ "url": "https://github.com/umudhasanli"
80
+ },
81
+ "license": "MIT",
82
+ "publishConfig": {
83
+ "access": "public"
84
+ },
85
+ "repository": {
86
+ "type": "git",
87
+ "url": "git+https://github.com/umudhasanli/flare-redact.git"
88
+ },
89
+ "homepage": "https://github.com/umudhasanli/flare-redact#readme",
90
+ "bugs": {
91
+ "url": "https://github.com/umudhasanli/flare-redact/issues"
92
+ },
93
+ "engines": {
94
+ "node": ">=18"
95
+ },
96
+ "devDependencies": {
97
+ "@types/node": "^20.0.0",
98
+ "typescript": "^5.6.0"
99
+ }
100
+ }