On this page
An encoded slash in a URL path can change which route handles a request when a proxy, server, or framework decodes it at a different stage. For example, /lab/a%2Fb may be treated as two path segments, with a/b as one segment value, or as three segments: lab, a, and b. Some servers reject the request instead.
This guide shows how to reproduce the distinction locally and trace it through a controlled proxy-to-application deployment.
Key Takeaways
- A literal
/separates path segments.%2Fis an encoded slash that may be data within a segment until a component decodes it. - Splitting the path before decoding and decoding before splitting can produce different route structures.
- A proxy, web server, framework, and application may each reject, preserve, or decode the encoded slash.
- Routing and authorization must agree on the resource being requested. A successful response alone does not prove that every layer interpreted the path identically.
How decoding changes the path
Consider the request target /lab/a%2Fb:
| Interpretation | Resulting segments |
|---|---|
| Split on literal slashes, then decode each segment | lab, a/b |
| Decode the whole path, then split on slashes | lab, a, b |
In the first interpretation, the decoded slash is part of the second segment's value. In the second, it becomes a separator before routing. %2f is another spelling of the encoded slash; hexadecimal letters in percent encodings are case-insensitive.
The two interpretations are not interchangeable for routing or access control. For example, a route that accepts one identifier after /lab/ might accept a/b under the first interpretation but see an extra path segment under the second. Actual behavior depends on the deployed components and configuration.
Advertisement
Reproduce the two interpretations locally
The following diagnostic server uses Node.js and its built-in HTTP module. It does not reproduce a particular framework's router; it shows the consequences of the two decoding orders. Run it only on your own machine. The example has not been executed for this article.
Save this as slash-lab.js:
const http = require('node:http');
const server = http.createServer((req, res) => {
if (req.method !== 'GET') {
res.writeHead(405, { Allow: 'GET' });
res.end('Method not allowed\n');
return;
}
// Remove the query string before interpreting path segments.
const target = req.url || '';
const questionMark = target.indexOf('?');
const rawPath = questionMark === -1 ? target : target.slice(0, questionMark);
if (!rawPath.startsWith('/lab/')) {
res.writeHead(404);
res.end('Not found\n');
return;
}
try {
const splitThenDecode = rawPath.split('/').slice(1).map(decodeURIComponent);
const decodeThenSplit = decodeURIComponent(rawPath).split('/').slice(1);
res.writeHead(200, { 'Content-Type': 'application/json; charset=utf-8' });
res.end(JSON.stringify({ rawPath, splitThenDecode, decodeThenSplit }, null, 2) + '\n');
} catch {
res.writeHead(400);
res.end('Invalid path encoding\n');
}
});
server.listen(8787, '127.0.0.1', () => {
console.log('Lab listening on http://127.0.0.1:8787');
});
Start it with node slash-lab.js. In a second terminal, send a request using curl:
curl --path-as-is -i 'http://127.0.0.1:8787/lab/a%2Fb'
The response body should show these values:
{
"rawPath": "/lab/a%2Fb",
"splitThenDecode": ["lab", "a/b"],
"decodeThenSplit": ["lab", "a", "b"]
}
Compare that with a literal slash:
curl --path-as-is -i 'http://127.0.0.1:8787/lab/a/b'
Both interpretations should now produce lab, a, and b as separate segments. Try %2f as well, then stop the server with Ctrl+C. The --path-as-is option helps prevent curl from normalizing path sequences, but it cannot prevent an intermediary from changing or rejecting a request.
Check the proxy, server, and framework
Use a staging deployment or isolated lab that you own or are explicitly authorized to test. Configure a harmless diagnostic route and avoid real identifiers, credentials, or sensitive data in test URLs and logs.
- Send the same test requests directly to the controlled application and through its proxy. Include
/lab/a/b,/lab/a%2Fb,/lab/a%2fb, and/lab/a%252Fb. - Record the response status and which harmless handler ran. A rejection may occur before the application receives the request; check proxy and server error logs if the application logs nothing.
- At each boundary, compare the incoming request target, the path forwarded upstream, the framework's route match, and any decoded route parameters. Use that component's documented logging fields: a field named “URI” or “path” is not necessarily the original request target.
- Check whether authentication and authorization run against the same effective route and identifier that the application uses. Repeat with a test identity that is allowed and one that is denied.
- Test the configuration you intend to deploy, including relevant rewrites, caches, and access-control rules. Remove or restrict diagnostic routes and logs afterward.
%252F is useful for detecting inconsistent multiple decoding: one decoding pass produces %2F, and a further pass can produce /. Whether that slash then becomes a separator depends on what happens next. Do not assume that all layers decode exactly once.
For Apache HTTP Server, the AllowEncodedSlashes directive is an important setting to investigate: its options can reject encoded separators, permit decoding, or permit them without decoding. For NGINX, inspect proxy_pass and rewrite configuration; whether a URI is specified in proxy_pass affects how the upstream request URI is formed. Framework route matching and parameter decoding add another layer, so consult the documentation for the exact deployed versions and configuration.
Documentation could not be retrieved for this article. Verify these settings and the applicable framework behavior against your versions' official documentation before changing a deployment; the lab above illustrates decoding order rather than verifying any server's defaults.
Advertisement
Common Mistakes
- Testing only the application directly. A proxy or server may reject or transform the request before the framework sees it.
- Treating decoded parameter values as the original path. Once decoding has occurred, a value containing
/does not reveal whether the client sent a literal or encoded slash. - Fixing a 404 by blindly allowing encoded slashes. This can create a mismatch between the component enforcing a rule and the component selecting the resource.
- Ignoring double encoding. A second decoding step can change the meaning of input that appeared harmless after the first.
- Comparing status codes alone. Two requests can both return
200while reaching different handlers or resource identifiers.
Best Practices
Define whether encoded separators are accepted for each route and reject ambiguous requests when they are not needed. Align proxy, server, router, and authorization behavior with that policy; avoid redundant decoding and test the actual end-to-end configuration.
If identifiers legitimately contain slashes, choose an explicit representation and verify how every layer handles it. Include negative authorization tests and regression tests for encoded, literal, and double-encoded forms. Also review other normalization rules relevant to your stack, such as backslashes and dot segments, rather than assuming slash handling is the only source of discrepancies.
Conclusion
An encoded slash changes routing when components disagree about when it becomes a path separator. Compare the request at each boundary in an authorized lab, then make routing and access-control decisions consistent across the deployed stack.
What would your domain sell for?
A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.