Skip to content

URL-encode API keys to prevent query string injection#7

Merged
erinlkolp merged 2 commits intomainfrom
claude/review-dial-api-module-eP5F3
Mar 1, 2026
Merged

URL-encode API keys to prevent query string injection#7
erinlkolp merged 2 commits intomainfrom
claude/review-dial-api-module-eP5F3

Conversation

@erinlkolp
Copy link
Copy Markdown
Owner

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

  • VUUtil.get_uri(): Added URL encoding to the api_key parameter using quote() to prevent special characters from being interpreted as query string delimiters
  • VUAdminUtil.get_uri(): Applied the same URL encoding fix to the admin_key parameter
  • Tests: Added comprehensive test cases to verify that API keys with special characters (& and =) are properly URL-encoded and cannot inject additional query parameters

Implementation Details

The fix uses Python's quote() function (from urllib.parse) to URL-encode API keys before inserting them into the URI. This ensures that characters like & become %26 and = 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

claude added 2 commits March 1, 2026 20:03
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
@erinlkolp erinlkolp merged commit ff624bc into main Mar 1, 2026
8 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