Page MenuHomePhabricator

Expand detection of protocol-relative hrefs to cover "/\evil.com" and variants
ClosedPublic

Authored by epriestley on Jan 18 2018, 8:05 PM.
Tags
None
Referenced Files
F14814527: D18873.id45265.diff
Mon, Jan 27, 4:53 PM
Unknown Object (File)
Sat, Jan 25, 2:58 PM
Unknown Object (File)
Fri, Jan 24, 11:01 PM
Unknown Object (File)
Fri, Jan 24, 11:01 PM
Unknown Object (File)
Fri, Jan 24, 11:00 PM
Unknown Object (File)
Fri, Jan 24, 9:48 PM
Unknown Object (File)
Wed, Jan 22, 12:21 AM
Unknown Object (File)
Tue, Jan 21, 11:14 AM
Subscribers
None

Details

Summary

Via HackerOne. See https://hackerone.com/reports/306414.

All browsers seem to accept <a href="/\evil.com" ...> as equivalent to //evil.com, i.e. a protocol-relative URI (uses "http" or "https" depending on the protocol for the current page).

They're equally accepting of <a href="/\/\\\\///\/\evil.com" ...> and so on, too.

I assume this is because normal users don't know the difference between slash and backslash, and someone in the 1990's thought this was a reaonable usability affordance and we're stuck with it forever?

Note that we've encountered this problem previously in PhabricatorEnv->isValidLocalURIForLink(), although the scope and context are a little different there. In that case, we simply reject URIs with backslashes anywhere.

The security risk associated with this -- "tabnabbing" -- is fairly low, and amounts to a targeted phishing attack, so I don't plan to take any exceptional security measures here.

Test Plan
  • Pre-change: wrote a [[ /\evil.com | xyz ]] link in Remarkup, saw it fail to get "noreferrer". Saw Chrome, Firefox and Safari all dutifully follow the link to evil.com.
  • Made change; added test coverage.
  • Tests pass.
  • Post-change: Verified /\evil.com link (and other similar links, e.g., ///evil.com, /\\evil.com) now get "noreferrer".

Diff Detail

Repository
rPHU libphutil
Branch
noreferrer
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 19047
Build 25701: Run Core Tests
Build 25700: arc lint + arc unit

Event Timeline

I think is probably clearer as-is instead of getting fancy with a regex.

This revision is now accepted and ready to land.Jan 18 2018, 8:09 PM

A vaguely related issue here is how we handle this in remarkup:

[[ http:/\evil.com/ | xyz ]]

We currently treat it as a wiki page, normalize it, and link to /w/evil.com/. This way this works is a little weird, but safe. If we treated it as a URI instead, browsers would accept it, since it seems that all browsers agree that this is a "perfectly valid" URI that has "absolutely nothing wrong with it".

I'm inclined to leave this behavior as-is for now. If we changed it in the future, I'd be inclined to explicitly reject these URIs as malformed.

This revision was automatically updated to reflect the committed changes.