Skip to content

Percent-encode credentials in Hyperdrive connectionString#6820

Open
tahmid-23 wants to merge 1 commit into
cloudflare:mainfrom
tahmid-23:hyperdrive-connection-string-encode
Open

Percent-encode credentials in Hyperdrive connectionString#6820
tahmid-23 wants to merge 1 commit into
cloudflare:mainfrom
tahmid-23:hyperdrive-connection-string-encode

Conversation

@tahmid-23

Copy link
Copy Markdown

Previously, Hyperdrive::getConnectionString would 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...)

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>
@tahmid-23 tahmid-23 requested review from a team as code owners June 16, 2026 13:48
@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@tahmid-23

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Jun 16, 2026
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.

1 participant