-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
base: master
Are you sure you want to change the base?
Conversation
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.
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.
Restructured the logic. Now we do it all. Plus we also check things even when not removing the web-root unlike master.
🤦♂️ Fixed. |
Signed-off-by: Josh <[email protected]>
b84b787
to
d8cd202
Compare
Also expanded the unit tests. |
// 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'], |
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.
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.
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