@creator.co/wapi 1.5.0 → 1.5.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/dist/package.json
CHANGED
|
@@ -16,10 +16,12 @@ export declare enum LOG_LEVELS {
|
|
|
16
16
|
* Configuration options for the logger.
|
|
17
17
|
* @typedef {Object} LoggerConfig
|
|
18
18
|
* @property {boolean | Array<string>} [sensitiveFilteringKeywords] - Specifies whether to filter sensitive keywords in log messages. Can be a boolean value or an array of strings.
|
|
19
|
+
* @property {number} [sensitiveMaxKeys] - Maximum number of keys from an object that sensitive filtering will be applied to. Default value is 10; Increases here should be together with max size at node VM
|
|
19
20
|
* @property {LOG_LEVELS | string} [logLevel] - The log level to use for logging. Can be one of the predefined log levels or a custom string value.
|
|
20
21
|
*/
|
|
21
22
|
export type LoggerConfig = {
|
|
22
23
|
sensitiveFilteringKeywords?: boolean | Array<string>;
|
|
24
|
+
sensitiveMaxKeys?: number;
|
|
23
25
|
logLevel?: LOG_LEVELS | string;
|
|
24
26
|
};
|
|
25
27
|
/**
|
|
@@ -349,6 +349,7 @@ var Logger = /** @class */ (function () {
|
|
|
349
349
|
*/
|
|
350
350
|
Logger.prototype.suppressSensitiveInfo = function (value) {
|
|
351
351
|
var _this = this;
|
|
352
|
+
var _a;
|
|
352
353
|
//really false
|
|
353
354
|
if (!this.filterBlacklist || !this.filterBlacklist[0])
|
|
354
355
|
return value;
|
|
@@ -357,11 +358,19 @@ var Logger = /** @class */ (function () {
|
|
|
357
358
|
return value;
|
|
358
359
|
// continue handling for each type
|
|
359
360
|
if (typeof value == 'string') {
|
|
361
|
+
// Try to parse json string
|
|
362
|
+
try {
|
|
363
|
+
return this.suppressSensitiveInfo(JSON.parse(value));
|
|
364
|
+
}
|
|
365
|
+
catch (_b) {
|
|
366
|
+
/* No handling */
|
|
367
|
+
}
|
|
360
368
|
//content based replacement
|
|
361
369
|
this.filterBlacklist.forEach(function (f) {
|
|
370
|
+
var _a;
|
|
362
371
|
var match = value.toLowerCase().includes(f);
|
|
363
372
|
if (match)
|
|
364
|
-
value =
|
|
373
|
+
value = "**SUPPRESSED_SENSITIVE_DATA** (".concat(((_a = String(value)) === null || _a === void 0 ? void 0 : _a.length) || 0, " len)");
|
|
365
374
|
});
|
|
366
375
|
return value;
|
|
367
376
|
}
|
|
@@ -369,14 +378,17 @@ var Logger = /** @class */ (function () {
|
|
|
369
378
|
return value.map(function (v) { return _this.suppressSensitiveInfo(v); });
|
|
370
379
|
}
|
|
371
380
|
else if (typeof value == 'object') {
|
|
372
|
-
//avoid supressing long objects and causing stack overflow
|
|
373
|
-
if (Object.keys(value).length >= 10)
|
|
381
|
+
// avoid supressing long objects and causing stack overflow
|
|
382
|
+
if (Object.keys(value).length >= (((_a = this.config) === null || _a === void 0 ? void 0 : _a.sensitiveMaxKeys) || 10))
|
|
374
383
|
return value;
|
|
375
|
-
//key based replacement
|
|
384
|
+
// key based replacement
|
|
376
385
|
Object.keys(value).forEach(function (elt) {
|
|
377
|
-
var
|
|
378
|
-
|
|
379
|
-
|
|
386
|
+
var _a;
|
|
387
|
+
// do not match sensitive keys with null vals
|
|
388
|
+
var match = value[elt] && _this.filterBlacklist.find(function (f) { return elt.toLowerCase().includes(f); });
|
|
389
|
+
if (match) {
|
|
390
|
+
value[elt] = "**SUPPRESSED_SENSITIVE_DATA** (".concat(((_a = String(value[elt])) === null || _a === void 0 ? void 0 : _a.length) || 0, " len)");
|
|
391
|
+
}
|
|
380
392
|
else
|
|
381
393
|
value[elt] = _this.suppressSensitiveInfo(value[elt]);
|
|
382
394
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Logger.js","sourceRoot":"","sources":["../../../src/Logger/Logger.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,6BAA8B;AAC9B,+CAAgD;AAChD,wCAAyC;AAEzC,sCAAgC;AAEhC;;;;;;;GAOG;AACH,IAAY,UAKX;AALD,WAAY,UAAU;IACpB,6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src/Logger/Logger.ts
CHANGED
|
@@ -44,10 +44,12 @@ const blacklist = ['password', 'token', 'accounts'].map(s => s.toLowerCase())
|
|
|
44
44
|
* Configuration options for the logger.
|
|
45
45
|
* @typedef {Object} LoggerConfig
|
|
46
46
|
* @property {boolean | Array<string>} [sensitiveFilteringKeywords] - Specifies whether to filter sensitive keywords in log messages. Can be a boolean value or an array of strings.
|
|
47
|
+
* @property {number} [sensitiveMaxKeys] - Maximum number of keys from an object that sensitive filtering will be applied to. Default value is 10; Increases here should be together with max size at node VM
|
|
47
48
|
* @property {LOG_LEVELS | string} [logLevel] - The log level to use for logging. Can be one of the predefined log levels or a custom string value.
|
|
48
49
|
*/
|
|
49
50
|
export type LoggerConfig = {
|
|
50
51
|
sensitiveFilteringKeywords?: boolean | Array<string>
|
|
52
|
+
sensitiveMaxKeys?: number
|
|
51
53
|
logLevel?: LOG_LEVELS | string
|
|
52
54
|
}
|
|
53
55
|
|
|
@@ -293,22 +295,31 @@ export default class Logger {
|
|
|
293
295
|
if (!value) return value
|
|
294
296
|
// continue handling for each type
|
|
295
297
|
if (typeof value == 'string') {
|
|
298
|
+
// Try to parse json string
|
|
299
|
+
try {
|
|
300
|
+
return this.suppressSensitiveInfo(JSON.parse(value))
|
|
301
|
+
} catch {
|
|
302
|
+
/* No handling */
|
|
303
|
+
}
|
|
296
304
|
//content based replacement
|
|
297
305
|
this.filterBlacklist.forEach(f => {
|
|
298
306
|
const match = value.toLowerCase().includes(f)
|
|
299
|
-
if (match) value =
|
|
307
|
+
if (match) value = `**SUPPRESSED_SENSITIVE_DATA** (${String(value)?.length || 0} len)`
|
|
300
308
|
})
|
|
301
309
|
return value
|
|
302
310
|
} else if (Array.isArray(value)) {
|
|
303
311
|
return value.map(v => this.suppressSensitiveInfo(v))
|
|
304
312
|
} else if (typeof value == 'object') {
|
|
305
|
-
//avoid supressing long objects and causing stack overflow
|
|
306
|
-
if (Object.keys(value).length >= 10) return value
|
|
307
|
-
//key based replacement
|
|
313
|
+
// avoid supressing long objects and causing stack overflow
|
|
314
|
+
if (Object.keys(value).length >= (this.config?.sensitiveMaxKeys || 10)) return value
|
|
315
|
+
// key based replacement
|
|
308
316
|
Object.keys(value).forEach(elt => {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
317
|
+
// do not match sensitive keys with null vals
|
|
318
|
+
const match =
|
|
319
|
+
value[elt] && (this.filterBlacklist as string[]).find(f => elt.toLowerCase().includes(f))
|
|
320
|
+
if (match) {
|
|
321
|
+
value[elt] = `**SUPPRESSED_SENSITIVE_DATA** (${String(value[elt])?.length || 0} len)`
|
|
322
|
+
} else value[elt] = this.suppressSensitiveInfo(value[elt])
|
|
312
323
|
})
|
|
313
324
|
return value
|
|
314
325
|
}
|
|
@@ -23,6 +23,16 @@ function fixLogTypePrefix(logType: string) {
|
|
|
23
23
|
return logType
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
function randomDeepObject(count, endKey) {
|
|
27
|
+
if (count <= 1) return { [endKey]: 'value' }
|
|
28
|
+
const object = {}
|
|
29
|
+
for (let i = 0; i < count; i++) {
|
|
30
|
+
const key = (+new Date() * Math.random()).toString(36).substring(0, 6)
|
|
31
|
+
object[key] = randomDeepObject(Math.floor(Math.random() * (count / 2)), endKey)
|
|
32
|
+
}
|
|
33
|
+
return object
|
|
34
|
+
}
|
|
35
|
+
|
|
26
36
|
function testLogs(isContainer: boolean, provider?: Logger) {
|
|
27
37
|
const type = isContainer ? 'container' : 'serverless'
|
|
28
38
|
const loggerType = !provider ? 'Console' : 'Logger'
|
|
@@ -37,7 +47,7 @@ function testLogs(isContainer: boolean, provider?: Logger) {
|
|
|
37
47
|
)
|
|
38
48
|
expect(consoleProxy.log).toHaveBeenNthCalledWith(
|
|
39
49
|
1,
|
|
40
|
-
expect.stringContaining('] **SUPPRESSED_SENSITIVE_DATA**')
|
|
50
|
+
expect.stringContaining('] **SUPPRESSED_SENSITIVE_DATA** (18 len)')
|
|
41
51
|
)
|
|
42
52
|
})
|
|
43
53
|
|
|
@@ -51,13 +61,43 @@ function testLogs(isContainer: boolean, provider?: Logger) {
|
|
|
51
61
|
)
|
|
52
62
|
expect(consoleProxy.log).toHaveBeenNthCalledWith(
|
|
53
63
|
1,
|
|
54
|
-
expect.stringContaining('] TEST {\n "password": "**SUPPRESSED_SENSITIVE_DATA**"\n}')
|
|
64
|
+
expect.stringContaining('] TEST {\n "password": "**SUPPRESSED_SENSITIVE_DATA** (3 len)"\n}')
|
|
55
65
|
)
|
|
56
66
|
// test if object is not mutate
|
|
57
67
|
c_expect(object.password).to.be.equals('123')
|
|
58
68
|
})
|
|
59
69
|
|
|
70
|
+
test(`${type} - ${loggerType} Log - Suppress sensitive info (long-object)`, async () => {
|
|
71
|
+
setContainerFlag(isContainer)
|
|
72
|
+
const object = randomDeepObject(99, 'password')
|
|
73
|
+
localProvider.log('TEST', object)
|
|
74
|
+
expect(consoleProxy.log).toHaveBeenNthCalledWith(
|
|
75
|
+
1,
|
|
76
|
+
expect.stringContaining((isContainer ? `${transactionID} ` : '') + '[INFO] [Logger.test.ts:')
|
|
77
|
+
)
|
|
78
|
+
expect(consoleProxy.log).toHaveBeenNthCalledWith(1, expect.stringContaining('] TEST'))
|
|
79
|
+
expect(consoleProxy.log).toHaveBeenNthCalledWith(
|
|
80
|
+
1,
|
|
81
|
+
expect.stringContaining('"password": "**SUPPRESSED_SENSITIVE_DATA** (5 len)"')
|
|
82
|
+
)
|
|
83
|
+
})
|
|
84
|
+
|
|
60
85
|
test(`${type} - ${loggerType} Log - Suppress sensitive info (object with sensitive string)`, async () => {
|
|
86
|
+
setContainerFlag(isContainer)
|
|
87
|
+
localProvider.log({ object: JSON.stringify({ password: '123' }) })
|
|
88
|
+
expect(consoleProxy.log).toHaveBeenNthCalledWith(
|
|
89
|
+
1,
|
|
90
|
+
expect.stringContaining((isContainer ? `${transactionID} ` : '') + '[INFO] [Logger.test.ts:')
|
|
91
|
+
)
|
|
92
|
+
expect(consoleProxy.log).toHaveBeenNthCalledWith(
|
|
93
|
+
1,
|
|
94
|
+
expect.stringContaining(
|
|
95
|
+
'] {\n "object": {\n "password": "**SUPPRESSED_SENSITIVE_DATA** (3 len)"\n }\n}'
|
|
96
|
+
)
|
|
97
|
+
)
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
test(`${type} - ${loggerType} Log - Suppress sensitive info (object with sensitive number)`, async () => {
|
|
61
101
|
setContainerFlag(isContainer)
|
|
62
102
|
localProvider.log({ object: JSON.stringify({ password: 123 }) })
|
|
63
103
|
expect(consoleProxy.log).toHaveBeenNthCalledWith(
|
|
@@ -66,7 +106,22 @@ function testLogs(isContainer: boolean, provider?: Logger) {
|
|
|
66
106
|
)
|
|
67
107
|
expect(consoleProxy.log).toHaveBeenNthCalledWith(
|
|
68
108
|
1,
|
|
69
|
-
expect.stringContaining(
|
|
109
|
+
expect.stringContaining(
|
|
110
|
+
'] {\n "object": {\n "password": "**SUPPRESSED_SENSITIVE_DATA** (3 len)"\n }\n}'
|
|
111
|
+
)
|
|
112
|
+
)
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
test(`${type} - ${loggerType} Log - Suppress sensitive info (null key)`, async () => {
|
|
116
|
+
setContainerFlag(isContainer)
|
|
117
|
+
localProvider.log({ object: JSON.stringify({ password: null }) })
|
|
118
|
+
expect(consoleProxy.log).toHaveBeenNthCalledWith(
|
|
119
|
+
1,
|
|
120
|
+
expect.stringContaining((isContainer ? `${transactionID} ` : '') + '[INFO] [Logger.test.ts:')
|
|
121
|
+
)
|
|
122
|
+
expect(consoleProxy.log).toHaveBeenNthCalledWith(
|
|
123
|
+
1,
|
|
124
|
+
expect.stringContaining('] {\n "object": {\n "password": null\n }\n}')
|
|
70
125
|
)
|
|
71
126
|
})
|
|
72
127
|
|
|
@@ -82,7 +137,7 @@ function testLogs(isContainer: boolean, provider?: Logger) {
|
|
|
82
137
|
|
|
83
138
|
test(`${type} - ${loggerType} Log - Suppress sensitive info (array)`, async () => {
|
|
84
139
|
setContainerFlag(isContainer)
|
|
85
|
-
localProvider.log('TEST2', [{ password: '
|
|
140
|
+
localProvider.log('TEST2', [{ password: '1234' }])
|
|
86
141
|
expect(consoleProxy.log).toHaveBeenNthCalledWith(
|
|
87
142
|
1,
|
|
88
143
|
expect.stringContaining((isContainer ? `${transactionID} ` : '') + '[INFO] [Logger.test.ts:')
|
|
@@ -90,7 +145,7 @@ function testLogs(isContainer: boolean, provider?: Logger) {
|
|
|
90
145
|
expect(consoleProxy.log).toHaveBeenNthCalledWith(
|
|
91
146
|
1,
|
|
92
147
|
expect.stringContaining(
|
|
93
|
-
'] TEST2 [\n {\n "password": "**SUPPRESSED_SENSITIVE_DATA**"\n }\n]'
|
|
148
|
+
'] TEST2 [\n {\n "password": "**SUPPRESSED_SENSITIVE_DATA** (4 len)"\n }\n]'
|
|
94
149
|
)
|
|
95
150
|
)
|
|
96
151
|
})
|
|
@@ -124,6 +179,7 @@ describe('Logger', () => {
|
|
|
124
179
|
{
|
|
125
180
|
logLevel: 'DEBUG',
|
|
126
181
|
sensitiveFilteringKeywords: true,
|
|
182
|
+
sensitiveMaxKeys: 100,
|
|
127
183
|
},
|
|
128
184
|
transactionID
|
|
129
185
|
)
|