Percent-encode credentials in Hyperdrive connectionString#6820
Open
tahmid-23 wants to merge 1 commit into
Open
Percent-encode credentials in Hyperdrive connectionString#6820tahmid-23 wants to merge 1 commit into
tahmid-23 wants to merge 1 commit into
Conversation
Hyperdrive.connectionString is built by splicing the stored (decoded) user/password/database into a URL with no percent-encoding, so a structural character in a component produces an invalid or misparsed connection string. The common trigger is a '/' in a base64-derived password: consumers that parse the string (node-postgres / Prisma via pg-connection-string -> new URL()) throw "Invalid URL string.". The discrete .user/.password/.database getters are unaffected; only .connectionString is malformed. Encode each component with kj::encodeUriComponent, the RFC-3986 component encoder that Postgres and MySQL connection URIs percent-decode against (and the exact inverse of decodeURIComponent, so a literal '%' round-trips too). Adds hyperdrive-connection-string-test covering '/', '?', '#', '@' and '%' in the password plus '/' in the user and '?' in the database. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
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.
Previously,
Hyperdrive::getConnectionStringwould not URI-encode its username, password, and path/database. This would lead to invalid connection strings being returned, if you attempted to consume the hyperdrive's connection string.We fix this by URI-encoding the respective components.
I didn't rebuild workerd to verify that my tests pass (I don't believe my laptop can handle it), but they fail with a prebuilt workerd. I think they will pass in CI.
(This change almost seems too obvious, so let me know if I'm missing something...)