(obj: any)
| 99 | } |
| 100 | |
| 101 | export function redactApiKeys(obj: any): any { |
| 102 | if (obj === null || obj === undefined) { |
| 103 | return obj |
| 104 | } |
| 105 | |
| 106 | if (typeof obj !== 'object') { |
| 107 | return obj |
| 108 | } |
| 109 | |
| 110 | if (Array.isArray(obj)) { |
| 111 | return obj.map((item) => redactApiKeys(item)) |
| 112 | } |
| 113 | |
| 114 | if (isUserFile(obj)) { |
| 115 | const filtered = filterUserFileForDisplay(obj) |
| 116 | const result: Record<string, any> = {} |
| 117 | for (const [key, value] of Object.entries(filtered)) { |
| 118 | if (isLargeDataKey(key) && typeof value === 'string') { |
| 119 | result[key] = TRUNCATED_MARKER |
| 120 | } else { |
| 121 | result[key] = value |
| 122 | } |
| 123 | } |
| 124 | return result |
| 125 | } |
| 126 | |
| 127 | const result: Record<string, any> = {} |
| 128 | |
| 129 | for (const [key, value] of Object.entries(obj)) { |
| 130 | if (isSensitiveKey(key)) { |
| 131 | result[key] = REDACTED_MARKER |
| 132 | } else if (isLargeDataKey(key) && typeof value === 'string') { |
| 133 | result[key] = TRUNCATED_MARKER |
| 134 | } else if (typeof value === 'object' && value !== null) { |
| 135 | result[key] = redactApiKeys(value) |
| 136 | } else { |
| 137 | result[key] = value |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | return result |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Sanitizes a string for safe logging by truncating and redacting sensitive patterns |
no test coverage detected