Cookie and URL boundary lab · Updated November 12, 2026
Encode a Cookie Value for a URL Safely
A cookie value and a URL query value are different grammars: encode the value for the destination context instead of copying a URL encoder result into a Set-Cookie header. This tool shows the URL component result beside a conservative cookie-value check.
Measured boundary cases
| Input | URL component | Cookie warning |
|---|---|---|
a&b=c | a%26b%3Dc | Raw ampersand and equals are delimiters in other contexts. |
session 50% | session%2050%25 | Space and percent need an explicit cookie policy. |
next;mode | next%3Bmode | Semicolon is not a safe delimiter to pass through blindly. |
Node and PHP output
Run date: November 12, 2026. Node.js v24.19.0 encodeURIComponent and PHP 8.5.12 rawurlencode both encode the same fixture as data; cookie serialization still needs a cookie-aware API and policy.
Fixture a&b=c; session 50% → Node.js v24.19.0: a%26b%3Dc%3B%20session%2050%25 → PHP 8.5.12: a%26b%3Dc%3B%20session%2050%25
Do not confuse transport layers
Encoding a cookie value does not make it secret and does not validate a session. Do not put credentials in a URL; for query parameters, use the query parameter parser. For ordinary component encoding, use the URL Encode tool.
FAQ
Can I decode a cookie with decodeURIComponent?
Only if the producer used URL component encoding. Cookie libraries may apply a different decoding policy, so test the actual framework.
Does encoding fix security?
No. It prevents delimiter collisions; authentication, signing, expiry, and transport security remain separate controls.