MCPcopy Index your code
hub / github.com/simstudioai/sim / redactApiKeys

Function redactApiKeys

apps/sim/lib/core/security/redaction.ts:101–142  ·  view source on GitHub ↗
(obj: any)

Source from the content-addressed store, hash-verified

99}
100
101export 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

Callers 5

store.tsFile · 0.90
redaction.test.tsFile · 0.90
buildBlockExecutionsFunction · 0.90
sanitizeInputsForLogMethod · 0.90

Calls 4

isUserFileFunction · 0.90
filterUserFileForDisplayFunction · 0.90
isLargeDataKeyFunction · 0.85
isSensitiveKeyFunction · 0.85

Tested by

no test coverage detected