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

fix(SetupChecks): Validate URL before parsing #49379

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

joshtrichards
Copy link
Member

@joshtrichards joshtrichards commented Nov 19, 2024

Came up while looking at #49373 / #49370 in stable30.

Summary

Using filter_var() should be safer / more likely to catch edge cases.

Also adds the url in the error output to help the operator track down the culprit faster.

TODO

Checklist

Copy link
Contributor

@come-nc come-nc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this less, because it does not explicitely check the return of parse_url. It’s bad for static analysis also.

And $url in the single quoted string will not be interpolated.

@joshtrichards
Copy link
Member Author

I like this less, because it does not explicitely check the return of parse_url. It’s bad for static analysis also.

Restructured the logic. Now we do it all. Plus we also check things even when not removing the web-root unlike master.

And $url in the single quoted string will not be interpolated.

🤦‍♂️ Fixed.

@joshtrichards joshtrichards force-pushed the fix-setupchecks-normalizeUrl-url-filter branch from b84b787 to d8cd202 Compare November 19, 2024 20:40
@joshtrichards
Copy link
Member Author

Also expanded the unit tests.

Comment on lines +96 to +168
// web-root left alone
// hostname without web-root
'nothing to change' => ['http://example.com', false, 'http://example.com'],
'with trailing slash' => ['http://example.com/', false, 'http://example.com'],
'with port and nothing to change' => ['http://example.com:8081', false, 'http://example.com:8081'],
'with port and trailing slash' => ['http://example.com:8081/', false, 'http://example.com:8081'],
// hostname with web-root
'nothing to change' => ['http://example.com/root', false, 'http://example.com/root'],
'with trailing slash' => ['http://example.com/root/', false, 'http://example.com/root'],
'with port and nothing to change' => ['http://example.com:8081/root', false, 'http://example.com:8081/root'],
'with port and trailing slash' => ['http://example.com:8081/root/', false, 'http://example.com:8081/root'],
// hostname with deep web-root
'nothing to change' => ['http://example.com/deep/webroot', false, 'http://example.com/deep/webroot'],
'with trailing slash' => ['http://example.com/deep/webroot/', false, 'http://example.com/deep/webroot'],
'with port and nothing to change' => ['http://example.com:8081/deep/webroot', false, 'http://example.com/deep/webroot'],
'with port and trailing slash' => ['http://example.com:8081/deep/webroot/', false, 'http://example.com/deep/webroot'],
// IPv4 instead of hostname without web-root
'nothing to change' => ['https://127.0.0.1', false, 'https://127.0.0.1'],
'with trailing slash' => ['https://127.0.0.1/', false, 'https://127.0.0.1'],
'with port and nothing to change' => ['https://127.0.0.1:8080', false, 'https://127.0.0.1:8080'],
'with port and trailing slash' => ['https://127.0.0.1:8080/', false, 'https://127.0.0.1:8080'],
// IPv4 instead of hostname with web-root
'nothing to change' => ['https://127.0.0.1/root', false, 'https://127.0.0.1/root'],
'with trailing slash' => ['https://127.0.0.1/root/', false, 'https://127.0.0.1/root'],
'with port and nothing to change' => ['https://127.0.0.1:8080/root', false, 'https://127.0.0.1:8080/root'],
'with port and trailing slash' => ['https://127.0.0.1:8080/root/', false, 'https://127.0.0.1:8080/root'],
// IPv6 instead of hostname without web-root
'nothing to change' => ['https://[ff02::1]', false, 'https://[ff02::1]'],
'with trailing slash' => ['https://[ff02::1]/', false, 'https://[ff02::1]'],
'with port and nothing to change' => ['https://[ff02::1]:8080', false, 'https://[ff02::1]:8080'],
'with port and trailing slash' => ['https://[ff02::1]:8080/', false, 'https://[ff02::1]:8080'],
// IPv6 instead of hostname with web-root
'nothing to change' => ['https://[ff02::1]/root', false, 'https://[ff02::1]/root'],
'with trailing slash' => ['https://[ff02::1]/root/', false, 'https://[ff02::1]/root'],
'with port and nothing to change' => ['https://[ff02::1]:8080/root', false, 'https://[ff02::1]:8080/root'],
'with port and trailing slash' => ['https://[ff02::1]:8080/root/', false, 'https://[ff02::1]:8080/root'],

// web-root specified for removal
// hostname without web-root
'nothing to change' => ['http://example.com', true, 'http://example.com'],
'with trailing slash' => ['http://example.com/', true, 'http://example.com'],
'with port and nothing to change' => ['http://example.com:8081', true, 'http://example.com:8081'],
'with port and trailing slash' => ['http://example.com:8081/', true, 'http://example.com:8081'],
// hostname with web-root
'without trailing slash' => ['http://example.com/root', true, 'http://example.com'],
'with trailing slash' => ['http://example.com/root/', true, 'http://example.com'],
'with port without trailing slash' => ['http://example.com:8081/root', true, 'http://example.com:8081'],
'with port and trailing slash' => ['http://example.com:8081/root/', true, 'http://example.com:8081'],
// hostname with deep web-root
'without trailing slash' => ['http://example.com/deep/webroot', true, 'http://example.com'],
'with trailing slash' => ['http://example.com/deep/webroot/', true, 'http://example.com'],
'with port without trailing slash' => ['http://example.com:8081/deep/webroot', true, 'http://example.com:8081'],
'with port and trailing slash' => ['http://example.com:8081/deep/webroot/', true, 'http://example.com:8081'],
// IPv4 instead of hostname without web-root
'nothing to change' => ['https://127.0.0.1', true, 'https://127.0.0.1'],
'with trailing slash' => ['https://127.0.0.1/', true, 'https://127.0.0.1'],
'with port and nothing to change' => ['https://127.0.0.1:8080', true, 'https://127.0.0.1:8080'],
'with port and trailing slash' => ['https://127.0.0.1:8080/', true, 'https://127.0.0.1:8080'],
// IPv4 instead of hostname with web-root
'without trailing slash' => ['https://127.0.0.1/root', true, 'https://127.0.0.1'],
'with trailing slash' => ['https://127.0.0.1/root/', true, 'https://127.0.0.1'],
'with port' => ['https://127.0.0.1:8080/root', true, 'https://127.0.0.1:8080/root'],
'with port and trailing slash' => ['https://127.0.0.1:8080/root/', true, 'https://127.0.0.1:8080/root'],
// IPv6 instead of hostname without web-root
'nothing to change' => ['https://[ff02::1]', true, 'https://[ff02::1]'],
'with trailing slash' => ['https://[ff02::1]/', true, 'https://[ff02::1]'],
'with port and nothing to change' => ['https://[ff02::1]:8080', true, 'https://[ff02::1]:8080'],
'with port and trailing slash' => ['https://[ff02::1]:8080/', true, 'https://[ff02::1]:8080'],
// IPv6 instead of hostname with web-root
'without trailing slash' => ['https://[ff02::1]/root', true, 'https://[ff02::1]'],
'with trailing slash' => ['https://[ff02::1]/root/', true, 'https://[ff02::1]'],
'with port' => ['https://[ff02::1]:8080/root', true, 'https://[ff02::1]:8080'],
'with port and trailing slash' => ['https://[ff02::1]:8080/root/', true, 'https://[ff02::1]:8080'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You cannot use the same key several time in an associative array, your are overwriting the previous value each time you use the same key.

@joshtrichards joshtrichards added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Nov 21, 2024
@blizzz blizzz mentioned this pull request Jan 8, 2025
@skjnldsv skjnldsv mentioned this pull request Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants