Skip to content

fix(security): redact caller query params and escape control chars in logs [SEC-2535] - #135

Merged
oliverlaz merged 4 commits into
masterfrom
oliverlazoroski/sec-2535-sec-21-logging-redactioncrlf-ruby
Nov 27, 2026
Merged

oliverlaz merged 4 commits into
masterfrom
oliverlazoroski/sec-2535-sec-21-logging-redactioncrlf-ruby

Conversation

@oliverlaz

Copy link
Copy Markdown
Member

Fixes the Ruby part of SEC-2535 (audit finding SEC-21, severity Low).

Problem

  • make_request baked caller query params into the path string, so http.request.sent logged them inside url.path, where LogRedaction.redact_query never ran. Only the SDK's own api_key (in url.query) was redacted.
  • Logged values (path, query values, error messages, response bodies with log_bodies) were interpolated verbatim, so a value containing CR/LF could forge extra log lines (log injection). Path params are interpolated unencoded by the generated clients, and the http.request.sent line is emitted before Faraday rejects such a URL.

Fix

  • make_request keeps query params as a Hash (values serialized but not URL-encoded) and hands them to request, which merges in api_key (the SDK's key still wins) and passes them to Faraday, which encodes them. Wire format is unchanged: Faraday already re-parsed and re-encoded the old path query string. Logging now sees the merged hash, so redact_query covers caller params (token, api_key, api_secret).
  • New LogRedaction.sanitize escapes every control character (C0, DEL, C1, U+2028/2029) to its escaped form (\r, \n, \e, ...) and scrubs invalid UTF-8. Every request log line (sent / received / failed / retry) and the pool fallback warning go through it.
  • url.path also goes through redact_message, so a caller-built path like post('/x?token=...') is scrubbed too.
  • The Authorization header and the JWT were never logged; a spec now pins that.

Tests

make test (341 examples, 0 failures) and make lint (rubocop: no offenses) pass locally on Ruby 4.0. New specs in spec/logging_spec.rb cover caller-param redaction, a caller-built path, no Authorization/JWT in logs, CR/LF in path/query/body/error message, and the sanitize helper. The CR/LF specs fail when sanitize is stubbed out.

@oliverlaz
oliverlaz requested review from itsmeadi and mogita November 25, 2026 11:37
@oliverlaz
oliverlaz marked this pull request as ready for review November 25, 2026 12:39
@oliverlaz
oliverlaz enabled auto-merge (squash) November 27, 2026 15:23
@oliverlaz
oliverlaz merged commit acd7eb6 into master Nov 27, 2026
7 checks passed
@oliverlaz
oliverlaz deleted the oliverlazoroski/sec-2535-sec-21-logging-redactioncrlf-ruby branch November 27, 2026 15:24
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