MCPcopy Index your code
hub / github.com/PaystackOSS/paystack-mcp-server / redactSensitiveData

Function redactSensitiveData

src/logger.ts:56–90  ·  view source on GitHub ↗
(obj: any)

Source from the content-addressed store, hash-verified

54}
55
56function redactSensitiveData(obj: any): any {
57 if (obj === null || obj === undefined) {
58 return obj;
59 }
60
61 if (typeof obj === 'string') {
62 // Redact bearer tokens and API keys in strings
63 return obj
64 .replace(/Bearer\s+\w+/gi, 'Bearer [REDACTED]')
65 .replace(/sk_test_\w+/g, '[REDACTED_SECRET_KEY]');
66 }
67
68 if (Array.isArray(obj)) {
69 return obj.map(redactSensitiveData);
70 }
71
72 if (typeof obj === 'object') {
73 const redacted: any = {};
74 for (const [key, value] of Object.entries(obj)) {
75 // Special handling for card objects - only redact cvv and number
76 if (key.toLowerCase() === 'card' && typeof value === 'object' && value !== null) {
77 redacted[key] = redactCardObject(value);
78 }
79 // Check if key matches sensitive patterns
80 else if (SENSITIVE_PATTERNS.some((pattern) => pattern.test(key))) {
81 redacted[key] = '[REDACTED]';
82 } else {
83 redacted[key] = redactSensitiveData(value);
84 }
85 }
86 return redacted;
87 }
88
89 return obj;
90}
91
92class Logger {
93 private currentLogLevel: LogLevel;

Callers 2

redactCardObjectFunction · 0.85
formatLogMethod · 0.85

Calls 1

redactCardObjectFunction · 0.85

Tested by

no test coverage detected