-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fix running Grav under Load Balancer with custom_base_url #3821
base: develop
Are you sure you want to change the base?
Conversation
…etgrav#2184]" Previous change broke running Grav under Load Balancer with custom_base_url set. Also, it's not a good idea to add 3rd party domain into host value, which could be accidently reused some time in the future. This (not counting CHANGELOG) reverts commit 0af3385.
P.S. I'm not sure why that one test case for |
The With your change, it makes Grav vulnerable again to host-based attacks as it then allows the poor parsing in PHP's parse_url() to be fooled by escaped script tags. The approach of using |
But if Without patch calling https://mycustom.example.com/custom_base//www.fake.com/pagea/subpageb
With patch calling https://mycustom.example.com/custom_base//www.fake.com/pagea/subpageb
Nevertheless, I'm still not sure what you mean by "vulnerable to host based attacks". If you mean that by adding http://domain.com it will protect from SSRF type of attacks I don't think it will. There are multiple other techniques how to exploit parse_url() behaviour. On top of that, PHP documentation clearly states that parse_url() cannot be trusted for URL validation, especially relative URLs, and additional measures, such as filter_var(), should be added. Or better yet, just compare the beginning of the path/header/whatever to the current absolute URL of the website to make sure you are actually redirecting to yourself. Thus, I still think adding domain which is controlled by a third-party to your code is not a proper fix. It is dangerous for lot of reasons big and small, e.g. https://medium.com/@maciej.pocwierz/how-an-empty-s3-bucket-can-make-your-aws-bill-explode-934a383cb8b1 At least it should have been http://domain.invalid or any other non routable registered domain. |
P.S. I also found custom |
So I added a test to the current 'develop' branch: public function testCustomBase(): void
{
$current_base = $this->config->get('system.custom_base_url');
$this->config->set('system.custom_base_url', '/test');
$this->uri->initializeWithURL('https://mydomain.example.com:8090/test/korteles/kodai%20something?test=true#some-fragment')->init();
$this->assertSame([
"scheme" => "https",
"host" => "mydomain.example.com",
"port" => 8090,
"user" => null,
"pass" => null,
"path" => "/korteles/kodai%20something",
"params" => [],
"query" => "test=true",
"fragment" => "some-fragment",
], $this->uri->toArray());
$this->config->set('system.custom_base_url', $current_base);
} **This passes as-is without your patch.. ** You can't simply dump the I beleive the current functionality is working as expected. Are you expecting some different? |
I'm not sure what should be put into initializeWithURL() but keep in mind, that |
P.S. I have tested your changes in c97a0ff . It still doesn't work. I get 404 for all pages. Dumped objects in the screenshot is $uri before static::parseUrl() ant $bits after it: |
Is there anything else I could do to progress this PR? |
Previous change broke running Grav under load balancer with custom_base_url set. All dynamic urls (pages, admin, etc.), returns 404. All static content is not affected.
dump($bits) just after this parse_url()
Original Grav 1.7.45 code accessed directly from http://localhost:8080/korteles/kodai
Result - OK.
Grav 1.7.45 with this PR applied accessed directly from http://localhost:8080/korteles/kodai
Result - OK.
Original Grav 1.7.45 code accessed from load balancer https://mydomain.example.com/test/korteles/kodai (
custom_base_url: /test
)Result - 404 or even some nasty httpd cycles, depending on the configuration of load calancer.
Grav 1.7.45 with this PR applied accessed from load balancer https://mydomain.example.com/test/korteles/kodai (
custom_base_url: /test
)Result - OK.
Load balancer is configured to rewrite /test/(.*) to /$1, and I ensured that it is reaching Grav under correct path. The patch probably also fixes #3511 .
Also, it's not a good idea to add 3rd party domain into host value, which could be accidently reused some time in the future.