I opened an issue here (ActionDispatch::Http::Parameters reveals sensitive information in exception messages and logs on parse error · Issue #41145 · rails/rails · GitHub) because we’re noticing that requests containing malformed JSON could potentially log sensitive information. One solution that came to mind is to introduce a flag like this…
Rails.application.configure do
#
# Defaults to false in test and development.
# Defaults to true in any other environment.
#
config.action_dispatch.conceal_request_body_on_parse_errors = true
end
This would prevent log messages (even at the debug level) from containing information like this…
Error occurred while parsing request parameters.
Contents:
{"user":{"ssn":"secret!"}
…and ActionDispatch::Http::Parameters::ParseError
messages from containing this (which could be logged in a piece of catch-all middleware)…
783: unexpected token at '{"user":{"ssn":"secret!"}'
I’m not familiar enough with Rails to know if that’s the best solution to the problem, but it felt like a new feature that could benefit from some feedback. Thanks!