-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Don't assume URIs with dots as static (#61286). #3215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1373,7 +1373,7 @@ static void php_cli_server_request_translate_vpath(php_cli_server_request *reque | |
char *buf = safe_pemalloc(1, request->vpath_len, 1 + document_root_len + 1 + sizeof("index.html"), 1); | ||
char *p = buf, *prev_path = NULL, *q, *vpath; | ||
size_t prev_path_len = 0; | ||
int is_static_file = 0; | ||
int is_php = 0; | ||
|
||
if (!buf) { | ||
return; | ||
|
@@ -1385,11 +1385,12 @@ static void php_cli_server_request_translate_vpath(php_cli_server_request *reque | |
if (request->vpath_len > 0 && request->vpath[0] != '/') { | ||
*p++ = DEFAULT_SLASH; | ||
} | ||
q = request->vpath + request->vpath_len; | ||
while (q > request->vpath) { | ||
if (*q-- == '.') { | ||
is_static_file = 1; | ||
break; | ||
q = request->vpath; | ||
{ | ||
if (q) { | ||
char *dot = strrchr(q, '.'); | ||
if (dot && !strcmp(dot, ".php")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In such case the file has not a ".php" extension. What's the problem? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If both are Thanks. |
||
is_php = 1; | ||
} | ||
} | ||
memmove(p, request->vpath, request->vpath_len); | ||
|
@@ -1420,7 +1421,7 @@ static void php_cli_server_request_translate_vpath(php_cli_server_request *reque | |
} | ||
file++; | ||
} | ||
if (!*file || is_static_file) { | ||
if (!*file || is_php) { | ||
if (prev_path) { | ||
pefree(prev_path, 1); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
--TEST-- | ||
PATH_INFO (relevant to #60112) | ||
--DESCRIPTION-- | ||
After this fix(#60112), previously 404 request like "localhost/foo/bar" | ||
now could serve correctly with request_uri "index.php" and PATH_INFO "/foo/bar/" | ||
--SKIPIF-- | ||
<?php | ||
include "skipif.inc"; | ||
?> | ||
--FILE-- | ||
<?php | ||
include "php_cli_server.inc"; | ||
php_cli_server_start('var_dump($_SERVER["PATH_INFO"]);', null); | ||
|
||
list($host, $port) = explode(':', PHP_CLI_SERVER_ADDRESS); | ||
$port = intval($port)?:80; | ||
|
||
$fp = fsockopen($host, $port, $errno, $errstr, 0.5); | ||
if (!$fp) { | ||
die("connect failed"); | ||
} | ||
|
||
if(fwrite($fp, <<<HEADER | ||
GET /foo/bar.anyext HTTP/1.1 | ||
Host: {$host} | ||
|
||
|
||
HEADER | ||
)) { | ||
while (!feof($fp)) { | ||
echo fgets($fp); | ||
} | ||
} | ||
|
||
fclose($fp); | ||
|
||
$fp = fsockopen($host, $port, $errno, $errstr, 0.5); | ||
if (!$fp) { | ||
die("connect failed"); | ||
} | ||
|
||
if(fwrite($fp, <<<HEADER | ||
GET /foo/bar.php HTTP/1.1 | ||
Host: {$host} | ||
|
||
|
||
HEADER | ||
)) { | ||
while (!feof($fp)) { | ||
echo fgets($fp); | ||
break; | ||
} | ||
} | ||
|
||
fclose($fp); | ||
?> | ||
--EXPECTF-- | ||
HTTP/1.1 200 OK | ||
Host: %s | ||
Date: %s | ||
Connection: close | ||
X-Powered-By: PHP/%s | ||
Content-type: text/html; charset=UTF-8 | ||
|
||
string(15) "/foo/bar.anyext" | ||
HTTP/1.1 404 Not Found |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,5 +42,5 @@ HEADER | |
|
||
fclose($fp); | ||
?> | ||
--EXPECTF-- | ||
HTTP/1.1 404 Not Found | ||
--EXPECT-- | ||
HTTP/1.1 200 OK |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part looks not quite correct. Fe how would be
/hello.php/world.php
handled? Iterating backwards seems to make more sense. Also some backward compatibility might be broken.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code before my patch, would raise a 404 unless a file corresponding to the path
/hello.php/world.php
is not present, because the path contains a dot.We can choose to make the recursive search for a router script for ANY file that does not exists, and I agree with this idea. I was only trying to be the less disruptive as possible with the previous behaviour.
For what concerns the backward compatibility: the built-in server is only used for development purposes and must not be used in production.
This new implementation serves all the files that the old one did, but it serves also other paths that instead would have got a 404 status.
As an example, Drupal 8 now works, while before it did not.