Skip to content
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

[HTTP Foundation] Fixed get path info issue #32008

Open
wants to merge 2 commits into
base: 4.4
from

Conversation

Projects
None yet
3 participants
@andypan104
Copy link

commented Jun 12, 2019

Q A
Branch? 4.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets N/A
License MIT
Doc PR N/A

Hello,
I fixed some issue on perpareBaseUrl() function.

In the case:

URL: '/xxxxx/index.php'
filePath: '/aaa/index.php/xxxxx/index.php' (apache hide '/aaa/index.php' )

prepareBaseUrl() return '/aaa/index.php' not ''
preparePathInfo() return 'hp' not '/xxxxx/index.php'.

fixed:
ADD check request URI begin with base URL.

@Tobion

This comment has been minimized.

Copy link
Member

commented Jun 12, 2019

I think we should work on #14064 (comment)
Whatever we try to guess, it's just always only a guess. Using path_info correctly should remove the guess work. @andypan104 would you want to work on the linked ticket?

@andypan104 andypan104 force-pushed the andypan104:4.4 branch from 80e704f to d085b26 Jun 13, 2019

@andypan104

This comment has been minimized.

Copy link
Author

commented Jun 13, 2019

Thx for suggest. but it's not working for me.


I think prepareBaseUrl only check URL include basename only.

Line:1801

!strpos(rawurldecode($truncatedRequestUri), $basename)

In my case:
I use apache RewriteRule to hide really file path for security.

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteRule ^(.*)$ public/index.php$1 [L]
</IfModule>

and I have same basename (index.php) in my route.
Use getPathInfo and return wrong information.

URL: http://domain/userInfo/index.php?id=123
Really path: /var/www/html/public/index.php/userInfo/index.php
getPathInfo is hp

I found the issue from prepareBaseUrl, cause it just check basename() not full URL.

If I used different as basename (index_1.php), get the correct pathInfo for me.
Cause line:1801 !strpos(rawurldecode($truncatedRequestUri), $basename) is true.

URL: http://domain/userInfo/index_1.php?id=123
Really path: /var/www/html/public/index.php/userInfo/index_1.php
getPathInfo is /userInfo/index_1.php

@andypan104

This comment has been minimized.

Copy link
Author

commented Jun 13, 2019

In #14064 (comment) getPathInfo() is fixed, but getUri() is not.

test case:

        $request = Request::create('http://test.com/test/app.php', 'GET', [], [], [],
            [
                'DOCUMENT_ROOT' => '/var/www/www.test.com',
                'SCRIPT_FILENAME' => '/var/www/www.test.com/app/app.php',
                'SCRIPT_NAME' => '/app/app.php',
                'PHP_SELF' => '/app/app.php/test/app.php',
            ]);
        $this->assertEquals('http://test.com/test/app.php', $request->getUri());
        $this->assertEquals('/test/app.php', $request->getPathInfo());
        $this->assertEquals('', $request->getQueryString());
        $this->assertEquals(80, $request->getPort());
        $this->assertEquals('test.com', $request->getHttpHost());
        $this->assertFalse($request->isSecure());

@andypan104 andypan104 closed this Jun 13, 2019

@andypan104 andypan104 reopened this Jun 13, 2019

@andypan104

This comment has been minimized.

Copy link
Author

commented Jun 13, 2019

Click wrong button.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.