@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.
@@ -0,0 +1,236 @@
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
+ // ── json handler ─────────────────────────────────────────────────────────────
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 const jsonHandler = {
17
+ name: "json",
18
+ process(value, ctx, engine) {
19
+ return engine.redact(value, { id: ctx.scopeId, name: ctx.scopeName });
20
+ },
21
+ };
22
+ // ── raw-string handler ───────────────────────────────────────────────────────
23
+ /**
24
+ * Handles plain string values. Wraps the string in an object so the engine
25
+ * can apply value-level pattern plugins, then extracts the result.
26
+ */
27
+ export const rawStringHandler = {
28
+ name: "raw-string",
29
+ process(value, ctx, engine) {
30
+ if (typeof value !== "string") {
31
+ return { value, redacted: false, details: [] };
32
+ }
33
+ // Wrap in object so the engine walks it as a string value
34
+ const result = engine.redact({ __raw: value }, { id: ctx.scopeId, name: ctx.scopeName });
35
+ const redacted = result.value;
36
+ return {
37
+ value: redacted.__raw,
38
+ redacted: result.redacted,
39
+ details: result.details,
40
+ };
41
+ },
42
+ };
43
+ // ── url-query handler ────────────────────────────────────────────────────────
44
+ /**
45
+ * Parses a URL string, redacts query parameter names/values using the engine,
46
+ * then serializes back to a URL string.
47
+ */
48
+ export const urlQueryHandler = {
49
+ name: "url-query",
50
+ process(value, ctx, engine) {
51
+ if (typeof value !== "string") {
52
+ return { value, redacted: false, details: [] };
53
+ }
54
+ let url;
55
+ try {
56
+ url = new URL(value);
57
+ }
58
+ catch {
59
+ // Not a valid URL — fall back to raw string redaction
60
+ return engine.redact(value, { id: ctx.scopeId, name: ctx.scopeName });
61
+ }
62
+ // Collect all entries first to preserve multiplicity (e.g., ?token=a&token=b)
63
+ const entries = [...url.searchParams.entries()];
64
+ if (entries.length === 0) {
65
+ return { value, redacted: false, details: [] };
66
+ }
67
+ let didRedact = false;
68
+ const details = [];
69
+ const redactedEntries = [];
70
+ for (const [key, raw] of entries) {
71
+ const result = engine.redact({ [key]: raw }, { id: ctx.scopeId, name: ctx.scopeName });
72
+ if (result.redacted) {
73
+ const redacted = result.value;
74
+ redactedEntries.push([key, String(redacted[key] ?? raw)]);
75
+ didRedact = true;
76
+ details.push(...result.details);
77
+ }
78
+ else {
79
+ redactedEntries.push([key, raw]);
80
+ }
81
+ }
82
+ if (!didRedact) {
83
+ return { value, redacted: false, details };
84
+ }
85
+ // Rebuild URL with redacted params, preserving multiplicity
86
+ const redactedUrl = new URL(url.origin + url.pathname);
87
+ for (const [k, v] of redactedEntries) {
88
+ redactedUrl.searchParams.append(k, v);
89
+ }
90
+ // Preserve hash
91
+ redactedUrl.hash = url.hash;
92
+ return {
93
+ value: redactedUrl.toString(),
94
+ redacted: true,
95
+ details,
96
+ };
97
+ },
98
+ };
99
+ // ── headers handler ──────────────────────────────────────────────────────────
100
+ /**
101
+ * Parse a Cookie header string into key/value pairs.
102
+ */
103
+ function parseCookieHeader(str) {
104
+ const result = {};
105
+ for (const part of str.split(";")) {
106
+ const trimmed = part.trim();
107
+ if (!trimmed)
108
+ continue;
109
+ const eq = trimmed.indexOf("=");
110
+ if (eq === -1)
111
+ continue;
112
+ result[trimmed.slice(0, eq).trim()] = trimmed.slice(eq + 1).trim();
113
+ }
114
+ return result;
115
+ }
116
+ /**
117
+ * Serialize a cookie key/value map back to a Cookie header string.
118
+ */
119
+ function serializeCookieHeader(obj) {
120
+ return Object.entries(obj)
121
+ .map(([k, v]) => `${k}=${String(v)}`)
122
+ .join("; ");
123
+ }
124
+ /**
125
+ * Handles HTTP header maps with special treatment for cookie headers.
126
+ *
127
+ * - Normal headers: redact as key/value pairs
128
+ * - `cookie`: parse into name/value pairs, redact, serialize back
129
+ * - `set-cookie`: parse value portion, preserve attributes (Path, Domain, etc.)
130
+ */
131
+ export const headersHandler = {
132
+ name: "headers",
133
+ process(value, ctx, engine) {
134
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
135
+ return { value, redacted: false, details: [] };
136
+ }
137
+ const input = value;
138
+ const output = {};
139
+ let didRedact = false;
140
+ const details = [];
141
+ for (const [headerName, headerValue] of Object.entries(input)) {
142
+ const lower = headerName.toLowerCase();
143
+ // Cookie header: parse into key/value pairs
144
+ if (lower === "cookie" && typeof headerValue === "string") {
145
+ const parsed = parseCookieHeader(headerValue);
146
+ const result = engine.redact(parsed, {
147
+ id: ctx.scopeId,
148
+ name: ctx.scopeName,
149
+ });
150
+ output[headerName] = serializeCookieHeader(result.value);
151
+ if (result.redacted) {
152
+ didRedact = true;
153
+ details.push(...result.details);
154
+ }
155
+ continue;
156
+ }
157
+ // Set-Cookie header: redact the value portion, preserve attributes
158
+ // Supports both single string and string[] (common in HTTP client shapes)
159
+ if (lower === "set-cookie") {
160
+ if (typeof headerValue === "string") {
161
+ const redacted = redactSetCookie(headerValue, ctx, engine);
162
+ output[headerName] = redacted.value;
163
+ if (redacted.redacted) {
164
+ didRedact = true;
165
+ details.push(...redacted.details);
166
+ }
167
+ continue;
168
+ }
169
+ if (Array.isArray(headerValue)) {
170
+ const redactedCookies = [];
171
+ for (const cookie of headerValue) {
172
+ if (typeof cookie !== "string") {
173
+ redactedCookies.push(cookie);
174
+ continue;
175
+ }
176
+ const redacted = redactSetCookie(cookie, ctx, engine);
177
+ redactedCookies.push(redacted.value);
178
+ if (redacted.redacted) {
179
+ didRedact = true;
180
+ details.push(...redacted.details);
181
+ }
182
+ }
183
+ output[headerName] = redactedCookies;
184
+ continue;
185
+ }
186
+ }
187
+ // Normal header: redact as { headerName: value }
188
+ const result = engine.redact({ [headerName]: headerValue }, { id: ctx.scopeId, name: ctx.scopeName });
189
+ output[headerName] = result.value[headerName];
190
+ if (result.redacted) {
191
+ didRedact = true;
192
+ details.push(...result.details);
193
+ }
194
+ }
195
+ return { value: didRedact ? output : value, redacted: didRedact, details };
196
+ },
197
+ };
198
+ /**
199
+ * Redact a Set-Cookie header value.
200
+ * Preserves cookie attributes (Path, Domain, HttpOnly, Secure, SameSite, Max-Age, Expires).
201
+ */
202
+ function redactSetCookie(raw, ctx, engine) {
203
+ const parts = raw.split(";").map((p) => p.trim());
204
+ if (parts.length === 0) {
205
+ return { value: raw, redacted: false, details: [] };
206
+ }
207
+ // First part is name=value
208
+ const first = parts[0];
209
+ const eq = first.indexOf("=");
210
+ if (eq === -1) {
211
+ return { value: raw, redacted: false, details: [] };
212
+ }
213
+ const cookieName = first.slice(0, eq).trim();
214
+ const cookieValue = first.slice(eq + 1).trim();
215
+ const result = engine.redact({ [cookieName]: cookieValue }, { id: ctx.scopeId, name: ctx.scopeName });
216
+ if (!result.redacted) {
217
+ return { value: raw, redacted: false, details: [] };
218
+ }
219
+ const redacted = result.value;
220
+ const redactedValue = String(redacted[cookieName] ?? cookieValue);
221
+ // Reconstruct: redacted name=value + original attributes
222
+ const attributes = parts.slice(1);
223
+ const reconstructed = attributes.length > 0
224
+ ? `${cookieName}=${redactedValue}; ${attributes.join("; ")}`
225
+ : `${cookieName}=${redactedValue}`;
226
+ return { value: reconstructed, redacted: true, details: result.details };
227
+ }
228
+ // ── Handler registry ─────────────────────────────────────────────────────────
229
+ /** All built-in handlers indexed by name. */
230
+ export const BUILTIN_HANDLERS = {
231
+ json: jsonHandler,
232
+ "raw-string": rawStringHandler,
233
+ "url-query": urlQueryHandler,
234
+ headers: headersHandler,
235
+ };
236
+ //# sourceMappingURL=handlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers.js","sourceRoot":"","sources":["../src/handlers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,g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AAO,EAAE,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC;AAC3E,CAAC;AAED,gFAAgF;AAEhF,6CAA6C;AAC7C,MAAM,CAAC,MAAM,gBAAgB,GAAqC;IAChE,IAAI,EAAE,WAAW;IACjB,YAAY,EAAE,gBAAgB;IAC9B,WAAW,EAAE,eAAe;IAC5B,OAAO,EAAE,cAAc;CACxB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,29 +1,36 @@
1
1
  /**
2
2
  * @glubean/redaction — Plugin-based secrets/PII detection and masking.
3
3
  *
4
- * Pure TypeScript, no runtime-specific dependencies.
4
+ * v2: scope-based redaction with per-scope rules and handler dispatch.
5
5
  *
6
6
  * @example
7
7
  * import {
8
- * RedactionEngine,
9
- * createBuiltinPlugins,
10
- * DEFAULT_CONFIG,
8
+ * compileScopes,
11
9
  * redactEvent,
10
+ * BUILTIN_SCOPES,
11
+ * DEFAULT_GLOBAL_RULES,
12
12
  * } from "@glubean/redaction";
13
13
  *
14
- * const engine = new RedactionEngine({
15
- * config: DEFAULT_CONFIG,
16
- * plugins: createBuiltinPlugins(DEFAULT_CONFIG),
14
+ * const compiled = compileScopes({
15
+ * builtinScopes: BUILTIN_SCOPES,
16
+ * globalRules: DEFAULT_GLOBAL_RULES,
17
+ * replacementFormat: "partial",
17
18
  * });
18
19
  *
19
- * const result = engine.redact({ authorization: "Bearer secret123" });
20
- * // result.value === { authorization: "[REDACTED]" }
20
+ * const redacted = redactEvent(
21
+ * { type: "trace", data: { requestHeaders: { authorization: "Bearer secret" } } },
22
+ * compiled,
23
+ * "partial",
24
+ * );
21
25
  */
22
- export type { CustomPattern, PatternsConfig, RedactionConfig, RedactionContext, RedactionPlugin, RedactionResult, RedactionScopes, SensitiveKeysConfig, } from "./types.js";
26
+ export type { CompiledScope, CustomPattern, GlobalRules, HandlerContext, RedactionConfig, RedactionContext, RedactionHandler, RedactionPlugin, RedactionResult, RedactionScope, RedactionScopeDeclaration, ScopeContext, ScopeRules, } from "./types.js";
23
27
  export { genericPartialMask, RedactionEngine } from "./engine.js";
24
28
  export type { RedactionEngineOptions } from "./engine.js";
25
- export { BUILT_IN_SENSITIVE_KEYS, DEFAULT_CONFIG, PATTERN_SOURCES } from "./defaults.js";
26
- export { awsKeysPlugin, bearerPlugin, createBuiltinPlugins, creditCardPlugin, emailPlugin, githubTokensPlugin, hexKeysPlugin, ipAddressPlugin, jwtPlugin, sensitiveKeysPlugin, } from "./plugins/mod.js";
29
+ export { BUILTIN_HANDLERS, headersHandler, jsonHandler, rawStringHandler, urlQueryHandler, } from "./handlers.js";
30
+ export { compileScopes, createScopeEngine } from "./compiler.js";
31
+ export type { CompilerOptions, ScopeOverride } from "./compiler.js";
27
32
  export { redactEvent } from "./adapter.js";
28
33
  export type { RedactableEvent } from "./adapter.js";
34
+ export { BUILTIN_SCOPES, DEFAULT_CONFIG, DEFAULT_GLOBAL_RULES, PATTERN_SOURCES, } from "./defaults.js";
35
+ export { awsKeysPlugin, bearerPlugin, createPatternPlugins, creditCardPlugin, emailPlugin, githubTokensPlugin, hexKeysPlugin, ipAddressPlugin, jwtPlugin, sensitiveKeysPlugin, } from "./plugins/mod.js";
29
36
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,YAAY,EACV,aAAa,EACb,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,eAAe,EACf,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAClE,YAAY,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAG1D,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,eAAe,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BAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -1,30 +1,38 @@
1
1
  /**
2
2
  * @glubean/redaction — Plugin-based secrets/PII detection and masking.
3
3
  *
4
- * Pure TypeScript, no runtime-specific dependencies.
4
+ * v2: scope-based redaction with per-scope rules and handler dispatch.
5
5
  *
6
6
  * @example
7
7
  * import {
8
- * RedactionEngine,
9
- * createBuiltinPlugins,
10
- * DEFAULT_CONFIG,
8
+ * compileScopes,
11
9
  * redactEvent,
10
+ * BUILTIN_SCOPES,
11
+ * DEFAULT_GLOBAL_RULES,
12
12
  * } from "@glubean/redaction";
13
13
  *
14
- * const engine = new RedactionEngine({
15
- * config: DEFAULT_CONFIG,
16
- * plugins: createBuiltinPlugins(DEFAULT_CONFIG),
14
+ * const compiled = compileScopes({
15
+ * builtinScopes: BUILTIN_SCOPES,
16
+ * globalRules: DEFAULT_GLOBAL_RULES,
17
+ * replacementFormat: "partial",
17
18
  * });
18
19
  *
19
- * const result = engine.redact({ authorization: "Bearer secret123" });
20
- * // result.value === { authorization: "[REDACTED]" }
20
+ * const redacted = redactEvent(
21
+ * { type: "trace", data: { requestHeaders: { authorization: "Bearer secret" } } },
22
+ * compiled,
23
+ * "partial",
24
+ * );
21
25
  */
22
26
  // Engine
23
27
  export { genericPartialMask, RedactionEngine } from "./engine.js";
24
- // Defaults
25
- export { BUILT_IN_SENSITIVE_KEYS, DEFAULT_CONFIG, PATTERN_SOURCES } from "./defaults.js";
26
- // Plugins
27
- export { awsKeysPlugin, bearerPlugin, createBuiltinPlugins, creditCardPlugin, emailPlugin, githubTokensPlugin, hexKeysPlugin, ipAddressPlugin, jwtPlugin, sensitiveKeysPlugin, } from "./plugins/mod.js";
28
+ // Handlers
29
+ export { BUILTIN_HANDLERS, headersHandler, jsonHandler, rawStringHandler, urlQueryHandler, } from "./handlers.js";
30
+ // Compiler
31
+ export { compileScopes, createScopeEngine } from "./compiler.js";
28
32
  // Adapter
29
33
  export { redactEvent } from "./adapter.js";
34
+ // Defaults
35
+ export { BUILTIN_SCOPES, DEFAULT_CONFIG, DEFAULT_GLOBAL_RULES, PATTERN_SOURCES, } from "./defaults.js";
36
+ // Plugins
37
+ export { awsKeysPlugin, bearerPlugin, createPatternPlugins, creditCardPlugin, emailPlugin, githubTokensPlugin, hexKeysPlugin, ipAddressPlugin, jwtPlugin, sensitiveKeysPlugin, } from "./plugins/mod.js";
30
38
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAcH,SAAS;AACT,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGlE,WAAW;AACX,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEzF,UAAU;AACV,OAAO,EACL,aAAa,EACb,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,SAAS,EACT,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAE1B,UAAU;AACV,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAmBH,SAAS;AACT,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGlE,WAAW;AACX,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,eAAe,GAChB,MAAM,eAAe,CAAC;AAEvB,WAAW;AACX,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAGjE,UAAU;AACV,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAG3C,WAAW;AACX,OAAO,EACL,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,eAAe,GAChB,MAAM,eAAe,CAAC;AAEvB,UAAU;AACV,OAAO,EACL,aAAa,EACb,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,SAAS,EACT,mBAAmB,GACpB,MAAM,kBAAkB,CAAC"}
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * @module plugins
3
3
  *
4
- * Re-exports all built-in plugins and provides `createBuiltinPlugins()`
5
- * factory that assembles the plugin list from a RedactionConfig.
4
+ * Re-exports all built-in plugins and provides factories
5
+ * for assembling plugin pipelines.
6
6
  */
7
- import type { RedactionConfig, RedactionPlugin } from "../types.js";
7
+ import type { RedactionPlugin } from "../types.js";
8
8
  import { sensitiveKeysPlugin } from "./sensitive-keys.js";
9
9
  import { jwtPlugin } from "./jwt.js";
10
10
  import { bearerPlugin } from "./bearer.js";
@@ -16,14 +16,7 @@ import { creditCardPlugin } from "./credit-card.js";
16
16
  import { hexKeysPlugin } from "./hex-keys.js";
17
17
  export { awsKeysPlugin, bearerPlugin, creditCardPlugin, emailPlugin, githubTokensPlugin, hexKeysPlugin, ipAddressPlugin, jwtPlugin, sensitiveKeysPlugin, };
18
18
  /**
19
- * Create the full plugin list from a RedactionConfig.
20
- *
21
- * Order: sensitive-keys plugin first (key-level), then enabled pattern
22
- * plugins (value-level), then user custom patterns.
23
- *
24
- * @example
25
- * const plugins = createBuiltinPlugins(DEFAULT_CONFIG);
26
- * const engine = new RedactionEngine({ config: DEFAULT_CONFIG, plugins });
19
+ * Create pattern plugins for a set of enabled pattern names.
27
20
  */
28
- export declare function createBuiltinPlugins(config: RedactionConfig): RedactionPlugin[];
21
+ export declare function createPatternPlugins(enabledPatterns: Set<string>): RedactionPlugin[];
29
22
  //# sourceMappingURL=mod.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/plugins/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;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,EACL,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,SAAS,EACT,mBAAmB,GACpB,CAAC;AAcF;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,eAAe,EAAE,GAAG,CAAC,MAAM,CAAC,GAC3B,eAAe,EAAE,CAQnB"}
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @module plugins
3
3
  *
4
- * Re-exports all built-in plugins and provides `createBuiltinPlugins()`
5
- * factory that assembles the plugin list from a RedactionConfig.
4
+ * Re-exports all built-in plugins and provides factories
5
+ * for assembling plugin pipelines.
6
6
  */
7
7
  import { sensitiveKeysPlugin } from "./sensitive-keys.js";
8
8
  import { jwtPlugin } from "./jwt.js";
@@ -26,40 +26,15 @@ const PATTERN_PLUGINS = {
26
26
  hexKeys: hexKeysPlugin,
27
27
  };
28
28
  /**
29
- * Create the full plugin list from a RedactionConfig.
30
- *
31
- * Order: sensitive-keys plugin first (key-level), then enabled pattern
32
- * plugins (value-level), then user custom patterns.
33
- *
34
- * @example
35
- * const plugins = createBuiltinPlugins(DEFAULT_CONFIG);
36
- * const engine = new RedactionEngine({ config: DEFAULT_CONFIG, plugins });
29
+ * Create pattern plugins for a set of enabled pattern names.
37
30
  */
38
- export function createBuiltinPlugins(config) {
31
+ export function createPatternPlugins(enabledPatterns) {
39
32
  const plugins = [];
40
- // Key-level plugin always first
41
- plugins.push(sensitiveKeysPlugin(config.sensitiveKeys));
42
- // Add enabled pattern plugins
43
- const patternFlags = config.patterns;
44
33
  for (const [name, plugin] of Object.entries(PATTERN_PLUGINS)) {
45
- if (patternFlags[name] === true) {
34
+ if (enabledPatterns.has(name)) {
46
35
  plugins.push(plugin);
47
36
  }
48
37
  }
49
- // Add user custom patterns
50
- for (const custom of config.patterns.custom ?? []) {
51
- try {
52
- // Validate regex compiles
53
- new RegExp(custom.regex, "g");
54
- plugins.push({
55
- name: custom.name,
56
- matchValue: () => new RegExp(custom.regex, "g"),
57
- });
58
- }
59
- catch {
60
- // Skip invalid regex patterns — per arch doc, CLI warns but doesn't abort
61
- }
62
- }
63
38
  return plugins;
64
39
  }
65
40
  //# sourceMappingURL=mod.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mod.js","sourceRoot":"","sources":["../../src/plugins/mod.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,EACL,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,SAAS,EACT,mBAAmB,GACpB,CAAC;AAEF,0DAA0D;AAC1D,MAAM,eAAe,GAAoC;IACvD,GAAG,EAAE,SAAS;IACd,MAAM,EAAE,YAAY;IACpB,OAAO,EAAE,aAAa;IACtB,YAAY,EAAE,kBAAkB;IAChC,KAAK,EAAE,WAAW;IAClB,SAAS,EAAE,eAAe;IAC1B,UAAU,EAAE,gBAAgB;IAC5B,OAAO,EAAE,aAAa;CACvB,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AE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,EACL,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,SAAS,EACT,mBAAmB,GACpB,CAAC;AAEF,0DAA0D;AAC1D,MAAM,eAAe,GAAoC;IACvD,GAAG,EAAE,SAAS;IACd,MAAM,EAAE,YAAY;IACpB,OAAO,EAAE,aAAa;IACtB,YAAY,EAAE,kBAAkB;IAChC,KAAK,EAAE,WAAW;IAClB,SAAS,EAAE,eAAe;IAC1B,UAAU,EAAE,gBAAgB;IAC5B,OAAO,EAAE,aAAa;CACvB,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,eAA4B;IAE5B,MAAM,OAAO,GAAsB,EAAE,CAAC;IACtC,KAAK,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,CAAC;QAC7D,IAAI,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9B,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -3,12 +3,17 @@
3
3
  *
4
4
  * Checks if a JSON key or header name matches one of the configured
5
5
  * sensitive keys (case-insensitive substring match).
6
- *
7
- * @example
8
- * // "x-authorization-token" matches "authorization"
9
- * // "X-Api-Key" matches "api-key" (after lowercasing)
10
6
  */
11
- import type { RedactionPlugin, SensitiveKeysConfig } from "../types.js";
7
+ import type { RedactionPlugin } from "../types.js";
8
+ /** Config for the sensitive keys plugin. */
9
+ export interface SensitiveKeysConfig {
10
+ /** Whether to include the built-in sensitive keys list. */
11
+ useBuiltIn: boolean;
12
+ /** Additional keys to treat as sensitive. */
13
+ additional: string[];
14
+ /** Keys to exclude from the built-in list. */
15
+ excluded: string[];
16
+ }
12
17
  /**
13
18
  * Create a sensitive-keys plugin from config.
14
19
  *
@@ -1 +1 @@
1
- {"version":3,"file":"sensitive-keys.d.ts","sourceRoot":"","sources":["../../src/plugins/sensitive-keys.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AA4BxE;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,mBAAmB,GAC1B,eAAe,CAgBjB"}
1
+ {"version":3,"file":"sensitive-keys.d.ts","sourceRoot":"","sources":["../../src/plugins/sensitive-keys.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,4CAA4C;AAC5C,MAAM,WAAW,mBAAmB;IAClC,2DAA2D;IAC3D,UAAU,EAAE,OAAO,CAAC;IACpB,6CAA6C;IAC7C,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,8CAA8C;IAC9C,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAqDD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,mBAAmB,GAC1B,eAAe,CAcjB"}
@@ -3,16 +3,36 @@
3
3
  *
4
4
  * Checks if a JSON key or header name matches one of the configured
5
5
  * sensitive keys (case-insensitive substring match).
6
- *
7
- * @example
8
- * // "x-authorization-token" matches "authorization"
9
- * // "X-Api-Key" matches "api-key" (after lowercasing)
10
6
  */
11
- import { BUILT_IN_SENSITIVE_KEYS } from "../defaults.js";
7
+ /**
8
+ * Built-in sensitive keys.
9
+ * v2: these are only used when `useBuiltIn: true` (for backwards compat).
10
+ * In the new model, sensitive keys live in scope declarations.
11
+ */
12
+ const BUILT_IN_SENSITIVE_KEYS = [
13
+ "password",
14
+ "passwd",
15
+ "secret",
16
+ "token",
17
+ "api_key",
18
+ "apikey",
19
+ "api-key",
20
+ "access_token",
21
+ "refresh_token",
22
+ "authorization",
23
+ "auth",
24
+ "credential",
25
+ "credentials",
26
+ "private_key",
27
+ "privatekey",
28
+ "private-key",
29
+ "ssh_key",
30
+ "client_secret",
31
+ "client-secret",
32
+ "bearer",
33
+ ];
12
34
  /**
13
35
  * Build the sensitive key set from config.
14
- * If useBuiltIn is true, starts with BUILT_IN_SENSITIVE_KEYS,
15
- * adds `additional`, removes `excluded`.
16
36
  */
17
37
  function buildKeySet(config) {
18
38
  const keys = new Set();
@@ -41,10 +61,8 @@ export function sensitiveKeysPlugin(config) {
41
61
  name: "sensitive-keys",
42
62
  isKeySensitive: (key) => {
43
63
  const lower = key.toLowerCase();
44
- // Exact match first (fast path)
45
64
  if (keys.has(lower))
46
65
  return true;
47
- // Substring match
48
66
  for (const sensitive of keys) {
49
67
  if (lower.includes(sensitive))
50
68
  return true;
@@ -1 +1 @@
1
- {"version":3,"file":"sensitive-keys.js","sourceRoot":"","sources":["../../src/plugins/sensitive-keys.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAEzD;;;;GAIG;AACH,SAAS,WAAW,CAAC,MAA2B;IAC9C,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAE/B,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QACtB,KAAK,MAAM,CAAC,IAAI,uBAAuB,EAAE,CAAC;YACxC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACd,CAAC;IACH,CAAC;IAED,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,UAAU,IAA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