File tree Expand file tree Collapse file tree 1 file changed +32
-1
lines changed
Expand file tree Collapse file tree 1 file changed +32
-1
lines changed Original file line number Diff line number Diff 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 - z A - Z 0 - 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}
You can’t perform that action at this time.
0 commit comments