Skip to content

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

Merged
pboling merged 2 commits into
ruby-oauth:mainfrom
makssein:debug-log-hash-request-body
Oct 25, 2026
Merged

pboling merged 2 commits into
ruby-oauth:mainfrom
makssein:debug-log-hash-request-body

Conversation

@makssein

@makssein makssein commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

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.
@pboling

pboling commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

@makssein This is pretty good. I'm releasing a new auth-sanitizer that will have a tool we can use to fix this.

Auth::Sanitizer.sanitize(value, filtered_keys:, label:)

ruby-oauth/auth-sanitizer#27

Also - I have the CI issues resolved separately. I'll have that into main shortly as well

@pboling

pboling commented Oct 25, 2026

Copy link
Copy Markdown
Member

Since this PR is just specs I'll merge it now.

@pboling
pboling merged commit 5113e79 into ruby-oauth:main Oct 25, 2026
3 of 39 checks passed
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.

2 participants