Escape feature and gate keys in HTTP adapter requests#1009
Open
jnunemaker wants to merge 4 commits into
Open
Conversation
The HTTP adapter interpolated feature/gate keys raw into request paths
and query strings (e.g. "/features/#{feature.key}", "/features?keys=#{csv_keys}").
A key containing /, ?, &, #, a comma, or a space produced a malformed
request or injected/overrode query parameters — and a key with a space
raised URI::InvalidURIError outright.
Escape each key with URI.encode_www_form_component at every interpolation
site (get, get_multi, remove, enable, disable, clear). The API server
already decodes keys with Rack::Utils.unescape, so the round-trip is
preserved. Also fix a spurious leading "&" in Client#uri_for_path when the
base URL has no query string.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
The HTTP adapter interpolated feature and gate keys raw into request paths and query strings (
"/features/#{feature.key}","/features?keys=#{csv_keys}"), so a key containing/,?,&,#, a comma, or a space produced a malformed request or injected/overrode query parameters — and a key with a space raisedURI::InvalidURIErroroutright.This escapes each key with
URI.encode_www_form_componentat every interpolation site (get,get_multi,remove,enable,disable,clear); the API server already decodes keys withRack::Utils.unescape, so the round-trip is preserved. It also fixes a spurious leading&inClient#uri_for_pathwhen the base URL has no query string.Added failing-first specs for
#get(path escaping) and#get_multi(query escaping); the full HTTP adapter suite (108 examples, including the end-to-end WEBrick +Flipper::Apishared adapter specs) passes.