[php-src] PR #25896: Fix GH-25880: HTTP wrapper resolves "//host/path" Location against the original host (master)
| From: | matyapiro31 | Date: | Sun, 29 Nov 2026 11:24:02 +0000 |
| Subject: | [php-src] PR #25896: Fix GH-25880: HTTP wrapper resolves "//host/path" Location against the original host (master) | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-41188@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/25896
Author: matyapiro31
Fixes GH-25880.
Replaces #25881, which targeted PHP-8.4 — [per @devnexen's
comment](https://github.com/php/php-src/pull/25881#issuecomment-7253499983) this qualifies more for
master, since it changes where a redirect goes.
## Problem
A redirect
Location value 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):
```mermaid
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 contacted
```
**After**:
```mermaid
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 stripped
```
## Change
In the redirect handling of ext/standard/http_fopen_wrapper.c, a Location
beginning with // now becomes <current scheme>:<Location> and
goes through the existing path (php_uri_parse_to_struct, same_origin
check, control character check). Nothing else in the resolution logic changed.
```mermaid
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 --> P
```
This 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.h now requires C11, which this
machine's MSVC configuration doesn't enable) blocks nmake before it reaches
this code. The logic itself is unchanged from the already-reviewed #25881; relying on CI here.
- Other relative forms (?query-only, dot segments) are intentionally left unchanged.
🤖 Generated with [Claude Code](https://claude.com/claude-code)