Repository navigation
Fix GH-25880: HTTP wrapper resolves "//host/path" Location against the original host (master) - #25896
Open
matyapiro31 wants to merge 1 commit into
Open
matyapiro31 wants to merge 1 commit into
matyapiro31 wants to merge 1 commit into
Conversation
… the original host A Location value starting with "//" is a network-path reference (RFC 3986 section 4.2) that replaces authority and path while keeping the scheme. The redirect code only distinguished absolute URLs from values starting with a single "/", so "//other.example/x" was sent as the request target "//other.example/x" to the original host instead of following the redirect to other.example. Treat it as a network-path reference and prefix the current scheme. The resulting URL goes through the existing origin check, so credentials are still stripped when the host differs. Adapted from the PHP-8.4 fix in php#25881 to master's refactored redirect resolution code (in-place-decode removal, GHSA-f6gg-rchx-xw8j scheme check). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes GH-25880.
Replaces #25881, which targeted PHP-8.4 — per @devnexen's comment this qualifies more for master, since it changes where a redirect goes.
Problem
A redirect
Locationvalue starting with//is a network-path reference (RFC 3986 section 4.2): it replaces the authority and path and keeps the scheme. The HTTP wrapper instead treated it as an absolute path on the original host.Before (
Location: //other.example/target):sequenceDiagram participant P as PHP (http wrapper) participant A as original.example participant B as other.example P->>A: GET /a/b A-->>P: 302 Location: //other.example/target Note over P: "/" prefix => treated as absolute path<br/>URL = http://original.example//other.example/target P->>A: GET //other.example/target Note over B: never contactedAfter:
sequenceDiagram participant P as PHP (http wrapper) participant A as original.example participant B as other.example P->>A: GET /a/b A-->>P: 302 Location: //other.example/target Note over P: "//" prefix => network-path reference<br/>URL = http: + //other.example/target P->>B: GET /target Note over P: host differs => same_origin = false<br/>=> credentials are strippedChange
In the redirect handling of
ext/standard/http_fopen_wrapper.c, aLocationbeginning with//now becomes<current scheme>:<Location>and goes through the existing path (php_uri_parse_to_struct,same_origincheck, control character check). Nothing else in the resolution logic changed.flowchart TD L[Location header] --> Q{starts with '//'?} Q -- yes, new --> N["new_path = scheme + ':' + Location"] Q -- no --> S{absolute URL?<br/>http/https/ftp/ftps} S -- yes --> U[use as is] S -- no --> R["relative / absolute-path:<br/>unchanged behavior"] N --> P[php_uri_parse_to_struct + same_origin check] U --> P R --> PThis is the same fix as #25881, re-applied on top of master's refactored redirect-resolution code (the in-place-decode removal and the control-character-check helper added since PHP-8.4, and the case-insensitive scheme check from GHSA-f6gg-rchx-xw8j).
Tests
New
http_network_path_location_redirect.phpt: fails before this change (request target is//ADDR/target), passes after (/target).Notes
I could not locally build this checkout of master end-to-end to run the test myself — an unrelated Windows build-system issue (
Zend/zend_portability.hnow requires C11, which this machine's MSVC configuration doesn't enable) blocksnmakebefore it reaches this code. The logic itself is unchanged from the already-reviewed #25881; relying on CI here.?query-only, dot segments) are intentionally left unchanged.🤖 Generated with Claude Code