mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-09-16 13:32:05 +09:00
Redact bot key from request logs (#269)
The bot HTTP API carries the bot key as a URL path segment (/rooms/:room_id/:bot_key/...). config.filter_parameters redacts query and form parameters but never path segments, so the key was written verbatim to the request log (the "Started POST ..." line) and to any log line echoing the pagination Link header. Add a log formatter that redacts the bot-key path segment wherever it appears in a formatted line, and wire it into the production logger.
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
# Bot requests carry the bot key as a URL path segment (/rooms/:room_id/:bot_key/...).
|
||||
# config.filter_parameters redacts query and form parameters but never path segments,
|
||||
# so the key would otherwise be written verbatim to the request log. Redact it wherever
|
||||
# it appears in a formatted log line.
|
||||
class LogScrubbingFormatter < ::Logger::Formatter
|
||||
BOT_KEY_IN_PATH = %r{(/rooms/\d+/)\d+-[A-Za-z0-9]+}
|
||||
|
||||
def call(severity, time, progname, message)
|
||||
scrub(super)
|
||||
end
|
||||
|
||||
private
|
||||
def scrub(line)
|
||||
line.gsub(BOT_KEY_IN_PATH, '\1[FILTERED]')
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user