Files
once-campfire/lib/rails_ext/log_scrubbing_formatter.rb
T
Jeremy Daer ef147d17db 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.
2026-09-01 12:40:55 -07:00

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