Clone log detailed message ouside the recursion
MODIFY
src/utils/Constants.ts
src/utils/Constants.ts
@@ -91,7 +91,10 @@ export default class Constants {
public static readonly REGEX_VALIDATION_LONGITUDE = /^-?([1]?[0-7][0-9]|[1]?[0-8][0]|[1-9]?[0-9])\.{0,1}[0-9]*$/;
public static readonly MAX_GPS_DISTANCE_METERS = 40000000; // Earth
- public static readonly SENSITIVE_DATA = Object.freeze(['name', 'firstName', 'password', 'repeatPassword', 'captcha', 'email', 'coordinates', 'latitude', 'longitude']);
+ public static readonly SENSITIVE_DATA = Object.freeze([
+ 'name', 'firstName', 'password', 'repeatPassword', 'captcha', 'email', 'coordinates', 'latitude', 'longitude',
+ 'Authorization', 'client_id', 'client_secret', 'refresh_token', 'localToken', 'token',
+ ]);
public static readonly MONGO_USER_MASK = Object.freeze({
'_id': 0,

MODIFY
src/utils/Logging.ts
src/utils/Logging.ts
@@ -680,7 +680,8 @@ export default class Logging {
// Process
log.process = log.process ? log.process : (cluster.isWorker ? 'worker ' + cluster.worker.id.toString() : 'master');
// Anonymize message
- log.detailedMessages = Logging.anonymizeSensitiveData(log.detailedMessages);
+ log.detailedMessages = Utils.cloneObject(log.detailedMessages);
+ Logging.anonymizeSensitiveData(log.detailedMessages);
// Check
if (log.detailedMessages) {
// Array?
@@ -710,7 +711,7 @@ export default class Logging {
}
}
- private static anonymizeSensitiveData(message: any): Promise<any> {
+ private static anonymizeSensitiveData(message: any): void {
if (!message || typeof message === 'number' || typeof message === 'boolean' || typeof message === 'function') {
// eslint-disable-next-line no-useless-return
return;
@@ -720,13 +721,10 @@ export default class Logging {
message.replace(new RegExp(sensitiveData, 'gi'), Constants.ANONYMIZED_VALUE);
}
} else if (Array.isArray(message)) {
- const items = [];
for (const item of message) {
- items.push(Logging.anonymizeSensitiveData(item))
+ Logging.anonymizeSensitiveData(item);
}
- message = items;
} else if (typeof message === 'object') {
- message = Utils.cloneObject(message);
for (const key of Object.keys(message)) {
// String?
if (typeof message[key] === 'string') {
@@ -751,7 +749,7 @@ export default class Logging {
message[key] = dataParts.join('&');
}
} else {
- message[key] = Logging.anonymizeSensitiveData(message[key]);
+ Logging.anonymizeSensitiveData(message[key]);
}
}
} else {
@@ -766,7 +764,6 @@ export default class Logging {
detailedMessages: { message: message }
});
}
- return message;
}
// Console Log

MODIFY
src/utils/Utils.ts
src/utils/Utils.ts
@@ -1036,6 +1036,9 @@ export default class Utils {
}
public static cloneObject<T>(object: T): T {
+ if (Utils.isNullOrUndefined(object)) {
+ return object;
+ }
return JSON.parse(JSON.stringify(object)) as T;
}

Clone log detailed message ouside the recursion