@@ -334,43 +334,55 @@ export class ApiLogger {
334334 * @param body - Raw body
335335 * @returns Sanitized body
336336 */
337- private sanitizeBody ( body : unknown ) : unknown {
338- if ( ! body ) {
339- return body ;
340- }
337+ private sanitizeBody ( body : unknown ) : unknown {
338+ if ( ! body ) {
339+ return body ;
340+ }
341341
342- // If body is a string, return as-is (already serialized)
343- if ( typeof body === "string" ) {
344- return body ;
345- }
342+ // If body is a string, return as-is (already serialized)
343+ if ( typeof body === "string" ) {
344+ return body ;
345+ }
346346
347- // If body is an object, sanitize sensitive fields
348- if ( typeof body === "object" && body !== null ) {
349- const sanitized : Record < string , unknown > = { } ;
350- const sensitiveFields = [
351- "password" ,
352- "token" ,
353- "secret" ,
354- "api_key" ,
355- "apiKey" ,
356- "private_key" ,
357- "privateKey" ,
358- ] ;
359-
360- for ( const [ key , value ] of Object . entries ( body ) ) {
361- const lowerKey = key . toLowerCase ( ) ;
362- if ( sensitiveFields . some ( ( field ) => lowerKey . includes ( field ) ) ) {
363- sanitized [ key ] = "[REDACTED]" ;
364- } else {
365- sanitized [ key ] = value ;
347+ // If body is a plain object, sanitize sensitive fields
348+ if ( this . isPlainObject ( body ) ) {
349+ const sanitized : Record < string , unknown > = { } ;
350+ const sensitiveFields = [
351+ "password" ,
352+ "token" ,
353+ "secret" ,
354+ "api_key" ,
355+ "apiKey" ,
356+ "private_key" ,
357+ "privateKey" ,
358+ ] ;
359+
360+ for ( const [ key , value ] of Object . entries ( body as Record < string , unknown > ) ) {
361+ const lowerKey = key . toLowerCase ( ) ;
362+ if ( sensitiveFields . some ( ( field ) => lowerKey . includes ( field ) ) ) {
363+ sanitized [ key ] = "[REDACTED]" ;
364+ } else {
365+ sanitized [ key ] = value ;
366+ }
366367 }
368+
369+ return sanitized ;
367370 }
368371
369- return sanitized ;
372+ return body ;
370373 }
371374
372- return body ;
373- }
375+
376+ /**
377+ * Check if value is a plain object
378+ */
379+ private isPlainObject ( value : unknown ) : value is Record < string , unknown > {
380+ if ( Object . prototype . toString . call ( value ) !== "[object Object]" ) {
381+ return false ;
382+ }
383+ const prototype = Object . getPrototypeOf ( value ) ;
384+ return prototype === null || prototype === Object . prototype ;
385+ }
374386
375387 /**
376388 * Create a preview of the body for logging
0 commit comments