You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: apply custom_headers to API client requests - #131
Flagsmith::ApiClient#build_headers ended with faraday.headers.merge(config.custom_headers). Faraday::Utils::Headers#merge returns a new object and does not modify the receiver, so the result was discarded and custom_headers (for example Authorization or a proxy token) never reached the API requests.
The fix uses merge!. Because the headers are now really sent, two related points are handled too:
X-Environment-Key is set after the merge, so custom_headers cannot replace the configured environment key. This is the same precedence the events API already uses.
The Faraday response logger writes request headers by default, so the values of custom_headers are shown as [REDACTED] in the log. They are still sent unchanged.
Test
Specs in spec/sdk/api_client_spec.rb check that custom headers are applied, that a custom x-environment-key does not override the configured key, and that a request sends the custom values while the log does not contain them.
This change was prepared with the assistance of an AI coding agent.
ApiClient#build_headers now uses merge! to add configured custom headers to Faraday’s headers. A spec checks that the configured Authorization and X-Proxy-Token headers are present alongside the default X-Environment-Key.
The change makes configured custom headers reach API requests, as intended. With the default logger, those headers, including credentials, will now also appear in stdout logs. A conflicting environment-key header can also make flag and event requests use different environments. Address the logging exposure before merging, and decide on a single precedence rule for the environment key.
- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: ASSERTIVE
Plan: Advanced
Run ID: dad15c26-d523-4101-9939-daf0e8f21b00
Commits
Reviewing files that changed from the base of the PR and between 9a53b08 and f0033bd.
Files selected for processing: 2
lib/flagsmith/sdk/api_client.rb
spec/sdk/api_client_spec.rb
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Major · Security & Privacy · Quick win
Keep custom credentials out of request logs.
With the default logger, a request now logs the configured Authorization and X-Proxy-Token values to stdout. Faraday 2.0.1 logs request headers at info level by default, and this client installs that logger without filters. Disable request-header logging or redact sensitive values while still sending them in requests. (raw.githubusercontent.com)
Minor · Data Integrity & Integration · Quick win
Apply one precedence rule to X-Environment-Key in both clients.
ApiClient#build_headers sets X-Environment-Key to config.environment_key, then merge!(config.custom_headers) replaces it with any custom value. EventProcessor#headers gives the environment key precedence over custom headers. If custom_headers sets a different X-Environment-Key, flag requests and event requests can target different environments, and events can be attributed to the wrong environment.
Choose one rule for conflicting X-Environment-Key values, and apply it in both lib/flagsmith/sdk/api_client.rb and lib/flagsmith/sdk/event_processor.rb. The current code uses opposite precedence in each client.
Both points are addressed in the latest commit: the configured environment key is now set after custom_headers, and custom header values are redacted in the request log.
Friendly ping in case this slipped through the cracks. Happy to make any changes if needed, thanks!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Flagsmith::ApiClient#build_headersended withfaraday.headers.merge(config.custom_headers).Faraday::Utils::Headers#mergereturns a new object and does not modify the receiver, so the result was discarded andcustom_headers(for exampleAuthorizationor a proxy token) never reached the API requests.The fix uses
merge!. Because the headers are now really sent, two related points are handled too:X-Environment-Keyis set after the merge, socustom_headerscannot replace the configured environment key. This is the same precedence the events API already uses.custom_headersare shown as[REDACTED]in the log. They are still sent unchanged.Test
Specs in
spec/sdk/api_client_spec.rbcheck that custom headers are applied, that a customx-environment-keydoes not override the configured key, and that a request sends the custom values while the log does not contain them.This change was prepared with the assistance of an AI coding agent.