Skip to content

Commit ccc29bf

Browse files
authored
Merge pull request #4668 from dpalou/MOBILE-4969
MOBILE-4969 error-log: Hide token-like info
2 parents 0f606da + 0ce826b commit ccc29bf

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/core/singletons/error-logs.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,38 @@ export class CoreErrorLogs {
3939
* @param error Error.
4040
*/
4141
static addErrorLog(error: CoreSettingsErrorLog): void {
42-
CoreErrorLogs.errorLogs.push(error);
42+
CoreErrorLogs.errorLogs.push({
43+
...error,
44+
data: CoreErrorLogs.sanitizeData(error.data),
45+
});
46+
}
47+
48+
/**
49+
* Sanitize error data by replacing possible tokens with masked values.
50+
*
51+
* @param data Data to sanitize.
52+
* @returns Sanitized data.
53+
*/
54+
protected static sanitizeData(data: unknown): unknown {
55+
if (typeof data === 'string') {
56+
// Hide anything that looks like a possible token.
57+
return data.replace(/\b[a-zA-Z0-9]{32,}/g, (match) => `...${match.slice(-3)}`);
58+
}
59+
60+
if (typeof data !== 'object' || data === null) {
61+
return data;
62+
}
63+
64+
if (Array.isArray(data)) {
65+
return data.map(item => CoreErrorLogs.sanitizeData(item));
66+
}
67+
68+
const sanitized: Record<string, unknown> = {};
69+
for (const [key, value] of Object.entries(data)) {
70+
sanitized[key] = CoreErrorLogs.sanitizeData(value);
71+
}
72+
73+
return sanitized;
4374
}
4475

4576
}

0 commit comments

Comments
 (0)