@x12i/logxer 4.0.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 +21 -0
- package/README.md +1255 -0
- package/dist/app-info.d.ts +25 -0
- package/dist/app-info.d.ts.map +1 -0
- package/dist/app-info.js +179 -0
- package/dist/app-info.js.map +1 -0
- package/dist/formatters/table-formatter.d.ts +23 -0
- package/dist/formatters/table-formatter.d.ts.map +1 -0
- package/dist/formatters/table-formatter.js +218 -0
- package/dist/formatters/table-formatter.js.map +1 -0
- package/dist/formatters/yaml-formatter.d.ts +14 -0
- package/dist/formatters/yaml-formatter.d.ts.map +1 -0
- package/dist/formatters/yaml-formatter.js +164 -0
- package/dist/formatters/yaml-formatter.js.map +1 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +219 -0
- package/dist/index.js.map +1 -0
- package/dist/logxer.d.ts +145 -0
- package/dist/logxer.d.ts.map +1 -0
- package/dist/logxer.js +811 -0
- package/dist/logxer.js.map +1 -0
- package/dist/outputs/shadow-sink.d.ts +83 -0
- package/dist/outputs/shadow-sink.d.ts.map +1 -0
- package/dist/outputs/shadow-sink.js +380 -0
- package/dist/outputs/shadow-sink.js.map +1 -0
- package/dist/outputs/unified-logger-output.d.ts +30 -0
- package/dist/outputs/unified-logger-output.d.ts.map +1 -0
- package/dist/outputs/unified-logger-output.js +125 -0
- package/dist/outputs/unified-logger-output.js.map +1 -0
- package/dist/sanitizer.d.ts +69 -0
- package/dist/sanitizer.d.ts.map +1 -0
- package/dist/sanitizer.js +507 -0
- package/dist/sanitizer.js.map +1 -0
- package/dist/trails/headers.d.ts +21 -0
- package/dist/trails/headers.d.ts.map +1 -0
- package/dist/trails/headers.js +121 -0
- package/dist/trails/headers.js.map +1 -0
- package/dist/trails/index.d.ts +59 -0
- package/dist/trails/index.d.ts.map +1 -0
- package/dist/trails/index.js +197 -0
- package/dist/trails/index.js.map +1 -0
- package/dist/types.d.ts +411 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/debug-config.d.ts +19 -0
- package/dist/utils/debug-config.d.ts.map +1 -0
- package/dist/utils/debug-config.js +172 -0
- package/dist/utils/debug-config.js.map +1 -0
- package/dist/utils/package-logs-level.d.ts +40 -0
- package/dist/utils/package-logs-level.d.ts.map +1 -0
- package/dist/utils/package-logs-level.js +79 -0
- package/dist/utils/package-logs-level.js.map +1 -0
- package/docs/package-usage.md +155 -0
- package/docs/package.md +48 -0
- package/docs/upgrade-for-package-authors.md +85 -0
- package/package.json +98 -0
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* logs-gateway - PII/Credentials Sanitizer
|
|
4
|
+
*
|
|
5
|
+
* This file contains the sanitization logic for detecting and masking sensitive data.
|
|
6
|
+
* Uses established npm packages for robust PII detection and sanitization.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.LogSanitizer = void 0;
|
|
43
|
+
const crypto = __importStar(require("crypto"));
|
|
44
|
+
// import fastRedact from 'fast-redact'; // Disabled for now
|
|
45
|
+
const sanitize_pii_1 = require("@cdssnc/sanitize-pii");
|
|
46
|
+
const validator = __importStar(require("validator"));
|
|
47
|
+
const xss_1 = require("xss");
|
|
48
|
+
/**
|
|
49
|
+
* Main sanitizer class for detecting and masking PII/credentials
|
|
50
|
+
*/
|
|
51
|
+
class LogSanitizer {
|
|
52
|
+
// private redactor: any; // Currently not used
|
|
53
|
+
constructor(config) {
|
|
54
|
+
this.config = {
|
|
55
|
+
enabled: false,
|
|
56
|
+
detectEmails: true,
|
|
57
|
+
detectIPs: true,
|
|
58
|
+
detectPhoneNumbers: true,
|
|
59
|
+
detectJWTs: true,
|
|
60
|
+
detectAPIKeys: true,
|
|
61
|
+
detectAWSCreds: true,
|
|
62
|
+
detectAzureKeys: true,
|
|
63
|
+
detectGCPKeys: true,
|
|
64
|
+
detectPasswords: true,
|
|
65
|
+
detectCreditCards: true,
|
|
66
|
+
maskWith: '[REDACTED]',
|
|
67
|
+
partialMaskRatio: 1.0,
|
|
68
|
+
maxDepth: 5,
|
|
69
|
+
keysDenylist: ['authorization', 'token', 'secret', 'api_key', 'passwd', 'password'],
|
|
70
|
+
keysAllowlist: [],
|
|
71
|
+
fieldsHashInsteadOfMask: [],
|
|
72
|
+
...config
|
|
73
|
+
};
|
|
74
|
+
// Validate maxDepth after config merge
|
|
75
|
+
this.config.maxDepth = Math.max(1, this.config.maxDepth);
|
|
76
|
+
// Initialize fast-redact for key-based redaction
|
|
77
|
+
// this.initializeRedactor(); // Disabled for now
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Initialize fast-redact with configuration
|
|
81
|
+
*/
|
|
82
|
+
// private initializeRedactor(): void {
|
|
83
|
+
// if (!this.config.enabled) {
|
|
84
|
+
// return;
|
|
85
|
+
// }
|
|
86
|
+
// // Build paths from denylist, supporting nested keys
|
|
87
|
+
// const paths = this.config.keysDenylist.filter(key => !key.includes('*')); // Only use exact paths for now
|
|
88
|
+
// this.redactor = fastRedact({
|
|
89
|
+
// paths,
|
|
90
|
+
// censor: this.config.maskWith,
|
|
91
|
+
// serialize: false
|
|
92
|
+
// });
|
|
93
|
+
// }
|
|
94
|
+
/**
|
|
95
|
+
* Sanitize a log entry's message and metadata
|
|
96
|
+
*/
|
|
97
|
+
sanitize(message, meta) {
|
|
98
|
+
if (!this.config.enabled) {
|
|
99
|
+
return {
|
|
100
|
+
sanitized: { message, data: meta },
|
|
101
|
+
redactionCount: 0,
|
|
102
|
+
truncated: false
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
const startTime = Date.now();
|
|
106
|
+
const maxTime = 100; // 100ms budget
|
|
107
|
+
let redactionCount = 0;
|
|
108
|
+
let truncated = false;
|
|
109
|
+
try {
|
|
110
|
+
// Sanitize message using pattern detection
|
|
111
|
+
const messageResult = this.sanitizeString(message, () => {
|
|
112
|
+
if (Date.now() - startTime > maxTime) {
|
|
113
|
+
truncated = true;
|
|
114
|
+
return message;
|
|
115
|
+
}
|
|
116
|
+
return this.detectAndMask(message);
|
|
117
|
+
});
|
|
118
|
+
const sanitizedMessage = messageResult.sanitized;
|
|
119
|
+
redactionCount += messageResult.redactionCount;
|
|
120
|
+
// Sanitize metadata using fast-redact for key-based redaction
|
|
121
|
+
let sanitizedMeta = meta;
|
|
122
|
+
if (meta && typeof meta === 'object') {
|
|
123
|
+
// Apply manual sanitization with key-based rules and hashing
|
|
124
|
+
const result = this.sanitizeObject(meta, 0, startTime, maxTime, new WeakSet());
|
|
125
|
+
sanitizedMeta = result.sanitized;
|
|
126
|
+
redactionCount += result.redactionCount;
|
|
127
|
+
truncated = truncated || result.truncated;
|
|
128
|
+
}
|
|
129
|
+
// Add sanitization metadata
|
|
130
|
+
if (sanitizedMeta && typeof sanitizedMeta === 'object') {
|
|
131
|
+
sanitizedMeta._sanitization = {
|
|
132
|
+
redactionCount,
|
|
133
|
+
truncated
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
sanitized: { message: sanitizedMessage, data: sanitizedMeta },
|
|
138
|
+
redactionCount,
|
|
139
|
+
truncated
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
// Handle sanitization errors gracefully
|
|
144
|
+
return {
|
|
145
|
+
sanitized: {
|
|
146
|
+
message: this.config.maskWith,
|
|
147
|
+
data: {
|
|
148
|
+
_sanitization: {
|
|
149
|
+
sanitizationError: true,
|
|
150
|
+
redactionCount: 0,
|
|
151
|
+
truncated: true
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
redactionCount: 0,
|
|
156
|
+
truncated: true
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Whether `fullPath` (lowercase, dot-separated) matches a deny/allow pattern.
|
|
162
|
+
* - `password` matches only path `password` (single segment).
|
|
163
|
+
* - `user.password` matches exactly that path.
|
|
164
|
+
* - `*.token` matches one segment + `.token` (e.g. `api.token`).
|
|
165
|
+
*/
|
|
166
|
+
pathMatchesPattern(fullPath, pattern) {
|
|
167
|
+
const fp = fullPath.toLowerCase();
|
|
168
|
+
const p = pattern.toLowerCase().trim();
|
|
169
|
+
if (!p)
|
|
170
|
+
return false;
|
|
171
|
+
if (p.includes('*')) {
|
|
172
|
+
if (p === '*.token') {
|
|
173
|
+
return /^[^.]+\.token$/.test(fp);
|
|
174
|
+
}
|
|
175
|
+
const parts = p.split('*');
|
|
176
|
+
const re = new RegExp('^' +
|
|
177
|
+
parts
|
|
178
|
+
.map((seg, i) => {
|
|
179
|
+
const escaped = seg.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
180
|
+
return i < parts.length - 1 ? `${escaped}[^.]*` : escaped;
|
|
181
|
+
})
|
|
182
|
+
.join('') +
|
|
183
|
+
'$');
|
|
184
|
+
return re.test(fp);
|
|
185
|
+
}
|
|
186
|
+
if (!p.includes('.')) {
|
|
187
|
+
return fp === p;
|
|
188
|
+
}
|
|
189
|
+
return fp === p;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Sanitize an object recursively
|
|
193
|
+
*/
|
|
194
|
+
sanitizeObject(obj, depth, startTime, maxTime, seen = new WeakSet(), pathPrefix = '') {
|
|
195
|
+
if (depth > this.config.maxDepth) {
|
|
196
|
+
return { sanitized: obj, redactionCount: 0, truncated: true };
|
|
197
|
+
}
|
|
198
|
+
if (Date.now() - startTime > maxTime) {
|
|
199
|
+
return { sanitized: this.config.maskWith, redactionCount: 1, truncated: true };
|
|
200
|
+
}
|
|
201
|
+
if (obj === null || obj === undefined) {
|
|
202
|
+
return { sanitized: obj, redactionCount: 0, truncated: false };
|
|
203
|
+
}
|
|
204
|
+
// Check for circular references
|
|
205
|
+
if (typeof obj === 'object' && seen.has(obj)) {
|
|
206
|
+
throw new Error('Circular reference detected');
|
|
207
|
+
}
|
|
208
|
+
// Add object to seen set for circular reference detection
|
|
209
|
+
if (typeof obj === 'object') {
|
|
210
|
+
seen.add(obj);
|
|
211
|
+
}
|
|
212
|
+
if (typeof obj === 'string') {
|
|
213
|
+
return this.sanitizeString(obj, () => this.detectAndMask(obj));
|
|
214
|
+
}
|
|
215
|
+
if (typeof obj === 'number' || typeof obj === 'boolean') {
|
|
216
|
+
return { sanitized: obj, redactionCount: 0, truncated: false };
|
|
217
|
+
}
|
|
218
|
+
if (Array.isArray(obj)) {
|
|
219
|
+
const sanitizedArray = [];
|
|
220
|
+
let totalRedactions = 0;
|
|
221
|
+
let truncated = false;
|
|
222
|
+
for (let i = 0; i < obj.length; i++) {
|
|
223
|
+
const item = obj[i];
|
|
224
|
+
const indexPath = pathPrefix ? `${pathPrefix}.${i}` : String(i);
|
|
225
|
+
const result = this.sanitizeObject(item, depth + 1, startTime, maxTime, seen, indexPath);
|
|
226
|
+
sanitizedArray.push(result.sanitized);
|
|
227
|
+
totalRedactions += result.redactionCount;
|
|
228
|
+
truncated = truncated || result.truncated;
|
|
229
|
+
}
|
|
230
|
+
return { sanitized: sanitizedArray, redactionCount: totalRedactions, truncated };
|
|
231
|
+
}
|
|
232
|
+
if (typeof obj === 'object') {
|
|
233
|
+
const sanitizedObj = {};
|
|
234
|
+
let totalRedactions = 0;
|
|
235
|
+
let truncated = false;
|
|
236
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
237
|
+
const lowerKey = key.toLowerCase();
|
|
238
|
+
const fullPath = pathPrefix ? `${pathPrefix}.${lowerKey}` : lowerKey;
|
|
239
|
+
const isInAllowlist = this.config.keysAllowlist.some((allowKey) => this.pathMatchesPattern(fullPath, allowKey));
|
|
240
|
+
if (isInAllowlist) {
|
|
241
|
+
sanitizedObj[key] = value;
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
// Check if this key should be hashed instead of masked
|
|
245
|
+
if (this.config.fieldsHashInsteadOfMask.includes(lowerKey)) {
|
|
246
|
+
if (typeof value === 'string') {
|
|
247
|
+
sanitizedObj[key] = this.hashValue(value);
|
|
248
|
+
totalRedactions++;
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
sanitizedObj[key] = value;
|
|
252
|
+
}
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
const shouldRedact = this.config.keysDenylist.some((denyKey) => this.pathMatchesPattern(fullPath, denyKey));
|
|
256
|
+
if (shouldRedact) {
|
|
257
|
+
sanitizedObj[key] = this.config.maskWith;
|
|
258
|
+
totalRedactions++;
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
// For other keys, only apply pattern detection to string values
|
|
262
|
+
if (typeof value === 'string') {
|
|
263
|
+
const sanitizedString = this.detectAndMask(value);
|
|
264
|
+
sanitizedObj[key] = sanitizedString;
|
|
265
|
+
if (sanitizedString !== value) {
|
|
266
|
+
totalRedactions++;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
const result = this.sanitizeObject(value, depth + 1, startTime, maxTime, seen, fullPath);
|
|
271
|
+
sanitizedObj[key] = result.sanitized;
|
|
272
|
+
totalRedactions += result.redactionCount;
|
|
273
|
+
truncated = truncated || result.truncated;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return { sanitized: sanitizedObj, redactionCount: totalRedactions, truncated };
|
|
277
|
+
}
|
|
278
|
+
return { sanitized: obj, redactionCount: 0, truncated: false };
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Sanitize a string value
|
|
282
|
+
*/
|
|
283
|
+
sanitizeString(str, detector) {
|
|
284
|
+
const sanitized = detector();
|
|
285
|
+
return {
|
|
286
|
+
sanitized,
|
|
287
|
+
redactionCount: sanitized !== str ? 1 : 0,
|
|
288
|
+
truncated: false
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Detect and mask sensitive patterns in a string using npm packages
|
|
293
|
+
*/
|
|
294
|
+
detectAndMask(str) {
|
|
295
|
+
let result = str;
|
|
296
|
+
// Use @cdssnc/sanitize-pii for comprehensive PII detection
|
|
297
|
+
if (this.config.detectEmails || this.config.detectIPs || this.config.detectPhoneNumbers) {
|
|
298
|
+
try {
|
|
299
|
+
result = (0, sanitize_pii_1.sanitizePii)(result, {
|
|
300
|
+
replacementTemplate: this.config.maskWith,
|
|
301
|
+
useDefaultPatterns: true
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
catch (error) {
|
|
305
|
+
// Fallback to custom patterns if the package fails
|
|
306
|
+
}
|
|
307
|
+
// Always apply custom patterns as fallback
|
|
308
|
+
result = this.fallbackPatternDetection(result);
|
|
309
|
+
}
|
|
310
|
+
// Use validator for additional email validation
|
|
311
|
+
if (this.config.detectEmails) {
|
|
312
|
+
result = result.replace(/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g, (match) => {
|
|
313
|
+
if (validator.isEmail(match)) {
|
|
314
|
+
return this.config.maskWith;
|
|
315
|
+
}
|
|
316
|
+
return match;
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
// Custom patterns for credentials and tokens
|
|
320
|
+
result = this.detectCredentials(result);
|
|
321
|
+
// XSS protection
|
|
322
|
+
result = (0, xss_1.filterXSS)(result, {
|
|
323
|
+
whiteList: {}, // Remove all HTML tags
|
|
324
|
+
stripIgnoreTag: true,
|
|
325
|
+
stripIgnoreTagBody: ['script']
|
|
326
|
+
});
|
|
327
|
+
return result;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Fallback pattern detection if npm packages fail
|
|
331
|
+
*/
|
|
332
|
+
fallbackPatternDetection(str) {
|
|
333
|
+
let result = str;
|
|
334
|
+
// Email addresses
|
|
335
|
+
if (this.config.detectEmails) {
|
|
336
|
+
result = result.replace(/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g, this.config.maskWith);
|
|
337
|
+
}
|
|
338
|
+
// IP addresses (IPv4 and IPv6)
|
|
339
|
+
if (this.config.detectIPs) {
|
|
340
|
+
// IPv4 addresses
|
|
341
|
+
result = result.replace(/\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/g, this.config.maskWith);
|
|
342
|
+
// IPv6 addresses - comprehensive pattern
|
|
343
|
+
result = result.replace(/\b(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\b/g, this.config.maskWith);
|
|
344
|
+
// Simple pattern for any IPv6-like string with :: (most general, run first)
|
|
345
|
+
result = result.replace(/[0-9a-fA-F]+:[0-9a-fA-F]+::[0-9a-fA-F]+/g, this.config.maskWith);
|
|
346
|
+
result = result.replace(/\b(?:[0-9a-fA-F]{1,4}:)*::(?:[0-9a-fA-F]{1,4}:)*[0-9a-fA-F]{1,4}\b/g, this.config.maskWith);
|
|
347
|
+
result = result.replace(/\b::(?:[0-9a-fA-F]{1,4}:){0,6}[0-9a-fA-F]{1,4}\b/g, this.config.maskWith);
|
|
348
|
+
result = result.replace(/\b(?:[0-9a-fA-F]{1,4}:){1,7}:\b/g, this.config.maskWith);
|
|
349
|
+
}
|
|
350
|
+
// Phone numbers (basic patterns)
|
|
351
|
+
if (this.config.detectPhoneNumbers) {
|
|
352
|
+
// US phone numbers
|
|
353
|
+
result = result.replace(/\b(?:\+?1[-.\s]?)?\(?[0-9]{3}\)?[-.\s]?[0-9]{3}[-.\s]?[0-9]{4}\b/g, this.config.maskWith);
|
|
354
|
+
// International phone numbers with country codes
|
|
355
|
+
result = result.replace(/\b\+[1-9]\d{1,3}[\s-]?\d{1,4}[\s-]?\d{1,4}[\s-]?\d{1,9}\b/g, this.config.maskWith);
|
|
356
|
+
// More flexible pattern for international numbers with spaces
|
|
357
|
+
result = result.replace(/\b\+[1-9]\d{1,3}\s+\d{1,4}\s+\d{1,4}\s+\d{1,9}\b/g, this.config.maskWith);
|
|
358
|
+
// Pattern without word boundaries for better matching
|
|
359
|
+
result = result.replace(/\+[1-9]\d{1,3}\s+\d+\s+\d+\s+\d+/g, this.config.maskWith);
|
|
360
|
+
// Generic phone number pattern
|
|
361
|
+
result = result.replace(/\b\+?[1-9]\d{1,14}\b/g, (match) => {
|
|
362
|
+
// More specific phone number validation
|
|
363
|
+
if (match.length >= 10 && match.length <= 15) {
|
|
364
|
+
return this.config.maskWith;
|
|
365
|
+
}
|
|
366
|
+
return match;
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
return result;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Detect credentials and API keys using custom patterns
|
|
373
|
+
*/
|
|
374
|
+
detectCredentials(str) {
|
|
375
|
+
let result = str;
|
|
376
|
+
// JWTs
|
|
377
|
+
if (this.config.detectJWTs) {
|
|
378
|
+
result = result.replace(/\beyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*\b/g, this.config.maskWith);
|
|
379
|
+
}
|
|
380
|
+
// API keys (generic patterns)
|
|
381
|
+
if (this.config.detectAPIKeys) {
|
|
382
|
+
result = result.replace(/\b[A-Za-z0-9_-]{20,}\b/g, (match) => {
|
|
383
|
+
// Skip if it looks like a normal word or number
|
|
384
|
+
if (/^[0-9]+$/.test(match) || /^[A-Za-z]+$/.test(match)) {
|
|
385
|
+
return match;
|
|
386
|
+
}
|
|
387
|
+
return this.config.maskWith;
|
|
388
|
+
});
|
|
389
|
+
// Specific API key patterns
|
|
390
|
+
result = result.replace(/\bsk-[A-Za-z0-9]{10,}\b/g, this.config.maskWith);
|
|
391
|
+
result = result.replace(/\bak_[A-Za-z0-9]{10,}\b/g, this.config.maskWith);
|
|
392
|
+
}
|
|
393
|
+
// AWS credentials
|
|
394
|
+
if (this.config.detectAWSCreds) {
|
|
395
|
+
result = result.replace(/\bAKIA[0-9A-Z]{16}\b/g, this.config.maskWith);
|
|
396
|
+
result = result.replace(/\baws_secret_access_key\s*[:=]\s*[A-Za-z0-9/+=]{40}\b/g, this.config.maskWith);
|
|
397
|
+
}
|
|
398
|
+
// Azure keys
|
|
399
|
+
if (this.config.detectAzureKeys) {
|
|
400
|
+
result = result.replace(/\b[A-Za-z0-9+/]{32,}={0,2}\b/g, (match) => {
|
|
401
|
+
// More specific Azure key patterns
|
|
402
|
+
if (match.length >= 32 && match.length <= 44) {
|
|
403
|
+
return this.config.maskWith;
|
|
404
|
+
}
|
|
405
|
+
return match;
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
// GCP keys
|
|
409
|
+
if (this.config.detectGCPKeys) {
|
|
410
|
+
result = result.replace(/\b[A-Za-z0-9_-]{24,}\b/g, (match) => {
|
|
411
|
+
// GCP service account keys are typically longer
|
|
412
|
+
if (match.length >= 24) {
|
|
413
|
+
return this.config.maskWith;
|
|
414
|
+
}
|
|
415
|
+
return match;
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
// Password fields
|
|
419
|
+
if (this.config.detectPasswords) {
|
|
420
|
+
result = result.replace(/\b(?:password|pass|pwd)\s*[:=]\s*[^\s]+\b/gi, this.config.maskWith);
|
|
421
|
+
}
|
|
422
|
+
// Credit cards (Luhn algorithm)
|
|
423
|
+
if (this.config.detectCreditCards) {
|
|
424
|
+
result = result.replace(/\b(?:\d{4}[-\s]?){3}\d{4}\b/g, (match) => {
|
|
425
|
+
const digits = match.replace(/[-\s]/g, '');
|
|
426
|
+
if (this.isValidCreditCard(digits)) {
|
|
427
|
+
return this.config.maskWith;
|
|
428
|
+
}
|
|
429
|
+
return match;
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
return result;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Apply pattern detection to object values
|
|
436
|
+
*/
|
|
437
|
+
applyPatternDetectionToObject(obj, startTime, maxTime) {
|
|
438
|
+
if (Date.now() - startTime > maxTime) {
|
|
439
|
+
return obj;
|
|
440
|
+
}
|
|
441
|
+
if (obj === null || obj === undefined) {
|
|
442
|
+
return obj;
|
|
443
|
+
}
|
|
444
|
+
if (typeof obj === 'string') {
|
|
445
|
+
return this.detectAndMask(obj);
|
|
446
|
+
}
|
|
447
|
+
if (typeof obj === 'number' || typeof obj === 'boolean') {
|
|
448
|
+
return obj;
|
|
449
|
+
}
|
|
450
|
+
if (Array.isArray(obj)) {
|
|
451
|
+
return obj.map(item => this.applyPatternDetectionToObject(item, startTime, maxTime));
|
|
452
|
+
}
|
|
453
|
+
if (typeof obj === 'object') {
|
|
454
|
+
const result = {};
|
|
455
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
456
|
+
// Skip sanitization metadata
|
|
457
|
+
if (key === '_sanitization') {
|
|
458
|
+
result[key] = value;
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
461
|
+
// Apply hashing for specified fields
|
|
462
|
+
if (this.config.fieldsHashInsteadOfMask.includes(key.toLowerCase()) && typeof value === 'string') {
|
|
463
|
+
result[key] = this.hashValue(value);
|
|
464
|
+
// redactionCount++; // This variable is not in scope here
|
|
465
|
+
}
|
|
466
|
+
else {
|
|
467
|
+
result[key] = this.applyPatternDetectionToObject(value, startTime, maxTime);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
return result;
|
|
471
|
+
}
|
|
472
|
+
return obj;
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Hash a value using SHA-256
|
|
476
|
+
*/
|
|
477
|
+
hashValue(value) {
|
|
478
|
+
return crypto.createHash('sha256').update(value).digest('hex');
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Validate credit card number using Luhn algorithm
|
|
482
|
+
*/
|
|
483
|
+
isValidCreditCard(cardNumber) {
|
|
484
|
+
if (!/^\d{13,19}$/.test(cardNumber)) {
|
|
485
|
+
return false;
|
|
486
|
+
}
|
|
487
|
+
let sum = 0;
|
|
488
|
+
let isEven = false;
|
|
489
|
+
for (let i = cardNumber.length - 1; i >= 0; i--) {
|
|
490
|
+
const char = cardNumber[i];
|
|
491
|
+
if (!char)
|
|
492
|
+
continue;
|
|
493
|
+
let digit = parseInt(char);
|
|
494
|
+
if (isEven) {
|
|
495
|
+
digit *= 2;
|
|
496
|
+
if (digit > 9) {
|
|
497
|
+
digit -= 9;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
sum += digit;
|
|
501
|
+
isEven = !isEven;
|
|
502
|
+
}
|
|
503
|
+
return sum % 10 === 0;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
exports.LogSanitizer = LogSanitizer;
|
|
507
|
+
//# sourceMappingURL=sanitizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitizer.js","sourceRoot":"","sources":["../src/sanitizer.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,+CAAiC;AACjC,4DAA4D;AAC5D,uDAAmD;AACnD,qDAAuC;AACvC,6BAAgC;AAYhC;;GAEG;AACH,MAAa,YAAY;IAEvB,+CAA+C;IAE/C,YAAY,MAA0B;QACpC,IAAI,CAAC,MAAM,GAAG;YACZ,OAAO,EAAE,KAAK;YACd,YAAY,EAAE,IAAI;YAClB,SAAS,EAAE,IAAI;YACf,kBAAkB,EAAE,IAAI;YACxB,UAAU,EAAE,IAAI;YAChB,aAAa,EAAE,IAAI;YACnB,cAAc,EAAE,IAAI;YACpB,eAAe,EAAE,IAAI;YACrB,aAAa,EAAE,IAAI;YACnB,eAAe,EAAE,IAAI;YACrB,iBAAiB,EAAE,IAAI;YACvB,QAAQ,EAAE,YAAY;YACtB,gBAAgB,EAAE,GAAG;YACrB,QAAQ,EAAE,CAAC;YACX,YAAY,EAAE,CAAC,eAAe,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,CAAC;YACnF,aAAa,EAAE,EAAE;YACjB,uBAAuB,EAAE,EAAE;YAC3B,GAAG,MAAM;SACV,CAAC;QAEF,uCAAuC;QACvC,IAAI,CAAC,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,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Ctx } from '../types';
|
|
5
|
+
/**
|
|
6
|
+
* Inject thread context into HTTP headers
|
|
7
|
+
*/
|
|
8
|
+
export declare function injectThreadHeaders(headers: Record<string, string>, context: ThreadContext): void;
|
|
9
|
+
/**
|
|
10
|
+
* Extract thread context from HTTP headers
|
|
11
|
+
*/
|
|
12
|
+
export declare function extractThreadHeaders(headers: Record<string, string>): Partial<ThreadContext>;
|
|
13
|
+
/**
|
|
14
|
+
* Inject operation context into HTTP headers
|
|
15
|
+
*/
|
|
16
|
+
export declare function injectOperationHeaders(headers: Record<string, string>, context: OperationCtx): void;
|
|
17
|
+
/**
|
|
18
|
+
* Extract operation context from HTTP headers
|
|
19
|
+
*/
|
|
20
|
+
export declare function extractOperationHeaders(headers: Record<string, string>): Partial<OperationCtx>;
|
|
21
|
+
//# sourceMappingURL=headers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headers.d.ts","sourceRoot":"","sources":["../../src/trails/headers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE5D;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,OAAO,EAAE,aAAa,GACrB,IAAI,CA2BN;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,OAAO,CAAC,aAAa,CAAC,CA6CxB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,OAAO,EAAE,YAAY,GACpB,IAAI,CAWN;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,OAAO,CAAC,YAAY,CAAC,CAmCvB"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Header injection and extraction for trails context
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.injectThreadHeaders = injectThreadHeaders;
|
|
7
|
+
exports.extractThreadHeaders = extractThreadHeaders;
|
|
8
|
+
exports.injectOperationHeaders = injectOperationHeaders;
|
|
9
|
+
exports.extractOperationHeaders = extractOperationHeaders;
|
|
10
|
+
/**
|
|
11
|
+
* Inject thread context into HTTP headers
|
|
12
|
+
*/
|
|
13
|
+
function injectThreadHeaders(headers, context) {
|
|
14
|
+
headers['x-thread-id'] = context.threadId;
|
|
15
|
+
headers['x-event-id'] = context.eventId;
|
|
16
|
+
headers['x-seq-no'] = context.sequenceNo.toString();
|
|
17
|
+
if (context.causationId) {
|
|
18
|
+
const causationStr = Array.isArray(context.causationId)
|
|
19
|
+
? context.causationId.join(',')
|
|
20
|
+
: context.causationId;
|
|
21
|
+
headers['x-causation-id'] = causationStr;
|
|
22
|
+
}
|
|
23
|
+
if (context.partitionKey) {
|
|
24
|
+
headers['x-partition-key'] = context.partitionKey;
|
|
25
|
+
}
|
|
26
|
+
if (context.attempt !== undefined) {
|
|
27
|
+
headers['x-attempt'] = context.attempt.toString();
|
|
28
|
+
}
|
|
29
|
+
if (context.shardId) {
|
|
30
|
+
headers['x-shard-id'] = context.shardId;
|
|
31
|
+
}
|
|
32
|
+
if (context.workerId) {
|
|
33
|
+
headers['x-worker-id'] = context.workerId;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Extract thread context from HTTP headers
|
|
38
|
+
*/
|
|
39
|
+
function extractThreadHeaders(headers) {
|
|
40
|
+
const context = {};
|
|
41
|
+
if (headers['x-thread-id']) {
|
|
42
|
+
context.threadId = headers['x-thread-id'];
|
|
43
|
+
}
|
|
44
|
+
if (headers['x-event-id']) {
|
|
45
|
+
context.eventId = headers['x-event-id'];
|
|
46
|
+
}
|
|
47
|
+
if (headers['x-seq-no']) {
|
|
48
|
+
const seqNo = parseInt(headers['x-seq-no'], 10);
|
|
49
|
+
if (!isNaN(seqNo)) {
|
|
50
|
+
context.sequenceNo = seqNo;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (headers['x-causation-id']) {
|
|
54
|
+
const causationStr = headers['x-causation-id'];
|
|
55
|
+
context.causationId = causationStr.includes(',')
|
|
56
|
+
? causationStr.split(',')
|
|
57
|
+
: causationStr;
|
|
58
|
+
}
|
|
59
|
+
if (headers['x-partition-key']) {
|
|
60
|
+
context.partitionKey = headers['x-partition-key'];
|
|
61
|
+
}
|
|
62
|
+
if (headers['x-attempt']) {
|
|
63
|
+
const attempt = parseInt(headers['x-attempt'], 10);
|
|
64
|
+
if (!isNaN(attempt)) {
|
|
65
|
+
context.attempt = attempt;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (headers['x-shard-id']) {
|
|
69
|
+
context.shardId = headers['x-shard-id'];
|
|
70
|
+
}
|
|
71
|
+
if (headers['x-worker-id']) {
|
|
72
|
+
context.workerId = headers['x-worker-id'];
|
|
73
|
+
}
|
|
74
|
+
return context;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Inject operation context into HTTP headers
|
|
78
|
+
*/
|
|
79
|
+
function injectOperationHeaders(headers, context) {
|
|
80
|
+
headers['x-operation-id'] = context.operationId;
|
|
81
|
+
headers['x-operation-name'] = context.operationName;
|
|
82
|
+
headers['x-operation-path'] = context.operationPath;
|
|
83
|
+
headers['x-operation-step'] = context.operationStep.toString();
|
|
84
|
+
headers['x-trace-id'] = context.traceId;
|
|
85
|
+
headers['x-span-id'] = context.spanId;
|
|
86
|
+
if (context.parentOperationId) {
|
|
87
|
+
headers['x-parent-operation-id'] = context.parentOperationId;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Extract operation context from HTTP headers
|
|
92
|
+
*/
|
|
93
|
+
function extractOperationHeaders(headers) {
|
|
94
|
+
const context = {};
|
|
95
|
+
if (headers['x-operation-id']) {
|
|
96
|
+
context.operationId = headers['x-operation-id'];
|
|
97
|
+
}
|
|
98
|
+
if (headers['x-parent-operation-id']) {
|
|
99
|
+
context.parentOperationId = headers['x-parent-operation-id'];
|
|
100
|
+
}
|
|
101
|
+
if (headers['x-operation-name']) {
|
|
102
|
+
context.operationName = headers['x-operation-name'];
|
|
103
|
+
}
|
|
104
|
+
if (headers['x-operation-path']) {
|
|
105
|
+
context.operationPath = headers['x-operation-path'];
|
|
106
|
+
}
|
|
107
|
+
if (headers['x-operation-step']) {
|
|
108
|
+
const step = parseInt(headers['x-operation-step'], 10);
|
|
109
|
+
if (!isNaN(step)) {
|
|
110
|
+
context.operationStep = step;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (headers['x-trace-id']) {
|
|
114
|
+
context.traceId = headers['x-trace-id'];
|
|
115
|
+
}
|
|
116
|
+
if (headers['x-span-id']) {
|
|
117
|
+
context.spanId = headers['x-span-id'];
|
|
118
|
+
}
|
|
119
|
+
return context;
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=headers.js.map
|