-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## There are two paths in every Starlette request\n\nThe ASGI scope dict is a structured wire-level interface. `scope[\"path\"]` is the path the server parsed from the HTTP request line. Starlette's router uses it. The route table on a `FastAPI()` app is matched against it. Whatever function ends up running, it ran because `scope[\"path\"]` named it.\n\n`request.url.path` is a different field. It is a property on a `URL` object that `Request.url` constructs lazily from the scope. The constructor lives in `starlette/datastructures.py`:\n\n```python\nclass URL:\n def __init__(self, url: str = \"\", scope: Scope | None = None, **components):\n if scope is not None:\n scheme = scope.get(\"scheme\", \"http\")\n server = scope.get(\"server\", None)\n path = scope[\"path\"]\n query_string = scope.get(\"query_string\", b\"\")\n\n host_header = None\n for key, value in scope[\"headers\"]:\n if key == b\"host\":\n host_header = value.decode(\"latin-1\")\n break\n\n if host_header is not None:\n url = f\"{scheme}://{host_header}{path}\"\n elif server is None:\n url = path\n ...\n self._url = url\n```\n\n`self._url` is a string. The `.path` property runs `urlsplit(self._url).path`. The path returned by that property is not the path the router used. It is the path field that `urlsplit` recovers from a string Starlette wrote by joining four pieces: the scheme, `://`, the Host header, and the scope path.\n\nThree of those pieces come from the server's own configuration. One is from the client.\n\n## The bypass is `urlsplit` reading the Host header\n\nPick a Host value that, when concatenated, produces a URL whose `.path` differs from `scope[\"path\"]`.\n\n```\nGET /admin HTTP/1.1\nHost: 127.0.0.1:8000/health?x=\n```\n\nThe scheme is `http`. The scope path is `/admin`. The Host header is `127.0.0.1:8000/health?x=`. The string Starlette concatenates is:\n\n```\nhttp://127.0.0.1:8000/health?x=/admin\n```\n\nHand that to `urlsplit`:\n\n```python\n>>> from urllib.parse import urlsplit\n>>> urlsplit(\"http://127.0.0.1:8000/health?x=/admin\")\nSplitResult(scheme='http', netloc='127.0.0.1:8000', path='/health', query='x=/admin', fragment='')\n```\n\n`urlsplit` has no model of what the application meant. It applies RFC 3986's grammar to the string. `/` after the authority opens the path. `?` ends the path and opens the query. The scope path falls into the query.\n\n`request.url.path` is now `/health`. `request.scope[\"path\"]` is still `/admin`. Both live on the same `Request` object. They disagree.\n\nAny middleware that reads `request.url.path` and uses it to make an authorization decision is reading a label whose value the Host header controls. The PoC's lab makes the disagreement visible by writing the middleware exactly that way:\n\n```python\n@app.middleware(\"http\")\nasync def intentionally_vulnerable_path_auth(request: Request, call_next):\n middleware_path_seen = request.url.path # vulnerable sink\n real_scope_path = request.scope.get(\"path\")\n\n if middleware_path_seen.startswith(PUBLIC_PATH_PREFIXES):\n response = await call_next(request)\n ...\n```\n\n`PUBLIC_PATH_PREFIXES` includes `/health`. `middleware_path_seen` is `/health`. The middleware allows. `call_next(request)` advances the request to the router. The router reads `scope[\"path\"]`, which is still `/admin`. The `/admin` handler runs. Whatever the application would return for an authenticated `/admin` request, the response is returned unauthenticated.\n\nThe curl from the lab's `manual_test.sh`:\n\n```bash\ncurl -i -H \"Host: 127.0.0.1:8000/health?x=\" http://127.0.0.1:8000/admin\n# expected: 200, admin-dashboard-data\n```\n\n## The two paths are a filter and a sink that were never written to agree\n\nStarlette ships two consumers of \"the path of this request.\" `scope[\"path\"]` is the value the protocol parser put there. `request.url.path` is the value `urlsplit` recovers from a string Starlette assembles on demand. They are derived through different code, from different inputs, and they have always been allowed to differ.\n\nThe author of an auth middleware reading `request.url.path` is not making an obvious mistake. The label looks like the request's path. The Starlette docs describe `request.url` as the URL of the request. Both `scope[\"path\"]` and `request.url.path` return `/health` for a healthy request to `/health`. The difference only manifests when an attacker controls a header that one of the constructors reads.\n\nThat is the shape this blog has been naming `gate-narrower-than-sink`. Two parsers read what should be the same logical input. The grammar of the gate's parser, `urlsplit` applied to a string that includes the Host header, is a different grammar than the sink's, the ASGI server's request-line parser writing to `scope[\"path\"]`. The input the sink accepts but the gate does not match flows through unfiltered. The [W3 Total Cache CVE](/posts/w3-total-cache-cve-2026-27384-strip-stricter-than-executor) this blog covered was the same shape with two PHP regexes describing the same template syntax differently. This one is the same shape with `urllib.parse.urlsplit` on one side and the ASGI server on the other.\n\n## The PoC's lab pins the version its README calls fixed\n\nThe PoC ships two artifacts: a network scanner and an intentionally vulnerable FastAPI lab. The scanner's README says:\n\n> **Affected:** Starlette ≤ 0.46.1 / FastAPI ≤ 0.115.x\n> **Fixed in:** Starlette 0.46.2+\n\nThe lab's `requirements.txt` says:\n\n```\nfastapi==0.115.12\nstarlette==0.46.2\nuvicorn[standard]==0.34.2\npydantic>=2.7,<3\n```\n\nThe lab's README explains that both apps, `app_vulnerable.py` on port 8000 and `app_fixed.py` on port 8001, use the same intentionally vulnerable Starlette package version. The `manual_test.sh` script expects the vulnerable app on `0.46.2` to return `200` for the bypass. It does.\n\nThe PoC author shipped a working demonstration that the version the scanner's documentation calls fixed is not. The `app_fixed.py` next to it works around the bug by reading `request.scope[\"path\"]` instead of `request.url.path`. The pattern-level fix the lab demonstrates is a developer-side change, not a framework upgrade.\n\nThe Starlette `URL` constructor on `0.46.2` concatenates the Host header into the string `urlsplit` reads, with no validation:\n\n```python\nif host_header is not None:\n url = f\"{scheme}://{host_header}{path}\"\n```\n\nThat line is identical in `0.46.1`, `0.46.2`, `0.47.0`, `0.47.1`, `0.47.2`, `0.47.3`, `0.48.0`, all of `0.49.x` through `0.52.x`, `1.0.0`, and `1.0.1`. Every version the scanner names as fixed still ships the line.\n\n## The fix is one regex on the Host header\n\nCommit `764dab0` in the Starlette repo, May 21, 2026, titled \"Ignore malformed `Host` header when constructing `request.url`\":\n\n```diff\n+# Rejects Host header chars (/, ?, #, @, ...) that would let urlsplit produce a path differing from scope[\"path\"].\n+_HOST_RE = re.compile(r\"^([a-z0-9.-]+|\\[[a-f0-9]*:[a-f0-9.:]+\\])(?::[0-9]+)?$\", re.IGNORECASE)\n...\n- if host_header is not None:\n+ if host_header is not None and _HOST_RE.fullmatch(host_header):\n url = f\"{scheme}://{host_header}{path}\"\n```\n\nThe maintainer's own comment names the bug. A Host header containing `/`, `?`, `#`, or `@` is rejected because allowing it lets `urlsplit` produce a path differing from `scope[\"path\"]`. The line that names the threat is added in the same commit as the line that closes it.\n\n`_HOST_RE` shipped in Starlette `1.1.0`, tagged 2026-05-23. The PoC was published 2026-05-28, five days after `1.1.0`, three hours before `1.2.0`. The \"Fixed in: Starlette 0.46.2+\" line was wrong when it was written.\n\n## host-header-as-self, again\n\nThis blog has named the shape: [host-header-as-self](/posts/airflow-aws-saml-poc-tests-wrong-endpoint). A server validates inbound requests against its own URL and derives that URL from a header the client sets. The signed \"intended for X\" check becomes \"intended for whatever the client claims X is.\" That post traced the Apache Airflow AWS Auth Manager's `_prepare_request` reading the Host header into `request_data['http_host']`, which flowed into `python3-saml`'s `Destination` check, which compared a signed SAML attribute against a value the IdP and the attacker both controlled.\n\nCVE-2026-48710 is the same shape one layer down. Airflow's bug used the Host header to compute the SAML self-URL the cryptographic gate compared against. Starlette's bug uses the Host header to compute the `request.url.path` value any custom auth middleware might gate on. The shared mechanism in both cases is the assembly of a string out of server fields and a client-supplied header, followed by a structural operation (signature check, `startswith`) that treats the whole string as the server's.\n\nThe Airflow exhibit's pre-patch line was `host = request.headers.get(\"host\", request.client.host if request.client else \"localhost\")`. The Starlette pre-patch line is `url = f\"{scheme}://{host_header}{path}\"`. Both functions believed they were computing the server's notion of itself. Both were transcribing the client's claim about it.\n\n## Close\n\nThe PoC's scanner is competent. The mechanism it tests for is real. The lab it ships is internally consistent: the version pinned in `requirements.txt` does demonstrate the bypass, and the `app_fixed.py` next to it does demonstrate the developer-side mitigation. The wrong sentence is the four-word claim at the top of the scanner's README that names a framework version that does not contain the fix.\n\nPoC: [Bhanunamikaze/BadHost-CVE-2026-48710-Exploit](https://github.com/Bhanunamikaze/BadHost-CVE-2026-48710-Exploit)\n","closing_line":"The fix is one regex on the Host header. It landed in main five days before the PoC dropped, in a release the PoC's README does not name.","hook_md":"`request.url.path` is not the request's path. It is the path field of a URL Starlette builds by concatenating the scheme, the Host header, and `scope[\"path\"]`, then handing the result to `urlsplit`. When the Host header contains a `/`, `urlsplit` reads it as the URL's path delimiter and `request.url.path` returns whatever the header named. The router still dispatches on `scope[\"path\"]`. CVE-2026-48710 is a middleware that gates on the first label and a sink that runs the second.","post_id":505,"slug":"starlette-cve-2026-48710-request-url-path-is-not-the-requests-path","title":"CVE-2026-48710: Starlette's request.url.path Is Not the Request's Path","type":"initial","unreadable_sentence":"`request.url.path` is not the request's path."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCaoIFrQAKCRDeZjl4jgkQ Jrl/AQDlNKcawS5F/e9v12A++GQC+fJ56gvxq2UNRPIkV5geDgEAwosUjOIsvnoF sOyEJ8KYThRmMG+x9KSXaTGvxTiVOAQ= =HNyd -----END PGP SIGNATURE-----