Skip to content

Debug log leaks secrets from the Hash request body of #get_token - #769

Open
makssein wants to merge 2 commits into
ruby-oauth:mainfrom
makssein:debug-log-hash-request-body
Open

makssein wants to merge 2 commits into
ruby-oauth:mainfrom
makssein:debug-log-hash-request-body

Conversation

@makssein

@makssein makssein commented Oct 12, 2026 •

Copy link
Copy Markdown

With OAUTH_DEBUG=true, secrets from the request body of #get_token and AccessToken#refresh! end up in the debug log: client_secret (with auth_scheme: :request_body), code_verifier, and refresh_token. These specs reproduce it through the real client calls and currently fail.

This happens because #get_token passes the params to Faraday as a Hash, and the debug logger is added before :url_encoded. So Faraday logs the body via #pretty_inspect, like {"client_secret" => "..."}. SanitizedLogger only redacts the Authorization header, JSON pairs, and key=value pairs, so this format slips through. The existing form-encoded spec doesn't catch it because it passes an already-encoded string to client.request.

This could be fixed by making SanitizedLogger also redact Ruby Hash #inspect output ("key" => "value", key: "value", :key=>"value"). That way it works regardless of the middleware order or a custom connection_build. On top of that, the default connection could add the logger after :url_encoded, so the log shows the real encoded body.

#get_token passes the params to Faraday as a Hash. The debug logger is added before :url_encoded, so it prints the request body with #pretty_inspect, and the sanitized logger, which only redacts JSON and form-encoded pairs, leaves the client secret, the code verifier and the refresh token in the output.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant