

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 10
click for more info
Not enough gems
Cost: 6 gems
1: Can You Keep a Secret?
incomplete
2: Error Responses
incomplete
3: Minimal Logging
incomplete
4: Obfuscation
incomplete
5: Filtering Logs
incomplete
6: Encrypted Logs
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Best practice is to prevent logging sensitive data at the source, but that discipline is hard to maintain, especially in a large codebase with many developers. So it's smart to add some filtering at the logger level during initialization.
var sensitiveKeys = []string{"password", "key", "apikey", "secret", "pin", "creditcardno"}
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{
// Replace any potentially sensitive values with the string [REDACTED]
ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr {
if slices.Contains(sensitiveKeys, a.Key) {
return slog.String(a.Key, "[REDACTED]")
}
return a
},
}))
It's virtually impossible to make this approach 100% thorough. So while it helps as a safety net, treat it as a last resort. Use it, but don't rely on it. The real fix is still to avoid logging sensitive data at the source during implementation and review.
Add a last-resort security filter to the logger.
Obviously, you should never ACTUALLY add a password to a log file, even if you know it's being redacted. This is for educational purposes only! No kittens were harmed in the making of this assignment.
Restart your server with LINKO_LOG_FILE=linko.access.log set:
LINKO_LOG_FILE=linko.access.log go run .
After making those requests, check linko.access.log:
user should be [REDACTED]Run and submit the CLI tests from the root of the Linko repo.