New issue
Advanced search Search tips

Issue 812543 link

Starred by 2 users

Issue metadata

Status: Fixed
Owner:
Closed: Feb 2018
Cc:
Components:
EstimatedDays: ----
NextAction: 2018-02-26
OS: ----
Pri: ----
Type: Bug



Sign in to add a comment

It's possible to construct URLPatterns with empty host

Reported by m...@the-compiler.org, Feb 15 2018

Issue description

PREFACE
-------

I've found an issue with URLPatterns (src/extensions/common/url_pattern.cc) which makes it possible to construct an URL pattern with an empty host. While this isn't a vulnerability in itself, it violates an invariant which other code seems to rely on, namely that the host is never empty. I haven't found a concrete exploit based on it yet, only various other strange and potentially dangerous behavior. Still, I feel it's better to report this privately as there's a lot of permission related code using URLPatterns and relying on that invariant. Because of that, I believe there are possibly ways to exploit this further than I've done below.

Let me note that this is the first time I'm reporting something as security bug, so please let me know if you need any additional information.

VULNERABILITY DETAILS
---------------------

A URL pattern such as "https://:443/" is treated as valid, despite not having a host (only a port). This is because an empty host is checked in various places (see PARSE_ERROR_EMPTY_HOST in url_pattern.cc) but never when host/port are separated.

Interestingly enough, there's even a unittest for this:
https://cs.chromium.org/chromium/src/extensions/common/url_pattern_unittest.cc?l=73&rcl=fd6806b8dae4614967be60035c47303b5ec36d76

However, there are various reasons I still believe this to be a mistake:

- The normal URL parser rejects such URLs.
- Various comments in url_pattern.cc say so, and internally, an empty host is actually used for "*" (matches any host) - however, only with match_subdomains_ set to true.
- With the pattern "https://:443/", the permission dialog shows "It can read and change your data on" (sic).
- With the pattern "*://:*/", all tabs and extensions crash (failed checks) and Chrome is unusable until the extension is removed.

Exaple of failed checks when the crashes happen:
[30:30:0215/014303.207072:FATAL:dispatcher.cc(926)] fjnbnpbmkenffdnngjfgmeleoegfcffe was never loaded: 
[82:82:0215/013659.806060:FATAL:user_script.cc(304)] Check failed: URLPattern::PARSE_SUCCESS == result. Host can not be empty. *:///
(the latter seems to come from re-parsing an adjusted host name as URLPattern a second time)

Crash IDs I got for a single reproduction with the crashing pattern:
00b03a4d0572681c, ed3e7c170f596277, 59f0a336a1eafe56, 0fdda6fc9bada545, 1364a0b2af59485b, 261a46b0b74b602d, 5d289abb965161d7, 2bc92ad91874f3f5

VERSION
-------

Chromium 64.0.3282.140 (stable) on Archlinux
Chromium 66.0.3343.3 (dev) on Archlinux

I don't expect there to be any difference with another OS.

REPRODUCTION CASE
-----------------

I've attached two .crx files:

- urlmatch_text.crx: Will show the faulty text in the permission dialog. (Un)fortunately, it doesn't actually run test.js (which does alert("foo")) on any website it seems.
- urlmatch_crash.crx: As soon as it's installed, all tabs (including chrome://extensions) and all extensions will crash and you'll need to remove it (e.g. via the extension icon) to make Chrome usable again. Note that any other extensions installed will be disabled and need to be enabled by hand again.

(Since .crx files are valid(-ish) .zip files, you should be able to unpack them to get the source easily.)

PATCH
-----

I currently can't build Chromium easily, but I attached a (completely untested) patch (meant to be applied with -p0 in the src/extensions/common/ subdir) with how I'd try to solve it. I have no idea if it works properly, so feel free to ignore it if not.
 
urlmatch_crash.crx
937 bytes Download
urlmatch_text.crx
958 bytes Download
urlmatch.patch
1.5 KB Download
Cc: rdevlin....@chromium.org
Components: Platform>Extensions
Labels: -Type-Bug-Security -Restrict-View-SecurityTeam FoundIn-66 FoundIn-64 Restrict-View-Google Type-Bug
Summary: It's possible to construct URLPatterns with empty host (was: Security: It's possible to construct URLPatterns with empty host)
Interesting, thanks for the report! 

At this point, this is only a stability issue (as these CHECK failures cause a Denial of Service condition).

If you find a way to get a more meaningful crash, please do update the issue.
Labels: Needs-Triage-M64
Cc: kkaluri@chromium.org
Labels: TE-NeedsTriageHelp
Unable to triage this issue from TE-End, hence adding TE-NeedsTriageHelp for further triage.
Cc: -rdevlin....@chromium.org
Owner: rdevlin....@chromium.org
Status: Assigned (was: Unconfirmed)
Nice find!  We should definitely fix that.  I've been in the area lately; I'll take it.
Project Member

Comment 5 by bugdroid1@chromium.org, Feb 23 2018

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/0ab1294c92dfab538b185f0f25f44f6491a49759

commit 0ab1294c92dfab538b185f0f25f44f6491a49759
Author: Devlin Cronin <rdevlin.cronin@chromium.org>
Date: Fri Feb 23 01:37:35 2018

[Extensions] Fix URLPattern Port Parsing

Fix URLPattern parsing when a port is present to ensure that a host is
provided. Also optimize a bit to avoid a few additional string copies.

Bug:  812543 , 810525

Change-Id: I209bf3f0dac37ce4d774e8bbb89fb7712284c6bc
Reviewed-on: https://chromium-review.googlesource.com/930000
Commit-Queue: Devlin <rdevlin.cronin@chromium.org>
Reviewed-by: Karan Bhatia <karandeepb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#538657}
[modify] https://crrev.com/0ab1294c92dfab538b185f0f25f44f6491a49759/extensions/common/url_pattern.cc
[modify] https://crrev.com/0ab1294c92dfab538b185f0f25f44f6491a49759/extensions/common/url_pattern_unittest.cc

NextAction: 2018-02-26
I think this should be fixed with #5.  I couldn't quite just use the patch provided in the original post because it wouldn't work with a few valid cases of having an empty host, but it was on the right track.

If you have a chance, and access to a trunk build (or Canary, in a day or so), please feel free to test this out and see if you find any other cases where this crops up!  I'll follow up on Monday and close this out if all seems well.

Thank you again for the report! :)
Thanks for the quick fix! I probably won't be able to test it before Monday, but it seems fine from a look at the diff.

Given that it's (hopefully) not security relevant and there's a fix on the way, would it be possible to remove Restrict-View-Google for this bug?
Cc: elawrence@chromium.org
I have no objections to removing the restriction.  Eric, any opinion?
Labels: -Restrict-View-Google
Fine by me. 
The NextAction date has arrived: 2018-02-26
Status: Fixed (was: Assigned)
Closing this one out.  Let us know if we missed anything!

Sign in to add a comment