Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit 5234f4a

Browse files
committed
Remove support for the X-Original-Url and X-Rewrite-Url headers
This patch modifies the logic of `Zend\Http\PhpEnvironment\Request::detectRequestUri()` such that it will ignore the X-Original-Url and X-Rewrite-Url headers when marshaling the request URI.
1 parent 9812b6e commit 5234f4a

File tree

3 files changed

+39
-27
lines changed

3 files changed

+39
-27
lines changed

CHANGELOG.md

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,50 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5-
## 2.8.1 - TBD
5+
## 2.8.1 - 2018-08-01
66

77
### Added
88

99
- Nothing.
1010

1111
### Changed
1212

13-
- Nothing.
13+
- This release modifies how `Zend\Http\PhpEnvironment\Request` marshals the
14+
request URI. In prior releases, we would attempt to inspect the
15+
`X-Rewrite-Url` and `X-Original-Url` headers, using their values, if present.
16+
These headers are issued by the ISAPI_Rewrite module for IIS (developed by
17+
HeliconTech). However, we have no way of guaranteeing that the module is what
18+
issued the headers, making it an unreliable source for discovering the URI. As
19+
such, we have removed this feature in this release of zend-http.
20+
21+
If you are developing a zend-mvc application, you can mimic the
22+
functionality by adding a bootstrap listener like the following:
23+
24+
```php
25+
public function onBootstrap(MvcEvent $mvcEvent)
26+
{
27+
$request = $mvcEvent->getRequest();
28+
$requestUri = null;
29+
30+
$httpXRewriteUrl = $request->getHeader('X-Rewrite-Url');
31+
if ($httpXRewriteUrl) {
32+
$requestUri = $httpXRewriteUrl->getFieldValue();
33+
}
34+
35+
$httpXOriginalUrl = $request->getHeader('X-Original-Url');
36+
if ($httpXOriginalUrl) {
37+
$requestUri = $httpXOriginalUrl->getFieldValue();
38+
}
39+
40+
if ($requestUri) {
41+
$request->setUri($requestUri)
42+
}
43+
}
44+
```
45+
46+
If you use a listener such as the above, make sure you also instruct your web
47+
server to strip any incoming headers of the same name so that you can
48+
guarantee they are issued by the ISAPI_Rewrite module.
1449

1550
### Deprecated
1651

src/PhpEnvironment/Request.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -434,18 +434,6 @@ protected function detectRequestUri()
434434
$requestUri = null;
435435
$server = $this->getServer();
436436

437-
// Check this first so IIS will catch.
438-
$httpXRewriteUrl = $server->get('HTTP_X_REWRITE_URL');
439-
if ($httpXRewriteUrl !== null) {
440-
$requestUri = $httpXRewriteUrl;
441-
}
442-
443-
// Check for IIS 7.0 or later with ISAPI_Rewrite
444-
$httpXOriginalUrl = $server->get('HTTP_X_ORIGINAL_URL');
445-
if ($httpXOriginalUrl !== null) {
446-
$requestUri = $httpXOriginalUrl;
447-
}
448-
449437
// IIS7 with URL Rewrite: make sure we get the unencoded url
450438
// (double slash problem).
451439
$iisUrlRewritten = $server->get('IIS_WasUrlRewritten');
@@ -454,12 +442,10 @@ protected function detectRequestUri()
454442
return $unencodedUrl;
455443
}
456444

445+
$requestUri = $server->get('REQUEST_URI');
446+
457447
// HTTP proxy requests setup request URI with scheme and host [and port]
458448
// + the URL path, only use URL path.
459-
if (! $httpXRewriteUrl) {
460-
$requestUri = $server->get('REQUEST_URI');
461-
}
462-
463449
if ($requestUri !== null) {
464450
return preg_replace('#^[^/:]+://[^/]+#', '', $requestUri);
465451
}

test/PhpEnvironment/RequestTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,6 @@ public static function baseUrlAndPathProvider()
116116
'/index.php',
117117
'',
118118
],
119-
[
120-
[
121-
'HTTP_X_REWRITE_URL' => '/index.php/news/3?var1=val1&var2=val2',
122-
'PHP_SELF' => '/index.php/news/3',
123-
'SCRIPT_FILENAME' => '/var/web/html/index.php',
124-
],
125-
'/index.php',
126-
'',
127-
],
128119
[
129120
[
130121
'ORIG_PATH_INFO' => '/index.php/news/3',

0 commit comments

Comments
 (0)