mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-09-14 04:22:04 +09:00
ef147d17db
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.
17 lines
565 B
Ruby
17 lines
565 B
Ruby
# 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
|