@glubean/redaction 0.1.3 → 0.1.7
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 +158 -0
- package/dist/adapter.d.ts +14 -26
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +26 -96
- package/dist/adapter.js.map +1 -1
- package/dist/compiler.d.ts +47 -0
- package/dist/compiler.d.ts.map +1 -0
- package/dist/compiler.js +178 -0
- package/dist/compiler.js.map +1 -0
- package/dist/defaults.d.ts +21 -11
- package/dist/defaults.d.ts.map +1 -1
- package/dist/defaults.js +192 -59
- package/dist/defaults.js.map +1 -1
- package/dist/engine.d.ts +15 -16
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +13 -26
- package/dist/engine.js.map +1 -1
- package/dist/handlers.d.ts +37 -0
- package/dist/handlers.d.ts.map +1 -0
- package/dist/handlers.js +236 -0
- package/dist/handlers.js.map +1 -0
- package/dist/index.d.ts +19 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -13
- package/dist/index.js.map +1 -1
- package/dist/plugins/mod.d.ts +5 -12
- package/dist/plugins/mod.d.ts.map +1 -1
- package/dist/plugins/mod.js +5 -30
- package/dist/plugins/mod.js.map +1 -1
- package/dist/plugins/sensitive-keys.d.ts +10 -5
- package/dist/plugins/sensitive-keys.d.ts.map +1 -1
- package/dist/plugins/sensitive-keys.js +27 -9
- package/dist/plugins/sensitive-keys.js.map +1 -1
- package/dist/types.d.ts +134 -82
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +3 -5
- package/dist/types.js.map +1 -1
- package/package.json +4 -1
package/dist/defaults.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EACf,yBAAyB,EAC1B,MAAM,YAAY,CAAC;AAIpB;;;;;GAKG;AACH,eAAO,MAAM,cAAc,EAAE,yBAAyB,EAuJrD,CAAC;AAIF;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAClC,MAAM,EACN;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAkClC,CAAC;AAIF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,EAAE,WAalC,CAAC;AAIF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,EAAE,eAO5B,CAAC"}
|
package/dist/defaults.js
CHANGED
|
@@ -1,41 +1,174 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module defaults
|
|
3
3
|
*
|
|
4
|
-
* Built-in
|
|
5
|
-
*
|
|
4
|
+
* Built-in scope declarations, pattern source strings, and default config.
|
|
5
|
+
*
|
|
6
|
+
* v2: HTTP scopes are declared as data, not as a fixed interface.
|
|
7
|
+
* They use the same shape as external plugin declarations.
|
|
6
8
|
*/
|
|
7
|
-
// ── Built-in
|
|
9
|
+
// ── Built-in HTTP scope declarations ─────────────────────────────────────────
|
|
8
10
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
+
* Built-in scope declarations for HTTP, log, error, assertion, and step events.
|
|
12
|
+
*
|
|
13
|
+
* These are the "http-plugin" built-in contributor — they use the same
|
|
14
|
+
* declaration model as any external plugin.
|
|
11
15
|
*/
|
|
12
|
-
export const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
16
|
+
export const BUILTIN_SCOPES = [
|
|
17
|
+
{
|
|
18
|
+
id: "http.request.headers",
|
|
19
|
+
name: "HTTP request headers",
|
|
20
|
+
event: "trace",
|
|
21
|
+
target: "data.requestHeaders",
|
|
22
|
+
handler: "headers",
|
|
23
|
+
rules: {
|
|
24
|
+
sensitiveKeys: ["authorization", "cookie", "x-api-key", "proxy-authorization"],
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: "http.request.query",
|
|
29
|
+
name: "HTTP request query",
|
|
30
|
+
event: "trace",
|
|
31
|
+
target: "data.url",
|
|
32
|
+
handler: "url-query",
|
|
33
|
+
rules: {
|
|
34
|
+
sensitiveKeys: [
|
|
35
|
+
"token",
|
|
36
|
+
"access_token",
|
|
37
|
+
"refresh_token",
|
|
38
|
+
"api_key",
|
|
39
|
+
"apikey",
|
|
40
|
+
"api-key",
|
|
41
|
+
"secret",
|
|
42
|
+
"password",
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
id: "http.request.body",
|
|
48
|
+
name: "HTTP request body",
|
|
49
|
+
event: "trace",
|
|
50
|
+
target: "data.requestBody",
|
|
51
|
+
handler: "json",
|
|
52
|
+
rules: {
|
|
53
|
+
sensitiveKeys: [
|
|
54
|
+
"password",
|
|
55
|
+
"passwd",
|
|
56
|
+
"secret",
|
|
57
|
+
"token",
|
|
58
|
+
"client_secret",
|
|
59
|
+
"client-secret",
|
|
60
|
+
"private_key",
|
|
61
|
+
"privatekey",
|
|
62
|
+
"private-key",
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
id: "http.response.headers",
|
|
68
|
+
name: "HTTP response headers",
|
|
69
|
+
event: "trace",
|
|
70
|
+
target: "data.responseHeaders",
|
|
71
|
+
handler: "headers",
|
|
72
|
+
rules: {
|
|
73
|
+
sensitiveKeys: ["set-cookie"],
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
id: "http.response.body",
|
|
78
|
+
name: "HTTP response body",
|
|
79
|
+
event: "trace",
|
|
80
|
+
target: "data.responseBody",
|
|
81
|
+
handler: "json",
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
id: "log.message",
|
|
85
|
+
name: "Log message",
|
|
86
|
+
event: "log",
|
|
87
|
+
target: "message",
|
|
88
|
+
handler: "raw-string",
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
id: "log.data",
|
|
92
|
+
name: "Log data",
|
|
93
|
+
event: "log",
|
|
94
|
+
target: "data",
|
|
95
|
+
handler: "json",
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
id: "error.message",
|
|
99
|
+
name: "Error message",
|
|
100
|
+
event: "error",
|
|
101
|
+
target: "message",
|
|
102
|
+
handler: "raw-string",
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
id: "error.stack",
|
|
106
|
+
name: "Error stack",
|
|
107
|
+
event: "error",
|
|
108
|
+
target: "stack",
|
|
109
|
+
handler: "raw-string",
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
id: "status.error",
|
|
113
|
+
name: "Status error",
|
|
114
|
+
event: "status",
|
|
115
|
+
target: "error",
|
|
116
|
+
handler: "raw-string",
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
id: "status.stack",
|
|
120
|
+
name: "Status stack",
|
|
121
|
+
event: "status",
|
|
122
|
+
target: "stack",
|
|
123
|
+
handler: "raw-string",
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
id: "assertion.message",
|
|
127
|
+
name: "Assertion message",
|
|
128
|
+
event: "assertion",
|
|
129
|
+
target: "message",
|
|
130
|
+
handler: "raw-string",
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
id: "assertion.actual",
|
|
134
|
+
name: "Assertion actual",
|
|
135
|
+
event: "assertion",
|
|
136
|
+
target: "actual",
|
|
137
|
+
handler: "json",
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
id: "assertion.expected",
|
|
141
|
+
name: "Assertion expected",
|
|
142
|
+
event: "assertion",
|
|
143
|
+
target: "expected",
|
|
144
|
+
handler: "json",
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
id: "warning.message",
|
|
148
|
+
name: "Warning message",
|
|
149
|
+
event: "warning",
|
|
150
|
+
target: "message",
|
|
151
|
+
handler: "raw-string",
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
id: "schema_validation.message",
|
|
155
|
+
name: "Schema validation message",
|
|
156
|
+
event: "schema_validation",
|
|
157
|
+
target: "message",
|
|
158
|
+
handler: "raw-string",
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
id: "step.returnState",
|
|
162
|
+
name: "Step return state",
|
|
163
|
+
event: "step_end",
|
|
164
|
+
target: "returnState",
|
|
165
|
+
handler: "json",
|
|
166
|
+
},
|
|
33
167
|
];
|
|
34
|
-
// ── Built-in pattern source strings
|
|
168
|
+
// ── Built-in pattern source strings ──────────────────────────────────────────
|
|
35
169
|
/**
|
|
36
170
|
* Regex source strings for built-in value-level patterns.
|
|
37
|
-
* Plugins create new RegExp instances from these on each call
|
|
38
|
-
* to avoid stale lastIndex state.
|
|
171
|
+
* Plugins create new RegExp instances from these on each call.
|
|
39
172
|
*/
|
|
40
173
|
export const PATTERN_SOURCES = {
|
|
41
174
|
jwt: {
|
|
@@ -71,40 +204,40 @@ export const PATTERN_SOURCES = {
|
|
|
71
204
|
flags: "gi",
|
|
72
205
|
},
|
|
73
206
|
};
|
|
74
|
-
// ── Default
|
|
207
|
+
// ── Default global rules ─────────────────────────────────────────────────────
|
|
208
|
+
/**
|
|
209
|
+
* Default global additive rules.
|
|
210
|
+
*
|
|
211
|
+
* These are intentionally minimal — most sensitive keys now live
|
|
212
|
+
* in scope-specific declarations, not in globals.
|
|
213
|
+
*/
|
|
214
|
+
export const DEFAULT_GLOBAL_RULES = {
|
|
215
|
+
sensitiveKeys: [],
|
|
216
|
+
patterns: [
|
|
217
|
+
"jwt",
|
|
218
|
+
"bearer",
|
|
219
|
+
"awsKeys",
|
|
220
|
+
"githubTokens",
|
|
221
|
+
"email",
|
|
222
|
+
"ipAddress",
|
|
223
|
+
"creditCard",
|
|
224
|
+
"hexKeys",
|
|
225
|
+
],
|
|
226
|
+
customPatterns: [],
|
|
227
|
+
};
|
|
228
|
+
// ── Default config ───────────────────────────────────────────────────────────
|
|
75
229
|
/**
|
|
76
|
-
*
|
|
230
|
+
* Default redaction config v2.
|
|
77
231
|
*
|
|
78
|
-
* All scopes
|
|
79
|
-
*
|
|
232
|
+
* All built-in scopes enabled, all patterns enabled globally,
|
|
233
|
+
* scope-specific sensitive keys declared per scope.
|
|
80
234
|
*/
|
|
81
235
|
export const DEFAULT_CONFIG = {
|
|
82
|
-
scopes: {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
responseBody: true,
|
|
88
|
-
consoleOutput: true,
|
|
89
|
-
errorMessages: true,
|
|
90
|
-
returnState: true,
|
|
91
|
-
},
|
|
92
|
-
sensitiveKeys: {
|
|
93
|
-
useBuiltIn: true,
|
|
94
|
-
additional: [],
|
|
95
|
-
excluded: [],
|
|
96
|
-
},
|
|
97
|
-
patterns: {
|
|
98
|
-
jwt: true,
|
|
99
|
-
bearer: true,
|
|
100
|
-
awsKeys: true,
|
|
101
|
-
githubTokens: true,
|
|
102
|
-
email: true,
|
|
103
|
-
ipAddress: true,
|
|
104
|
-
creditCard: true,
|
|
105
|
-
hexKeys: true,
|
|
106
|
-
custom: [],
|
|
107
|
-
},
|
|
236
|
+
scopes: BUILTIN_SCOPES.map((s) => ({
|
|
237
|
+
...s,
|
|
238
|
+
enabled: true,
|
|
239
|
+
})),
|
|
240
|
+
globalRules: DEFAULT_GLOBAL_RULES,
|
|
108
241
|
replacementFormat: "partial",
|
|
109
242
|
};
|
|
110
243
|
//# sourceMappingURL=defaults.js.map
|
package/dist/defaults.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,gFAAgF;AAEhF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAgC;IACzD;QACE,EAAE,EAAE,sBAAsB;QAC1B,IAAI,EAAE,sBAAsB;QAC5B,KAAK,EAAE,OAAO;QACd,MAAM,EAAE,qBAAqB;QAC7B,OAAO,EAAE,SAAS;QAClB,KAAK,EAAE;YACL,aAAa,EAAE,CAAC,eAAe,EAAE,QAAQ,EAAE,WAAW,EAAE,qBAAqB,CAAC;SAC/E;KACF;IACD;QACE,EAAE,EAAE,oBAAoB;QACxB,IAAI,EAAE,oBAAoB;QAC1B,KAAK,EAAE,OAAO;QACd,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE,WAAW;QACpB,KAAK,EAAE;YACL,aAAa,EAAE;gBACb,OAAO;gBACP,cAAc;gBACd,eAAe;gBACf,SAAS;gBACT,QAAQ;gBACR,SAAS;gBACT,QAAQ;gBACR,UAAU;aACX;SACF;KACF;IACD;QACE,EAAE,EAAE,mBAAmB;QACvB,IAAI,EAAE,mBAAmB;QACzB,KAAK,EAAE,OAAO;QACd,MAAM,EAAE,kBAAkB;QAC1B,OAAO,EAAE,MAAM;QACf,KAAK,EAAE;YACL,aAAa,EAAE;gBACb,UAAU;gBACV,QAAQ;gBACR,QAAQ;gBACR,OAAO;gBACP,eAAe;gBACf,eAAe;gBACf,aAAa;gBACb,YAAY;gBACZ,aAAa;aACd;SACF;KACF;IACD;QACE,EAAE,EAAE,uBAAuB;QAC3B,IAAI,EAAE,uBAAuB;QAC7B,KAAK,EAAE,OAAO;QACd,MAAM,EAAE,sBAAsB;QAC9B,OAAO,EAAE,SAAS;QAClB,KAAK,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;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAgB;IAC/C,aAAa,EAAE,EAAE;IACjB,QAAQ,EAAE;QACR,KAAK;QACL,QAAQ;QACR,SAAS;QACT,cAAc;QACd,OAAO;QACP,WAAW;QACX,YAAY;QACZ,SAAS;KACV;IACD,cAAc,EAAE,EAAE;CACnB,CAAC;AAEF,gFAAgF;AAEhF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAoB;IAC7C,MAAM,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACjC,GAAG,CAAC;QACJ,OAAO,EAAE,IAAI;KACd,CAAC,CAAC;IACH,WAAW,EAAE,oBAAoB;IACjC,iBAAiB,EAAE,SAAS;CAC7B,CAAC"}
|
package/dist/engine.d.ts
CHANGED
|
@@ -1,46 +1,45 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module engine
|
|
3
3
|
*
|
|
4
|
-
* RedactionEngine —
|
|
4
|
+
* RedactionEngine — recursive JSON walker that applies plugins
|
|
5
5
|
* to detect and mask sensitive data.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* v2: the engine is instantiated per-scope with a scope-specific plugin pipeline.
|
|
8
|
+
* It no longer does scope gating — that responsibility moves to the compiler/dispatcher.
|
|
9
9
|
*/
|
|
10
|
-
import type {
|
|
10
|
+
import type { RedactionPlugin, RedactionResult, ScopeContext } from "./types.js";
|
|
11
11
|
/** Options for constructing a RedactionEngine instance. */
|
|
12
|
-
export interface RedactionEngineOptions
|
|
13
|
-
|
|
12
|
+
export interface RedactionEngineOptions {
|
|
13
|
+
/** Plugin pipeline for this engine instance. */
|
|
14
14
|
plugins: RedactionPlugin[];
|
|
15
|
+
/** Replacement format. */
|
|
16
|
+
replacementFormat: "simple" | "labeled" | "partial";
|
|
15
17
|
/** Max object nesting depth before truncation. Default: 10. */
|
|
16
18
|
maxDepth?: number;
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
19
21
|
* Generic partial mask: show first 3 and last 3 characters for long values,
|
|
20
22
|
* less for shorter values, full mask for very short ones.
|
|
21
|
-
*
|
|
22
|
-
* Used as fallback when a plugin does not provide its own partialMask().
|
|
23
23
|
*/
|
|
24
24
|
export declare function genericPartialMask(value: string): string;
|
|
25
25
|
/**
|
|
26
26
|
* Plugin-based redaction engine.
|
|
27
27
|
*
|
|
28
28
|
* Walks JSON values recursively, applying registered plugins for key-level
|
|
29
|
-
* and value-level redaction.
|
|
30
|
-
* "simple" ([REDACTED]), "labeled" ([REDACTED:plugin_name]), "partial" (smart masking).
|
|
29
|
+
* and value-level redaction.
|
|
31
30
|
*/
|
|
32
|
-
export declare class RedactionEngine
|
|
33
|
-
private readonly config;
|
|
31
|
+
export declare class RedactionEngine {
|
|
34
32
|
private readonly plugins;
|
|
33
|
+
private readonly replacementFormat;
|
|
35
34
|
private readonly maxDepth;
|
|
36
|
-
constructor(options: RedactionEngineOptions
|
|
35
|
+
constructor(options: RedactionEngineOptions);
|
|
37
36
|
/**
|
|
38
37
|
* Redact a value. Recursively walks objects and arrays.
|
|
39
38
|
*
|
|
40
|
-
* @param value
|
|
41
|
-
* @param
|
|
39
|
+
* @param value The value to redact.
|
|
40
|
+
* @param ctx Optional scope context for plugin dispatch.
|
|
42
41
|
*/
|
|
43
|
-
redact(value: unknown,
|
|
42
|
+
redact(value: unknown, ctx?: ScopeContext): RedactionResult;
|
|
44
43
|
private walkValue;
|
|
45
44
|
private walkObject;
|
|
46
45
|
private walkString;
|
package/dist/engine.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAEV,eAAe,EACf,eAAe,EACf,YAAY,EACb,MAAM,YAAY,CAAC;AAEpB,2DAA2D;AAC3D,MAAM,WAAW,sBAAsB;IACrC,gDAAgD;IAChD,OAAO,EAAE,eAAe,EAAE,CAAC;IAC3B,0BAA0B;IAC1B,iBAAiB,EAAE,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;IACpD,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKxD;AAED;;;;;GAKG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoB;IAC5C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAmC;IACrE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;gBAEtB,OAAO,EAAE,sBAAsB;IAM3C;;;;;OAKG;IACH,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,YAAY,GAAG,eAAe;IAa3D,OAAO,CAAC,SAAS;IAiDjB,OAAO,CAAC,UAAU;IA4DlB,OAAO,CAAC,UAAU;CA4CnB"}
|
package/dist/engine.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module engine
|
|
3
3
|
*
|
|
4
|
-
* RedactionEngine —
|
|
4
|
+
* RedactionEngine — recursive JSON walker that applies plugins
|
|
5
5
|
* to detect and mask sensitive data.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* v2: the engine is instantiated per-scope with a scope-specific plugin pipeline.
|
|
8
|
+
* It no longer does scope gating — that responsibility moves to the compiler/dispatcher.
|
|
9
9
|
*/
|
|
10
10
|
/**
|
|
11
11
|
* Generic partial mask: show first 3 and last 3 characters for long values,
|
|
12
12
|
* less for shorter values, full mask for very short ones.
|
|
13
|
-
*
|
|
14
|
-
* Used as fallback when a plugin does not provide its own partialMask().
|
|
15
13
|
*/
|
|
16
14
|
export function genericPartialMask(value) {
|
|
17
15
|
const len = value.length;
|
|
@@ -25,34 +23,26 @@ export function genericPartialMask(value) {
|
|
|
25
23
|
* Plugin-based redaction engine.
|
|
26
24
|
*
|
|
27
25
|
* Walks JSON values recursively, applying registered plugins for key-level
|
|
28
|
-
* and value-level redaction.
|
|
29
|
-
* "simple" ([REDACTED]), "labeled" ([REDACTED:plugin_name]), "partial" (smart masking).
|
|
26
|
+
* and value-level redaction.
|
|
30
27
|
*/
|
|
31
28
|
export class RedactionEngine {
|
|
32
|
-
config;
|
|
33
29
|
plugins;
|
|
30
|
+
replacementFormat;
|
|
34
31
|
maxDepth;
|
|
35
32
|
constructor(options) {
|
|
36
|
-
this.config = options.config;
|
|
37
33
|
this.plugins = options.plugins;
|
|
34
|
+
this.replacementFormat = options.replacementFormat;
|
|
38
35
|
this.maxDepth = options.maxDepth ?? 10;
|
|
39
36
|
}
|
|
40
37
|
/**
|
|
41
38
|
* Redact a value. Recursively walks objects and arrays.
|
|
42
39
|
*
|
|
43
|
-
* @param value
|
|
44
|
-
* @param
|
|
40
|
+
* @param value The value to redact.
|
|
41
|
+
* @param ctx Optional scope context for plugin dispatch.
|
|
45
42
|
*/
|
|
46
|
-
redact(value,
|
|
47
|
-
|
|
48
|
-
if (scope) {
|
|
49
|
-
const scopes = this.config.scopes;
|
|
50
|
-
if (scopes[scope] === false) {
|
|
51
|
-
return { value, redacted: false, details: [] };
|
|
52
|
-
}
|
|
53
|
-
}
|
|
43
|
+
redact(value, ctx) {
|
|
44
|
+
const scopeStr = ctx?.id ?? "";
|
|
54
45
|
const details = [];
|
|
55
|
-
const scopeStr = scope ?? "";
|
|
56
46
|
const result = this.walkValue(value, scopeStr, [], details, 0);
|
|
57
47
|
return {
|
|
58
48
|
value: result.value,
|
|
@@ -107,8 +97,7 @@ export class RedactionEngine {
|
|
|
107
97
|
}
|
|
108
98
|
}
|
|
109
99
|
if (keySensitive) {
|
|
110
|
-
|
|
111
|
-
if (replacement === "partial") {
|
|
100
|
+
if (this.replacementFormat === "partial") {
|
|
112
101
|
const str = value === null || value === undefined ? "" : String(value);
|
|
113
102
|
result[key] = genericPartialMask(str);
|
|
114
103
|
}
|
|
@@ -145,15 +134,13 @@ export class RedactionEngine {
|
|
|
145
134
|
const regex = plugin.matchValue(result, ctx);
|
|
146
135
|
if (!regex)
|
|
147
136
|
continue;
|
|
148
|
-
// Test if the pattern matches
|
|
149
137
|
if (regex.test(result)) {
|
|
150
138
|
regex.lastIndex = 0; // Reset after test()
|
|
151
|
-
|
|
152
|
-
if (replacement === "partial") {
|
|
139
|
+
if (this.replacementFormat === "partial") {
|
|
153
140
|
const maskFn = plugin.partialMask ?? genericPartialMask;
|
|
154
141
|
result = result.replace(regex, (match) => maskFn(match));
|
|
155
142
|
}
|
|
156
|
-
else if (
|
|
143
|
+
else if (this.replacementFormat === "labeled") {
|
|
157
144
|
const tag = `[REDACTED:${plugin.name}]`;
|
|
158
145
|
result = result.replace(regex, tag);
|
|
159
146
|
}
|
package/dist/engine.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAmBH;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAa;IAC9C,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC;IACzB,IAAI,GAAG,IAAI,CAAC;QAAE,OAAO,MAAM,CAAC;IAC5B,IAAI,GAAG,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACjE,OAAO,KAAK,CAAC,KAAK,CAAC,C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BAAiB,KAAK,SAAS,EAAE,CAAC;oBAChD,MAAM,GAAG,GAAG,aAAa,MAAM,CAAC,IAAI,GAAG,CAAC;oBACxC,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;gBACtC,CAAC;qBAAM,CAAC;oBACN,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;gBAC/C,CAAC;gBAED,SAAS,GAAG,IAAI,CAAC;gBACjB,OAAO,CAAC,IAAI,CAAC;oBACX,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;oBACpB,MAAM,EAAE,MAAM,CAAC,IAAI;oBACnB,QAAQ,EAAE,GAAG;iBACd,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IACtC,CAAC;CACF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module handlers
|
|
3
|
+
*
|
|
4
|
+
* Built-in redaction handlers. Each handler interprets a specific payload shape.
|
|
5
|
+
*
|
|
6
|
+
* - `json` — recursive object/array walker (delegates to engine.redact)
|
|
7
|
+
* - `raw-string` — value-pattern matching only
|
|
8
|
+
* - `url-query` — parse URL, redact query param names/values, serialize back
|
|
9
|
+
* - `headers` — header map with case-insensitive keys, cookie/set-cookie parsing
|
|
10
|
+
*/
|
|
11
|
+
import type { RedactionHandler } from "./types.js";
|
|
12
|
+
/**
|
|
13
|
+
* Default handler: delegates directly to engine.redact() which recursively
|
|
14
|
+
* walks objects/arrays and applies key-level + value-level plugins.
|
|
15
|
+
*/
|
|
16
|
+
export declare const jsonHandler: RedactionHandler;
|
|
17
|
+
/**
|
|
18
|
+
* Handles plain string values. Wraps the string in an object so the engine
|
|
19
|
+
* can apply value-level pattern plugins, then extracts the result.
|
|
20
|
+
*/
|
|
21
|
+
export declare const rawStringHandler: RedactionHandler;
|
|
22
|
+
/**
|
|
23
|
+
* Parses a URL string, redacts query parameter names/values using the engine,
|
|
24
|
+
* then serializes back to a URL string.
|
|
25
|
+
*/
|
|
26
|
+
export declare const urlQueryHandler: RedactionHandler;
|
|
27
|
+
/**
|
|
28
|
+
* Handles HTTP header maps with special treatment for cookie headers.
|
|
29
|
+
*
|
|
30
|
+
* - Normal headers: redact as key/value pairs
|
|
31
|
+
* - `cookie`: parse into name/value pairs, redact, serialize back
|
|
32
|
+
* - `set-cookie`: parse value portion, preserve attributes (Path, Domain, etc.)
|
|
33
|
+
*/
|
|
34
|
+
export declare const headersHandler: RedactionHandler;
|
|
35
|
+
/** All built-in handlers indexed by name. */
|
|
36
|
+
export declare const BUILTIN_HANDLERS: Record<string, RedactionHandler>;
|
|
37
|
+
//# sourceMappingURL=handlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../src/handlers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAA6D,MAAM,YAAY,CAAC;AAI9G;;;GAGG;AACH,eAAO,MAAM,WAAW,EAAE,gBAKzB,CAAC;AAIF;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,gBAe9B,CAAC;AAIF;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,gBA0D7B,CAAC;AA4BF;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,EAAE,gBA+E5B,CAAC;AAkDF,6CAA6C;AAC7C,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAK7D,CAAC"}
|