flare-redact 1.11.0 → 1.12.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 +115 -0
- package/README.md +3 -3
- package/SECURITY.md +1 -1
- package/dist/audit.d.ts.map +1 -1
- package/dist/audit.js +3 -2
- package/dist/audit.js.map +1 -1
- package/dist/detectors.d.ts +1 -2
- package/dist/detectors.d.ts.map +1 -1
- package/dist/detectors.js +8 -4
- package/dist/detectors.js.map +1 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +24 -6
- package/dist/engine.js.map +1 -1
- package/dist/extra.d.ts.map +1 -1
- package/dist/extra.js +3 -1
- package/dist/extra.js.map +1 -1
- package/dist/fold.d.ts +22 -0
- package/dist/fold.d.ts.map +1 -0
- package/dist/fold.js +140 -0
- package/dist/fold.js.map +1 -0
- package/dist/help.d.ts.map +1 -1
- package/dist/help.js +13 -9
- package/dist/help.js.map +1 -1
- package/dist/i18n.d.ts +10 -0
- package/dist/i18n.d.ts.map +1 -1
- package/dist/i18n.js +18 -1
- package/dist/i18n.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/pack.d.ts +2 -2
- package/dist/pack.d.ts.map +1 -1
- package/dist/pack.js +9 -7
- package/dist/pack.js.map +1 -1
- package/dist/pino.d.ts +18 -0
- package/dist/pino.d.ts.map +1 -1
- package/dist/pino.js +61 -0
- package/dist/pino.js.map +1 -1
- package/dist/printf.d.ts +8 -0
- package/dist/printf.d.ts.map +1 -0
- package/dist/printf.js +49 -0
- package/dist/printf.js.map +1 -0
- package/dist/terms.d.ts +4 -4
- package/dist/terms.d.ts.map +1 -1
- package/dist/terms.js +22 -13
- package/dist/terms.js.map +1 -1
- package/dist/winston.d.ts.map +1 -1
- package/dist/winston.js +14 -0
- package/dist/winston.js.map +1 -1
- package/docs/guide.md +43 -16
- package/package.json +1 -1
- package/spec/SPEC.md +142 -51
- package/spec/conformance/README.md +7 -4
- package/spec/conformance/cases.json +22 -0
- package/spec/conformance/expected.json +378 -0
- package/spec/detectors.json +4 -4
- package/spec/detectors.schema.json +1 -1
package/dist/pino.js
CHANGED
|
@@ -9,14 +9,75 @@ import { redact } from './index.js';
|
|
|
9
9
|
*
|
|
10
10
|
* const log = pino(pinoRedact());
|
|
11
11
|
* log.info({ user: 'bob@corp.com' }); // → { "user": "b***@***" }
|
|
12
|
+
*
|
|
13
|
+
* pino hands `formatters.log` only the merging object, never the message, so
|
|
14
|
+
* one formatter is not enough:
|
|
15
|
+
*
|
|
16
|
+
* - `hooks.logMethod` redacts the message, the printf arguments it
|
|
17
|
+
* interpolates and an Error passed first (whose message becomes `msg`);
|
|
18
|
+
* - `formatters.log` redacts the merging object after the mixin and the
|
|
19
|
+
* serializers ran, and `formatters.bindings` the base bindings;
|
|
20
|
+
* - pino does not run `formatters.bindings` for `child()` bindings, so a
|
|
21
|
+
* logger whose bindings hold something sensitive has its whole line redacted
|
|
22
|
+
* in `hooks.streamWrite`, where pino has that hook. That is checked once per
|
|
23
|
+
* logger, so other loggers pay nothing. `setBindings()` after a logger's
|
|
24
|
+
* first line is not checked again.
|
|
12
25
|
*/
|
|
13
26
|
export function pinoRedact(opts = {}) {
|
|
27
|
+
const sensitiveBindings = new WeakMap();
|
|
28
|
+
let redactLine = false;
|
|
29
|
+
const bindingsNeedRedaction = (logger) => {
|
|
30
|
+
if (typeof logger !== 'object' || logger === null)
|
|
31
|
+
return false;
|
|
32
|
+
const known = sensitiveBindings.get(logger);
|
|
33
|
+
if (known !== undefined)
|
|
34
|
+
return known;
|
|
35
|
+
const read = logger.bindings;
|
|
36
|
+
let sensitive = false;
|
|
37
|
+
if (typeof read === 'function') {
|
|
38
|
+
const bindings = read.call(logger);
|
|
39
|
+
sensitive = JSON.stringify(redact(bindings, opts)) !== JSON.stringify(bindings);
|
|
40
|
+
}
|
|
41
|
+
sensitiveBindings.set(logger, sensitive);
|
|
42
|
+
return sensitive;
|
|
43
|
+
};
|
|
14
44
|
return {
|
|
45
|
+
hooks: {
|
|
46
|
+
logMethod(args, method) {
|
|
47
|
+
// A plain object first is the merging object: formatters.log covers it,
|
|
48
|
+
// so it is not scanned twice.
|
|
49
|
+
const safe = args.map((arg, index) => (index === 0 && isMergingObject(arg) ? arg : redact(arg, opts)));
|
|
50
|
+
const previous = redactLine;
|
|
51
|
+
redactLine = bindingsNeedRedaction(this);
|
|
52
|
+
try {
|
|
53
|
+
return method.apply(this, safe);
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
redactLine = previous;
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
streamWrite(line) {
|
|
60
|
+
if (!redactLine)
|
|
61
|
+
return line;
|
|
62
|
+
try {
|
|
63
|
+
return `${JSON.stringify(redact(JSON.parse(line), opts))}\n`;
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return `${JSON.stringify({ msg: '[REDACTION FAILED]' })}\n`;
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
},
|
|
15
70
|
formatters: {
|
|
71
|
+
bindings(bindings) {
|
|
72
|
+
return redact(bindings, opts);
|
|
73
|
+
},
|
|
16
74
|
log(object) {
|
|
17
75
|
return redact(object, opts);
|
|
18
76
|
},
|
|
19
77
|
},
|
|
20
78
|
};
|
|
21
79
|
}
|
|
80
|
+
function isMergingObject(value) {
|
|
81
|
+
return typeof value === 'object' && value !== null && !(value instanceof Error);
|
|
82
|
+
}
|
|
22
83
|
//# sourceMappingURL=pino.js.map
|
package/dist/pino.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pino.js","sourceRoot":"","sources":["../src/pino.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAsB,MAAM,YAAY,CAAC;AAExD
|
|
1
|
+
{"version":3,"file":"pino.js","sourceRoot":"","sources":["../src/pino.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MA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CAAC,CAAC,CAAC,CAAC;gBACvG,MAAM,QAAQ,GAAG,UAAU,CAAC;gBAC5B,UAAU,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;gBACzC,IAAI,CAAC;oBACH,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBAClC,CAAC;wBAAS,CAAC;oBACT,UAAU,GAAG,QAAQ,CAAC;gBACxB,CAAC;YACH,CAAC;YACD,WAAW,CAAC,IAAY;gBACtB,IAAI,CAAC,UAAU;oBAAE,OAAO,IAAI,CAAC;gBAC7B,IAAI,CAAC;oBACH,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC;gBAC/D,CAAC;gBAAC,MAAM,CAAC;oBACP,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,oBAAoB,EAAE,CAAC,IAAI,CAAC;gBAC9D,CAAC;YACH,CAAC;SACF;QACD,UAAU,EAAE;YACV,QAAQ,CAAC,QAAiC;gBACxC,OAAO,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YAChC,CAAC;YACD,GAAG,CAAC,MAA+B;gBACjC,OAAO,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YAC9B,CAAC;SACF;KACF,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,KAAc;IACrC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC;AAClF,CAAC"}
|
package/dist/printf.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `console.log('%s', value)` calls a user-defined `toString()` while it
|
|
3
|
+
* formats, after the arguments were redacted, so the text that method returns
|
|
4
|
+
* would be printed as it is. Call it first, for exactly the arguments a `%s`
|
|
5
|
+
* consumes, so the redactor sees the text that will be printed.
|
|
6
|
+
*/
|
|
7
|
+
export declare function printfStrings(args: unknown[]): unknown[];
|
|
8
|
+
//# sourceMappingURL=printf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"printf.d.ts","sourceRoot":"","sources":["../src/printf.ts"],"names":[],"mappings":"AAeA;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,CAuBxD"}
|
package/dist/printf.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Shared by wrapConsole and shadowConsole. Not exported from the package.
|
|
2
|
+
const BUILT_IN_TO_STRING = new Set([
|
|
3
|
+
Object.prototype.toString,
|
|
4
|
+
Array.prototype.toString,
|
|
5
|
+
Error.prototype.toString,
|
|
6
|
+
Date.prototype.toString,
|
|
7
|
+
RegExp.prototype.toString,
|
|
8
|
+
Function.prototype.toString,
|
|
9
|
+
Number.prototype.toString,
|
|
10
|
+
Boolean.prototype.toString,
|
|
11
|
+
String.prototype.toString,
|
|
12
|
+
Symbol.prototype.toString,
|
|
13
|
+
BigInt.prototype.toString,
|
|
14
|
+
]);
|
|
15
|
+
/**
|
|
16
|
+
* `console.log('%s', value)` calls a user-defined `toString()` while it
|
|
17
|
+
* formats, after the arguments were redacted, so the text that method returns
|
|
18
|
+
* would be printed as it is. Call it first, for exactly the arguments a `%s`
|
|
19
|
+
* consumes, so the redactor sees the text that will be printed.
|
|
20
|
+
*/
|
|
21
|
+
export function printfStrings(args) {
|
|
22
|
+
const [format] = args;
|
|
23
|
+
if (typeof format !== 'string' || args.length < 2 || !format.includes('%s'))
|
|
24
|
+
return args;
|
|
25
|
+
const out = args.slice();
|
|
26
|
+
let next = 1;
|
|
27
|
+
for (let i = 0; i < format.length - 1 && next < args.length; i++) {
|
|
28
|
+
if (format[i] !== '%')
|
|
29
|
+
continue;
|
|
30
|
+
const spec = format.charAt(++i);
|
|
31
|
+
if (!'sdifjoOc'.includes(spec))
|
|
32
|
+
continue; // %% and unknown specifiers take no argument
|
|
33
|
+
const value = args[next];
|
|
34
|
+
if (spec === 's' && typeof value === 'object' && value !== null) {
|
|
35
|
+
const toString = value.toString;
|
|
36
|
+
if (typeof toString === 'function' && !BUILT_IN_TO_STRING.has(toString)) {
|
|
37
|
+
try {
|
|
38
|
+
out[next] = String(value);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// A throwing toString prints nothing secret; leave it to the console.
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
next++;
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=printf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"printf.js","sourceRoot":"","sources":["../src/printf.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAU;IAC1C,MAAM,CAAC,SAAS,CAAC,QAAQ;IACzB,KAAK,CAAC,SAAS,CAAC,QAAQ;IACxB,KAAK,CAAC,SAAS,CAAC,QAAQ;IACxB,IAAI,CAAC,SAAS,CAAC,QAAQ;IACvB,MAAM,CAAC,SAAS,CAAC,QAAQ;IACzB,QAAQ,CAAC,SAAS,CAAC,QAAQ;IAC3B,MAAM,CAAC,SAAS,CAAC,QAAQ;IACzB,OAAO,CAAC,SAAS,CAAC,QAAQ;IAC1B,MAAM,CAAC,SAAS,CAAC,QAAQ;IACzB,MAAM,CAAC,SAAS,CAAC,QAAQ;IACzB,MAAM,CAAC,SAAS,CAAC,QAAQ;CAC1B,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,IAAe;IAC3C,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IACtB,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IACzF,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;IACzB,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACjE,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG;YAAE,SAAS;QAChC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;QAChC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,SAAS,CAAC,6CAA6C;QACvF,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;QACzB,IAAI,IAAI,KAAK,GAAG,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YAChE,MAAM,QAAQ,GAAI,KAAgC,CAAC,QAAQ,CAAC;YAC5D,IAAI,OAAO,QAAQ,KAAK,UAAU,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACxE,IAAI,CAAC;oBACH,GAAG,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;gBAC5B,CAAC;gBAAC,MAAM,CAAC;oBACP,sEAAsE;gBACxE,CAAC;YACH,CAAC;QACH,CAAC;QACD,IAAI,EAAE,CAAC;IACT,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/dist/terms.d.ts
CHANGED
|
@@ -9,10 +9,10 @@ export declare function normalizeTerms(input: TermSpec[] | Record<string, string
|
|
|
9
9
|
}>;
|
|
10
10
|
/**
|
|
11
11
|
* Build a detector from a user-supplied word/phrase list. Terms are matched
|
|
12
|
-
* literally
|
|
13
|
-
* names and codewords in any language.
|
|
14
|
-
* reversible placeholders; in a one-way
|
|
15
|
-
* text (or `***`).
|
|
12
|
+
* literally, longest first (in characters; ties keep the caller's order), with
|
|
13
|
+
* Unicode-aware boundaries, so it works for names and codewords in any language.
|
|
14
|
+
* In a vault/session the matches get reversible placeholders; in a one-way
|
|
15
|
+
* `redact` they use each term's `replace` text (or `***`).
|
|
16
16
|
*/
|
|
17
17
|
export declare function buildTermsDetector(input: TermSpec[] | Record<string, string> | undefined, caseSensitive?: boolean): Detector | null;
|
|
18
18
|
//# sourceMappingURL=terms.d.ts.map
|
package/dist/terms.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"terms.d.ts","sourceRoot":"","sources":["../src/terms.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"terms.d.ts","sourceRoot":"","sources":["../src/terms.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG/C,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAInE,wBAAgB,cAAc,CAC5B,KAAK,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GACrD,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAM3C;AASD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EACtD,aAAa,UAAQ,GACpB,QAAQ,GAAG,IAAI,CAyBjB"}
|
package/dist/terms.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { expandDottedI } from './fold.js';
|
|
1
2
|
const escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
2
3
|
export function normalizeTerms(input) {
|
|
3
4
|
if (!input)
|
|
@@ -7,31 +8,39 @@ export function normalizeTerms(input) {
|
|
|
7
8
|
: Object.entries(input).map(([term, replace]) => ({ term, replace }));
|
|
8
9
|
return list.filter((t) => t.term && t.term.length > 0);
|
|
9
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* A term must not touch a letter, a combining mark, a number or `_` on either
|
|
13
|
+
* side (SPEC §9). Marks count as part of a word, so `राज` does not match inside
|
|
14
|
+
* `राजा` and `cafe` does not match a decomposed `café`.
|
|
15
|
+
*/
|
|
16
|
+
const WORD = '[\\p{L}\\p{M}\\p{N}_]';
|
|
10
17
|
/**
|
|
11
18
|
* Build a detector from a user-supplied word/phrase list. Terms are matched
|
|
12
|
-
* literally
|
|
13
|
-
* names and codewords in any language.
|
|
14
|
-
* reversible placeholders; in a one-way
|
|
15
|
-
* text (or `***`).
|
|
19
|
+
* literally, longest first (in characters; ties keep the caller's order), with
|
|
20
|
+
* Unicode-aware boundaries, so it works for names and codewords in any language.
|
|
21
|
+
* In a vault/session the matches get reversible placeholders; in a one-way
|
|
22
|
+
* `redact` they use each term's `replace` text (or `***`).
|
|
16
23
|
*/
|
|
17
24
|
export function buildTermsDetector(input, caseSensitive = false) {
|
|
18
25
|
const list = normalizeTerms(input);
|
|
19
26
|
if (!list.length)
|
|
20
27
|
return null;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
const pattern = new RegExp(`(
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
// Array.prototype.sort is stable, so equal lengths keep the caller's order.
|
|
29
|
+
const ordered = [...list].sort((a, b) => [...b.term].length - [...a.term].length);
|
|
30
|
+
const flags = caseSensitive ? 'u' : 'iu';
|
|
31
|
+
const source = (term) => (caseSensitive ? escapeRe(term) : expandDottedI(escapeRe(term)));
|
|
32
|
+
const alt = ordered.map((t) => source(t.term)).join('|');
|
|
33
|
+
const pattern = new RegExp(`(?<!${WORD})(?:${alt})(?!${WORD})`, `g${flags}`);
|
|
34
|
+
// The replacement belongs to the first term (in matching order) that matches
|
|
35
|
+
// the text exactly, which is the alternative the scan above took.
|
|
36
|
+
const exact = ordered.map((t) => ({ re: new RegExp(`^(?:${source(t.term)})$`, flags), replace: t.replace ?? '***' }));
|
|
37
|
+
const replacementFor = (match) => exact.find((t) => t.re.test(match))?.replace ?? '***';
|
|
29
38
|
return {
|
|
30
39
|
id: 'custom_term',
|
|
31
40
|
label: 'Custom term',
|
|
32
41
|
why: 'A term you configured as sensitive.',
|
|
33
42
|
pattern,
|
|
34
|
-
mask:
|
|
43
|
+
mask: replacementFor,
|
|
35
44
|
default: true,
|
|
36
45
|
tags: ['custom'],
|
|
37
46
|
};
|
package/dist/terms.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"terms.js","sourceRoot":"","sources":["../src/terms.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"terms.js","sourceRoot":"","sources":["../src/terms.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAI1C,MAAM,QAAQ,GAAG,CAAC,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AAEjF,MAAM,UAAU,cAAc,CAC5B,KAAsD;IAEtD,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IACtB,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAC/B,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,E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version":3,"file":"winston.d.ts","sourceRoot":"","sources":["../src/winston.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAExD;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,IAAI,GAAE,aAAkB,IAC5C,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAiBhE"}
|
package/dist/winston.js
CHANGED
|
@@ -17,7 +17,21 @@ export function winstonRedact(opts = {}) {
|
|
|
17
17
|
for (const key of Object.keys(info)) {
|
|
18
18
|
info[key] = redact(info[key], opts);
|
|
19
19
|
}
|
|
20
|
+
// Formats placed after this one read two more things: format.splat()
|
|
21
|
+
// interpolates and merges the raw arguments kept under Symbol.for('splat'),
|
|
22
|
+
// and format.errors() reads the message and stack an Error keeps as
|
|
23
|
+
// non-enumerable properties.
|
|
24
|
+
const meta = info;
|
|
25
|
+
if (Array.isArray(meta[SPLAT]))
|
|
26
|
+
meta[SPLAT] = redact(meta[SPLAT], opts);
|
|
27
|
+
if (info instanceof Error) {
|
|
28
|
+
for (const key of ['message', 'stack']) {
|
|
29
|
+
if (typeof info[key] === 'string')
|
|
30
|
+
info[key] = redact(info[key], opts);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
20
33
|
return info;
|
|
21
34
|
};
|
|
22
35
|
}
|
|
36
|
+
const SPLAT = Symbol.for('splat');
|
|
23
37
|
//# sourceMappingURL=winston.js.map
|
package/dist/winston.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"winston.js","sourceRoot":"","sources":["../src/winston.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAsB,MAAM,YAAY,CAAC;AAExD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAAC,OAAsB,EAAE;IACpD,OAAO,CAAC,IAA6B,EAA2B,EAAE;QAChE,KAAK,MAAM,GAAG,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;AAED,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC"}
|
package/docs/guide.md
CHANGED
|
@@ -10,7 +10,7 @@ version. Coding assistants can read the same API in condensed form at
|
|
|
10
10
|
- [Install](#install)
|
|
11
11
|
- [Practical guides](https://flare-collection.github.io/flare-redact/guides/)
|
|
12
12
|
- [Runnable examples](#runnable-examples)
|
|
13
|
-
- [Python, Go, and
|
|
13
|
+
- [Python, Go, Rust, Java and .NET](#python-go-rust-java-and-net)
|
|
14
14
|
- [Fluent Bit](#fluent-bit)
|
|
15
15
|
- [The sidecar gateway](#the-sidecar-gateway)
|
|
16
16
|
- [Redact anything](#redact-anything)
|
|
@@ -160,21 +160,25 @@ Clone the repository and run these small applications locally:
|
|
|
160
160
|
|
|
161
161
|
Run `npm run build` and install an example's dependencies before its first run.
|
|
162
162
|
|
|
163
|
-
## Python, Go, and
|
|
163
|
+
## Python, Go, Rust, Java and .NET
|
|
164
|
+
|
|
165
|
+
<a id="python-go-and-rust"></a>
|
|
164
166
|
|
|
165
167
|
The people who most need to keep data out of a prompt are usually not writing
|
|
166
|
-
JavaScript. There are now
|
|
168
|
+
JavaScript. There are now six engines, and they are not six ports: they all
|
|
167
169
|
execute the same [FRS-1 detector specification](../spec/SPEC.md) and are held to the
|
|
168
170
|
same [conformance corpus](../spec/conformance/), so a policy written once produces
|
|
169
171
|
identical output in every one of them.
|
|
170
172
|
|
|
171
173
|
Each engine is its own package. Installing `flare-redact` from npm gives you the
|
|
172
|
-
JavaScript engine and nothing else: no Python, no Go, no Rust,
|
|
173
|
-
dependencies of any kind.
|
|
174
|
+
JavaScript engine and nothing else: no Python, no Go, no Rust, no JVM, no .NET,
|
|
175
|
+
and no dependencies of any kind.
|
|
174
176
|
|
|
175
177
|
| | Install | Docs |
|
|
176
178
|
|---|---|---|
|
|
177
179
|
| **Go** | `go get github.com/flare-collection/flare-redact/sdk/go` | [`sdk/go`](../sdk/go) |
|
|
180
|
+
| **Java** | `io.github.flare-collection:flare-redact` on Maven Central | [`sdk/java`](../sdk/java) |
|
|
181
|
+
| **.NET** | `dotnet add package FlareRedact` | [`sdk/dotnet`](../sdk/dotnet) |
|
|
178
182
|
| **Python** | `pip install flare-redact` | [`sdk/python`](../sdk/python) |
|
|
179
183
|
| **Rust** | `cargo add flare-redact` | [`sdk/rust`](../sdk/rust) |
|
|
180
184
|
|
|
@@ -183,11 +187,11 @@ first release after 1.9.1. Until it lands, or to pin a tag, install them from
|
|
|
183
187
|
this repository:
|
|
184
188
|
|
|
185
189
|
```bash
|
|
186
|
-
pip install "flare-redact @ git+https://github.com/flare-collection/flare-redact@v1.
|
|
190
|
+
pip install "flare-redact @ git+https://github.com/flare-collection/flare-redact@v1.12.1#subdirectory=sdk/python"
|
|
187
191
|
```
|
|
188
192
|
|
|
189
193
|
```toml
|
|
190
|
-
flare-redact = { git = "https://github.com/flare-collection/flare-redact", tag = "v1.
|
|
194
|
+
flare-redact = { git = "https://github.com/flare-collection/flare-redact", tag = "v1.12.1" }
|
|
191
195
|
```
|
|
192
196
|
|
|
193
197
|
```python
|
|
@@ -208,19 +212,34 @@ let policy = Policy::compile(Options::new().enable(["pii"]))?;
|
|
|
208
212
|
let safe = policy.redact_str("contact ada@example.com")?;
|
|
209
213
|
```
|
|
210
214
|
|
|
211
|
-
|
|
212
|
-
|
|
215
|
+
```java
|
|
216
|
+
Policy policy = Policy.compile(RedactOptions.builder().enable("pii").build());
|
|
217
|
+
String safe = policy.redactString("contact ada@example.com");
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
```csharp
|
|
221
|
+
builder.Logging.AddConsole().AddFlareRedact(new RedactOptions { Enable = { "pii" } });
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Maven Central and NuGet packages for Java and .NET are on the way. Until they
|
|
225
|
+
are published, build `sdk/java` with `mvn install` and `sdk/dotnet` with
|
|
226
|
+
`dotnet pack`.
|
|
227
|
+
|
|
228
|
+
Each SDK is dependency-light on purpose (Python and Go use the standard library
|
|
229
|
+
only, the Java and .NET cores have no dependencies at all, Rust is `regex` plus
|
|
230
|
+
`serde`) because a redaction library
|
|
213
231
|
that expands your dependency tree is a security library that widened your attack
|
|
214
232
|
surface. Each also ships the integrations its ecosystem actually uses: a
|
|
215
233
|
`logging` filter and formatter, OpenAI/Anthropic client wrappers and
|
|
216
234
|
[pandas, Polars and DuckDB](#clean-data-frames-and-sql-tables) helpers in
|
|
217
|
-
Python, an `slog.Handler` and an `http.RoundTripper` in Go
|
|
235
|
+
Python, an `slog.Handler` and an `http.RoundTripper` in Go, Logback and Log4j 2
|
|
236
|
+
in Java, and Serilog and `Microsoft.Extensions.Logging` in .NET.
|
|
218
237
|
|
|
219
|
-
Drift is the reason this is a specification and not
|
|
220
|
-
maintained in
|
|
238
|
+
Drift is the reason this is a specification and not six ports. Detection logic
|
|
239
|
+
maintained in six hand-written copies diverges within a release or two, and a
|
|
221
240
|
redactor that behaves differently per language is worse than none, because the
|
|
222
241
|
team stops being able to reason about what leaves the process. The corpus runs in
|
|
223
|
-
all
|
|
242
|
+
all six test suites; a change that makes them disagree fails CI.
|
|
224
243
|
|
|
225
244
|
Detectors themselves are data. Write an [FRS-1 pack](../spec/SPEC.md) once and every
|
|
226
245
|
engine loads the same file:
|
|
@@ -995,8 +1014,13 @@ import { pinoRedact } from 'flare-redact/pino';
|
|
|
995
1014
|
|
|
996
1015
|
const log = pino(pinoRedact(policy));
|
|
997
1016
|
log.info({ user: 'bob@corp.com' }); // → {"user":"b***@***"}
|
|
1017
|
+
log.info('dsn %s', process.env.DATABASE_URL); // the message and its arguments too
|
|
998
1018
|
```
|
|
999
1019
|
|
|
1020
|
+
It covers the merging object, the message and its printf arguments, an Error
|
|
1021
|
+
logged on its own, and `child()` bindings. If you build pino's options
|
|
1022
|
+
yourself, spread the result in: `pino({ ...pinoRedact(policy), level: 'debug' })`.
|
|
1023
|
+
|
|
1000
1024
|
**winston**: a format that redacts every field, symbol metadata left intact:
|
|
1001
1025
|
|
|
1002
1026
|
```js
|
|
@@ -1006,6 +1030,9 @@ import { winstonRedact } from 'flare-redact/winston';
|
|
|
1006
1030
|
winston.format.combine(winston.format(winstonRedact(policy))(), winston.format.json());
|
|
1007
1031
|
```
|
|
1008
1032
|
|
|
1033
|
+
It also redacts what `format.splat()` and `format.errors()` read, so it can sit
|
|
1034
|
+
before or after them.
|
|
1035
|
+
|
|
1009
1036
|
**HTTP**: a safe-to-log snapshot of a request; the live request is untouched.
|
|
1010
1037
|
The URL string, query object, params, headers, and body are all sanitized:
|
|
1011
1038
|
|
|
@@ -1310,7 +1337,7 @@ not, as long as Node 20 or newer is on the PATH:
|
|
|
1310
1337
|
```yaml
|
|
1311
1338
|
repos:
|
|
1312
1339
|
- repo: https://github.com/flare-collection/flare-redact
|
|
1313
|
-
rev: v1.
|
|
1340
|
+
rev: v1.12.1
|
|
1314
1341
|
hooks:
|
|
1315
1342
|
- id: flare-redact # only the lines being added, like --staged
|
|
1316
1343
|
```
|
|
@@ -1375,7 +1402,7 @@ reports never echo the matched secret value:
|
|
|
1375
1402
|
with:
|
|
1376
1403
|
node-version: 24
|
|
1377
1404
|
- name: Scan project text files
|
|
1378
|
-
run: npx --yes --package flare-redact@1.
|
|
1405
|
+
run: npx --yes --package flare-redact@1.12.1 flare-redact --scan . --exclude package-lock.json
|
|
1379
1406
|
```
|
|
1380
1407
|
|
|
1381
1408
|
The scan runs on the GitHub runner, reports safe file and source locations, and
|
|
@@ -1592,7 +1619,7 @@ sealVault(vaultOrEntries, password): Promise<SealedVaultV1>
|
|
|
1592
1619
|
openVault(envelope, password): Promise<Array<[placeholder, original]>>
|
|
1593
1620
|
|
|
1594
1621
|
// adapters, each takes the same options object
|
|
1595
|
-
pinoRedact(opts?) // 'flare-redact/pino' → { formatters
|
|
1622
|
+
pinoRedact(opts?) // 'flare-redact/pino' → { hooks, formatters } pino options
|
|
1596
1623
|
winstonRedact(opts?) // 'flare-redact/winston' → a format transform
|
|
1597
1624
|
sentryRedact(opts?) // 'flare-redact/sentry' → { beforeSend, beforeSendTransaction, beforeSendSpan, beforeSendLog, beforeBreadcrumb }
|
|
1598
1625
|
redactSentryEvent(e, opts?) // 'flare-redact/sentry' → one redacted error event or transaction
|
package/package.json
CHANGED