URL userinfo boundary lab · Updated November 16, 2026
Encode Basic Auth Credentials in a URL Safely
Encode reserved characters inside the username or password, but do not treat URL userinfo as a secure storage mechanism. An unescaped @ can terminate credentials early and change which host the parser sees.
Three userinfo boundaries
| Input | Safe component | Observed boundary |
|---|---|---|
alice | alice | Plain username needs no escaping. |
pa@ss word | pa%40ss%20word | The data at-sign is not the host separator. |
https://user:[email protected] | Host remains separate | The final @ separates userinfo from the host. |
Node and PHP measured output
Run date: November 16, 2026. Node.js v24.19.0 and PHP 8.5.12 parse the same encoded fixture; credentials remain userinfo, not a query parameter.
Node.js v24.19.0 → username alice, password pa%40ss%20word, host example.test, port 8443PHP 8.5.12 parse_url → user alice, pass pa%40ss%20word, host example.test, port 8443
Common failure
Do not put real passwords or API keys in shareable URLs. Encoding prevents delimiter collisions; it does not encrypt the credential, and URLs may appear in browser history, logs, referrers, and screenshots.
FAQ
Should I encode the whole URL?
No. Encode the username and password components before building the authority, then leave the host, port, path, and query delimiters structural.
Can the browser send this securely?
Use HTTPS and prefer an authentication mechanism that does not expose secrets in URLs. URL parsing success is not a security approval.
For general components, use the URL Encode tool. For non-encryption guidance, see URL encoding is not encryption.