URL-encode API keys to prevent query string injection#7
Merged
Conversation
Both VUUtil.get_uri() and VUAdminUtil.get_uri() were interpolating the api_key/admin_key directly into the URL without URL-encoding. A key containing & or = could inject extra query parameters, e.g. key="x&admin_key=evil" would silently append a second parameter. Wrap the key with quote() (already imported) in both methods. Add two new regression tests that verify a key with & and = is percent-encoded and does not produce extra query parameters. https://claude.ai/code/session_01QsyBUkQCyboH9i46sS1gtL
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
This PR fixes a security vulnerability where API keys containing special characters (like
&and=) could break the query string structure or inject unintended parameters.Changes
api_keyparameter usingquote()to prevent special characters from being interpreted as query string delimitersadmin_keyparameter&and=) are properly URL-encoded and cannot inject additional query parametersImplementation Details
The fix uses Python's
quote()function (fromurllib.parse) to URL-encode API keys before inserting them into the URI. This ensures that characters like&become%26and=becomes%3D, preventing them from being misinterpreted as query string syntax. The encoding is applied at the point where the key is inserted into the URI string, maintaining backward compatibility while securing against injection attacks.https://claude.ai/code/session_01QsyBUkQCyboH9i46sS1gtL