← All Exercises
Redact Secrets Before Logging
intermediatejavascript
Background
Credential leakage happens at the log call site, not in the secret store. A redaction pass applied before logging removes the most common accidental disclosure path.
Problem
Mask API keys, access key ids and key-value credentials in a log line while keeping the surrounding diagnostic text intact.
Input
JSON object: { text: string }Output
JSON string: the line with secret values replaced by [REDACTED]
Sample tests
Sample 1
Input: {"text":"upstream key=sk-live-abcdef1234567890 user=bob status=200"}Expected: "upstream key=[REDACTED] user=bob status=200"
Sample 2
Input: {"text":"aws AKIAIOSFODNN7EXAMPLE token=ghp_abcdefghijklmnopqrstuvwx"}Expected: "aws [REDACTED] token=[REDACTED]"
Your solution
Learning objective
Apply redaction at the logging boundary so secrets never reach log storage.