Page MenuHomePhabricator

parse_url() behavior has changed with PHP7, causing libphutil unit tests to fail and possibly creating security concerns
Closed, ResolvedPublic

Description

Some of the PhutilURITestCase::testURIParsing tests currently fail on PHP7.1 because of this fix:

https://bugs.php.net/bug.php?id=73192

However, it's possible that this fix actually creates danger if cURL has different behavior. See T6755 for context. We should:

  • Fix these tests, possibly by rejecting these URIs on both versions of PHP with an exception.
  • Definitely make PhutilURI start throwing exceptions on this junk if some versions of PHP and some versions of cURL could conspire to behave unsafely.

Event Timeline

I think this is, to at least some degree, a legitimate security problem. Consider:

http://good.com#u:p@evil.com/
ClientDomain
Safarigood.com
cURL CLIevil.com
PHP < 7.1evil.com
PHP >= 7.1good.com
Chromegood.com
Firefoxgood.com
wgetgood.com

I think we just need to detect anything in this form (and the similar form, http://good.com?u:p@evil.com -- with ? instead of #) and reject it. The unambiguous way to write this is either good.com/? (query string) or good.com%3A (username).

This change creates a slight problem for us at KDE as we have some historical commits in our Subversion repository which have URLs in them which are invalid. This exception means that:

  • Herald spins forever trying to process these commits, failing every single time (currently up to 855 failures).
  • The commit can't be viewed in the browser (See https://phabricator.kde.org/R883:271607)

Would it be acceptable to change PhutilRemarkupHyperlinkRule to catch this exception and behave as if it were a non-whitelisted protocol? (Happy to draft the patch, just want to check before I do so)

Would it be acceptable to change PhutilRemarkupHyperlinkRule to catch this exception and behave as if it were a non-whitelisted protocol? (Happy to draft the patch, just want to check before I do so)

Yep, see D18149 and D18076 for similar changes.

(I'll fix this if you don't get there first, but have used up all my brain energy for today. And thanks for the report!)

Not a problem - thanks for fixing that so quickly.
I can confirm that fixed the issue for us.