On this page
An encoded URL path authorization bypass can occur when an access check and a router interpret the same request path differently. A proxy might check one representation, while an application decodes or normalizes it again and routes it to a protected resource.
This guide uses an intentionally vulnerable local simulation to make that mismatch visible, then outlines how to investigate and prevent it in a real deployment. Run tests only against systems you own or are explicitly authorized to test.
Key Takeaways
- A path check is unsafe if a later layer can transform the path into a different protected route.
- Percent-encoded separators, dot segments, and double-encoded characters deserve explicit tests across the entire request chain.
- Make the application authorize the matched route and resource, not just a raw path string checked upstream.
- Actual decoding behavior is implementation- and configuration-specific. The local example below is a simulation, not a claim about a particular proxy or framework.
Where path interpretations diverge
A request can pass through a proxy, web server, framework router, and authorization layer. Each may receive a different representation of the path. For example, one layer could decode %2F into /, while another removes .. segments. A check made before those transformations may not apply to the resource eventually selected.
Double encoding adds another opportunity for disagreement: %252F becomes %2F after one percent-decoding pass and / after another. Whether either pass actually occurs depends on the components and configuration in use.
The critical question is not merely “Does a component decode the path?” It is: Does the authorization decision apply to the same route and resource the application ultimately serves?
Advertisement
Run a controlled local simulation
The following Python standard-library example starts two HTTP servers bound to loopback. The first simulates a proxy that decodes once and checks for /private. The second simulates an application that decodes again, normalizes dot segments, and routes the result. The proxy forwards its decoded representation to the application; this is a deliberate choice for the demonstration, not a statement about real proxy defaults.
The example is intentionally insecure and returns only a fictional message. It has not been executed in this editorial environment. Save it as path_lab.py and run it with python3 path_lab.py on a machine where the two local ports are available. Stop it with Ctrl+C if necessary.
from http.client import HTTPConnection, HTTPException
from http.server import BaseHTTPRequestHandler, HTTPServer
from posixpath import normpath
from threading import Thread
from urllib.parse import unquote
HOST = "127.0.0.1"
PROXY_PORT = 18761
APP_PORT = 18762
def reply(handler, status, text):
body = text.encode("utf-8")
handler.send_response(status)
handler.send_header("Content-Type", "text/plain; charset=utf-8")
handler.send_header("Content-Length", str(len(body)))
handler.end_headers()
handler.wfile.write(body)
class QuietHandler(BaseHTTPRequestHandler):
def log_message(self, format, *args):
pass
class App(QuietHandler):
def do_GET(self):
received = self.path
decoded = unquote(received)
route = normpath(decoded)
print(f" app: received={received!r}, decoded={decoded!r}, route={route!r}", flush=True)
# Deliberately no application authorization: this is the flaw being demonstrated.
if route == "/private":
reply(self, 200, "fictional protected route")
else:
reply(self, 404, "no route")
class Proxy(QuietHandler):
def do_GET(self):
received = self.path
checked = unquote(received)
print(f" proxy: received={received!r}, checked={checked!r}", flush=True)
if checked == "/private" or checked.startswith("/private/"):
reply(self, 403, "blocked by simulated proxy")
return
connection = HTTPConnection(HOST, APP_PORT, timeout=3)
try:
connection.request("GET", checked)
response = connection.getresponse()
body = response.read()
self.send_response(response.status)
self.send_header("Content-Type", "text/plain; charset=utf-8")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
except (OSError, HTTPException):
self.send_error(502, "simulated upstream failure")
finally:
connection.close()
def main():
servers = []
try:
servers.append(HTTPServer((HOST, APP_PORT), App))
servers.append(HTTPServer((HOST, PROXY_PORT), Proxy))
for server in servers:
Thread(target=server.serve_forever, daemon=True).start()
targets = [
"/private",
"/public%2F..%2Fprivate",
"/public%252F..%252Fprivate",
"/%2570rivate",
]
for target in targets:
print(f"request: {target}", flush=True)
connection = HTTPConnection(HOST, PROXY_PORT, timeout=3)
try:
connection.request("GET", target)
response = connection.getresponse()
body = response.read().decode("utf-8")
print(f" response: {response.status} {body}", flush=True)
finally:
connection.close()
finally:
for server in servers:
server.shutdown()
server.server_close()
if __name__ == "__main__":
main()
The direct /private request is intended to be blocked at the simulated proxy. For the encoded examples, compare the proxy's checked value with the application's final route. In particular, the double-encoded slash becomes an encoded slash at the proxy and a separator at the application. The double-encoded p in /%2570rivate illustrates the same mismatch without a separator.
These are expected behaviors derived from the example's code, not observed test results. The lab deliberately leaves authorization out of the application so that a mismatch has a visible consequence; it is not a template for production code.
Advertisement
Investigate a real request chain
Use a controlled staging environment and a test account with known permissions. Do not expose sensitive data for the experiment. Record the component versions, configuration, route, HTTP method, and identity used for each case.
- Identify the boundaries. List the client-facing proxy, any additional gateways or web servers, the application router, and the component making the authorization decision.
- Capture representations safely. Where supported, log the received request target and the path representation used for access checks and routing. Add a correlation identifier so observations across layers can be matched. Avoid logging credentials, sensitive query strings, or private path data.
- Compare decisions. For each input, record whether the proxy accepted it, which route and resource the application selected, and whether authorization allowed access. A rejected request is a valid and often preferable outcome for ambiguous input.
- Check the deployed documentation and configuration. Consult the current documentation for each actual component, including its settings for encoded separators, decoding, normalization, and forwarding. This article could not consult current proxy or framework documentation, so it does not assert their exact behavior or defaults. Confirm behavior in your own authorized environment.
- Add regression tests. Run the same cases through the complete deployed chain, not only against a router unit test. Include an unauthorized identity and an authorized one so the tests distinguish routing failures from authorization failures.
Use a client that can send the intended request target without first rewriting it; verify what the first server actually receives. Otherwise, a client-side normalization can make a test misleading.
Inputs to compare
For a fictional protected route /private, consider these alongside the ordinary path. Their outcomes are deployment-specific; the purpose is to find inconsistencies, not to assume a bypass.
| Test input or category | Question to answer |
|---|---|
/private | Does an unauthorized identity receive a denial? |
/public%2F..%2Fprivate | Are encoded separators decoded before or after the access check, and are dot segments normalized? |
/public%252F..%252Fprivate | Does another layer decode the path a second time? |
/%2570rivate | Can repeated decoding change a path segment into a protected route name? |
Lowercase encodings such as %2f | Are equivalent encodings handled consistently? |
| Repeated slashes, backslashes, malformed escapes, or encoded non-ASCII characters | Does any layer reject, reinterpret, or normalize them differently? |
Also test trailing slashes, route parameters, and relevant HTTP methods. Keep query-string tests separate from path tests unless the application's access rules intentionally depend on query parameters.
Common Mistakes
- Checking only a prefix of the raw path. A later decode or normalization can change which route is selected. Prefix checks can also confuse distinct route names.
- Decoding repeatedly until a path stops changing. This can introduce new separators or dot segments and make behavior harder to reason about. Define the accepted representation and decoding boundary instead.
- Assuming every layer sees the same path. Forwarding rules and server APIs can expose different representations; capture the values used for the actual decisions.
- Testing only the proxy or only the application. A mismatch occurs between layers, so an isolated test may miss it.
- Treating the lab's behavior as a framework default. Its decoding and forwarding rules were chosen to demonstrate a failure mode.
Best Practices
- Authorize the matched route and resource in the application. Apply authorization after routing has identified what is being accessed and before the handler performs the protected action. Preserve any earlier proxy checks as defense in depth, not as the sole control.
- Define a consistent path policy. Specify which representations are accepted, where decoding and normalization occur, and what is forwarded. Reject ambiguous or malformed paths when the deployment cannot interpret them consistently. Avoid a design in which a downstream layer can reinterpret an already-authorized path.
- Test the policy end to end. Cover encoded and double-encoded inputs, normal requests, denied identities, and permitted identities. Assert both the selected resource and the authorization result.
- Review changes at boundaries. Proxy upgrades, configuration changes, new routing rules, and middleware changes can alter the interpretation on which access checks depend. Re-run the regression suite after such changes.
Conclusion
An encoded path is dangerous when the access check and the final route refer to different interpretations of the same request. Trace the path through every layer, reject ambiguous forms where appropriate, and authorize the resource the application actually selects.
What would your domain sell for?
A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.