On this page
A semicolon in a URL path can be treated as ordinary path data by one component and as a parameter separator by another. That difference can change which route an application serves, especially when a proxy and an application server process the same request differently.
This guide shows how to compare URL parsing with actual route selection, including encoded semicolons, in a local or otherwise authorized environment.
Key Takeaways
- A semicolon can appear within a path segment; its meaning depends on the components handling the request.
- Parsing a URL into path and query components does not predict which route a server will select.
- Test both literal
;and encoded%3B. Decoding and parameter removal can happen at different layers or in different orders. - Compare the request seen by the proxy, the backend, and the router without logging credentials or sensitive query values.
Start with the path, not an assumed parameter
Consider this fictional URL:
http://127.0.0.1:8080/products;view=compact?sort=name
Its path is /products;view=compact, and its query is sort=name. The question mark separates the query from the path; the semicolon does not make view=compact a query parameter.
A stack may interpret ;view=compact as segment-associated data, remove it before matching a route, retain it as part of the route path, or apply another policy. In some applications, the semicolon is simply ordinary data. A parser can identify the path component, but only the receiving stack can determine how that path is handled.
RFC 3986 and the relevant framework documentation could not be consulted for this article. Check those sources and the documentation for your deployed proxy and framework before relying on stack-specific behavior.
Advertisement
Reproduce semicolon in URL path routing locally
The following small Python lab deliberately implements two different matching rules. It is not a model of a particular framework or proxy. It lets you compare the parsed path with the route selected by each rule.
Save this as semicolon_lab.py and run it with Python 3. It uses only the standard library and listens on the local machine. The example has not been executed for this article.
import json
from http.server import BaseHTTPRequestHandler, HTTPServer
from urllib.parse import unquote, urlsplit
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
parsed = urlsplit(self.path)
parts = parsed.path.split("/", 2)
if len(parts) != 3 or parts[1] not in ("literal", "strip"):
self.send_error(404, "Use /literal/... or /strip/...")
return
mode = parts[1]
decoded_path = "/" + unquote(parts[2])
if mode == "strip":
match_path = "/".join(
segment.split(";", 1)[0] for segment in decoded_path.split("/")
)
else:
match_path = decoded_path
routes = {
"/products": "products route",
"/products;view=compact": "literal semicolon route",
}
route = routes.get(match_path)
body = json.dumps({
"request_target": self.path,
"parsed_path": parsed.path,
"query": parsed.query,
"decoded_path_under_mode": decoded_path,
"path_used_for_matching": match_path,
"selected_route": route,
}, indent=2).encode("utf-8")
self.send_response(200 if route else 404)
self.send_header("Content-Type", "application/json; charset=utf-8")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
server = HTTPServer(("127.0.0.1", 8080), Handler)
try:
server.serve_forever()
except KeyboardInterrupt:
pass
finally:
server.server_close()
Start the server in one terminal:
python3 semicolon_lab.py
In another terminal, send these requests:
curl -i 'http://127.0.0.1:8080/literal/products;view=compact?sort=name'
curl -i 'http://127.0.0.1:8080/strip/products;view=compact?sort=name'
curl -i 'http://127.0.0.1:8080/literal/products%3Bview=compact?sort=name'
curl -i 'http://127.0.0.1:8080/strip/products%3Bview=compact?sort=name'
Compare parsed_path, path_used_for_matching, and selected_route in each response. In this lab, the literal rule retains the decoded semicolon, while the strip rule removes the semicolon and following data from each path segment before matching. The lab decodes %3B before applying either rule, so the encoded and literal semicolons are expected to lead to the same matching behavior within each mode.
That decoding order is a choice made by the lab, not a universal server rule. Other stacks may reject, preserve, decode, or rewrite an encoded semicolon at different stages. Stop the lab with Ctrl+C.
Trace the real request through each layer
Use a local deployment or a system you are explicitly authorized to test. Choose a harmless endpoint and synthetic values, then compare at least these request targets:
/products/products;view=compact/products%3Bview=compact/products;view=compact?sort=name
For each request, record the response status and the route or handler that actually ran. If possible, compare the target sent to the proxy, the target forwarded to the backend, and the path the framework uses for route matching. A direct backend request can help isolate the proxy, provided access is authorized and the direct request uses comparable host, scheme, and application configuration.
Check the deployed versions and configuration for each layer. In particular, look for URL decoding, rewriting, path normalization, segment-parameter handling, and rejected-character policies. A proxy can pass a target through while the framework transforms it, or the proxy can change or reject it before the application sees it.
Use sanitized, temporary diagnostics. Request targets can contain session identifiers, tokens, or personal data, so avoid capturing real secrets and follow your logging policy. Remove debug logging after the investigation.
Advertisement
Common Mistakes
- Treating a parser result as a routing result. A URL parser shows components; it does not reproduce every proxy and framework rule.
- Assuming
;always introduces a parameter. It may be literal path data, and its handling can depend on where it appears. - Testing only the literal character.
%3Bcan take a different path through decoding and filtering. Also test the spelling your client actually sends. - Comparing unlike environments. Host headers, proxy rewrites, configuration, and application versions can all affect the result.
- Fixing only the route mismatch. If authorization, caching, and routing interpret paths differently, a mismatch may have security consequences. Review those layers together without assuming a specific exploit or impact.
Best Practices
Define the path forms your application accepts, then test them through the same proxy and server chain used in deployment. Add regression cases for literal and encoded semicolons, including rejected requests if rejection is the intended policy.
Make normalization and authorization decisions consistent with the path ultimately used for routing. Where that is not possible, reject ambiguous forms at an appropriate boundary and verify that downstream components cannot reinterpret them differently.
Conclusion
A semicolon's presence alone does not determine a route. Compare the request target, parsed path, transformations, and selected handler at each layer, then document and test the behavior your deployment intends to support.
What would your domain sell for?
A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.