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

Restrict <base> to ~sane schemes. #2249

Closed
mikewest opened this issue Jan 9, 2017 · 47 comments · Fixed by #9665
Closed

Restrict <base> to ~sane schemes. #2249

mikewest opened this issue Jan 9, 2017 · 47 comments · Fixed by #9665

Comments

@mikewest
Copy link
Member

mikewest commented Jan 9, 2017

Apparently, Chrome is happy to support <base href="data:/randomness/">, which doesn't seem like a good idea. WDYT about restricting document base URLs to network schemes (and, I suppose, the scheme of the current document's URL's origin... file: comes to mind).

@annevk
Copy link
Member

annevk commented Jan 9, 2017

What's the reason for restricting it?

If we do this, we need to update quite a number of /url tests that rely on manipulating the base element to work.

@lweichselbaum
Copy link

If you can inject a base tag with data:, you can control all script tags with relative paths (in Chrome) and bypass nonce based CSPs.
E.g.: <script src=x.js nonce=random-123></script>

While I think it makes sense to fix this, it must be noted that the more generic form of this attack (using an attacker controlled domain) would still work.

<script src=x.js nonce=random-123></script>

@annevk
Copy link
Member

annevk commented Jan 9, 2017

Okay, so the assumption is that an attacker can inject a data URL <base>, but not an HTTP URL <base>?

@mikewest
Copy link
Member Author

mikewest commented Jan 9, 2017

I don't think this change has ~any value in preventing XSS. As you both note, the attacker can inject <base href='https://evil.com/'>. We accept the risk of the one (which we have to, because I'm pretty sure that cross-origin <base> is too widely used to discard), so we accept the risk of the other.

That said, it's not clear to me that it makes sense to include non-network schemes (and particularly non-hierarchical schemes) as potential document base URLs. I'm not suggesting that we remove the resolution rules set up in the URL spec; I am suggesting that we poke at the contours of what we allow for HTML documents. data:/path is a totally reasonable (for some definition of "reasonable") URL, and it should have resolution rules. That doesn't mean it should also be usable as a document base URL. :)

@mikewest
Copy link
Member Author

mikewest commented Jan 9, 2017

The specific thing that triggered this suggestion is actually a mismatch between the way the URL parser handles data: URLs, and the way Chrome handles extracting a body from data: URLs. That is, data:/,alert(1) is parsed as a URL with a scheme of data: and a path of /,alert(1), but turns into a resource with a body of alert(1) and a type of / when fetched. That's somewhat surprising.

@mikewest
Copy link
Member Author

I've landed https://codereview.chromium.org/2626243002 in Chrome to gather some metrics.

While we're here, it might also be reasonable to mitigate some dangling markup issues in target by restricting its character set to exclude things like < and \r\n. Let's see what the numbers look like.

@mikewest
Copy link
Member Author

mikewest commented Feb 8, 2017

@annevk, any thoughts on #2249 (comment)? Based on early numbers from the last week or so of Chrome's beta (which is, admittedly not a truly representative sample), data: appeared exactly zero times as a base URL.

Also, newlines in target appeared 5 times, and < 16 times. I'd like to restrict those as well. :)

@annevk
Copy link
Member

annevk commented Feb 8, 2017

Not really, that it works seems expected from how the system is designed. Though data URL parsing/interpretation could use some better interoperability and standard here and there.

As for adding defense-in-depth restrictions, it seems reasonable if we can get everyone to implement them. Bit ambivalent on the whole thing myself.

@mikewest
Copy link
Member Author

mikewest commented Feb 8, 2017

FWIW, based on quick experimentation with https://output.jsbin.com/zucihoraca:

  • Safari matches Chrome's behavior
  • Edge ignores data: inside <base> (it tries to request the original resource)
  • Firefox allows data: URLs in <base>, but doesn't request the resulting resource. I haven't dug into the details of why.

I'd like to change Chrome's behavior to align with either Edge or Firefox. Edge's behavior makes more sense to me. If you're ambivalent, that's what I'd prefer to do.

@annevk
Copy link
Member

annevk commented Feb 8, 2017

You will also need to test multiple <base> elements to see if its ignored or used but then ignored.

@mikewest
Copy link
Member Author

mikewest commented Feb 8, 2017

All browsers seem to ignore all but the first <base> element, as specified.

I should be more clear about what I mean when I say "ignored". The patch to HTML that I'd propose would be something like changing step 3 of https://html.spec.whatwg.org/multipage/semantics.html#set-the-frozen-base-url to:

  1. Set element's frozen base URL to document's fallback base URL, if urlRecord is failure, or urlRecord's scheme is data, or running "Is base allowed for Document?" on the resulting URL record and document returns "Blocked", and to urlRecord otherwise.

That is, we'd treat <base href="data:whatever"> just like <base href="http::::///////not-valid">. It would have a frozen base url of the document's fallback base url, and we'd ignore any subsequent <base> tags.

@bzbarsky
Copy link
Contributor

bzbarsky commented Feb 8, 2017

For what it's worth, the way Firefox handles this (in URL spec terms) is by always setting the "cannot-be-a-base-URL" flag on data: URLs.

@bzbarsky
Copy link
Contributor

Wait, why are we changing web platform tests before we've agreed on what the spec should say here?

@annevk
Copy link
Member

annevk commented Feb 10, 2017

Yeah I'm not sure why that happened. @jeffcarp that should not have been merged.

@annevk
Copy link
Member

annevk commented Feb 10, 2017

I created whatwg/meta#17 to clarify the CONTRIBUTOR guidelines around this so that it hopefully doesn't happen again.

@zcorpan
Copy link
Member

zcorpan commented Feb 10, 2017

I guess the problem here was that https://codereview.chromium.org/2685843003 landed before this PR, and tests are automatically upstreamed to web-platform-tests.

@zcorpan
Copy link
Member

zcorpan commented Feb 10, 2017

I sent a message to blink-dev about this https://groups.google.com/a/chromium.org/d/msg/blink-dev/QIRcSgN9AK4/0JY58rBhCAAJ

@RByers
Copy link

RByers commented Feb 10, 2017

Yes, this test change shouldn't have been landed until the spec was updated. Sorry about this, we're still getting used to our new system encouraging blink developers to land test changes along with their blink patches (which then get automatically merged back to WPT). We'll work on improving our docs and guidance to reduce mistakes like this. In the meantime, please feel free to revert anything you feel was landed in error.

We've been talking lots with @jgraham and others about the inevitable conflicts/mistakes like this as we all work to make WPT a first-class part of our engine development process, but we're all optimistic it'll be worth it in the end :-)

/cc @foolip

foolip pushed a commit to whatwg/meta that referenced this issue Feb 10, 2017
@foolip
Copy link
Member

foolip commented Feb 10, 2017

We've anticipated some mishaps of this sort. Just yesterday I noticed an unexpected test change in servo/servo@8b69e73 and it was quickly dealt with, so let's keep learning how to do this together :)

@mikewest, can you write a PR that matches what you'd like to ship, or is it entangled in a bunch of other questions which we have yet to decide on?

@zcorpan
Copy link
Member

zcorpan commented Feb 14, 2017

@mikewest have you considered Gecko's approach (see #2249 (comment))? That doesn't just affect <base> but also new URL('bar', 'data:/,/foo') etc.

@annevk
Copy link
Member

annevk commented Feb 14, 2017

Gecko's approach would require changing the URL Standard and special casing data URLs in it. That does not seem great.

@annevk
Copy link
Member

annevk commented Feb 14, 2017

(And would still leave the hole for javascript URLs, unless we also change the URL Standard for them.)

@zcorpan
Copy link
Member

zcorpan commented Feb 14, 2017

Right. Can you explain what is bad about it? It's not clear to me. :-)

ashkulz pushed a commit to qtwebkit/webkit-mirror that referenced this issue Apr 5, 2020
    Disallow setting base URL to a data or JavaScript URL
    https://bugs.webkit.org/show_bug.cgi?id=207136

    Source/WebCore:

    Reviewed by Brent Fulgham.

    Inspired by <https://bugs.chromium.org/p/chromium/issues/detail?id=679318>.

    Block setting the base URL to a data URL or JavaScript URL as such usage is questionable.
    This makes WebKit match the behavior of Chrome and Firefox and is in the spirit of the
    discussion in <whatwg/html#2249>.

    On Mac and iOS, this restriction is applied only to apps linked against a future SDK to
    avoid breaking shipped apps.

    For all other ports, this restriction is enabled by default.

    Tests: fast/url/relative2.html
           fast/url/segments-from-data-url2.html
           http/tests/security/allowed-base-url-data-url-via-setting.html
           http/tests/security/denied-base-url-data-url.html
           http/tests/security/denied-base-url-javascript-url.html

    * dom/Document.cpp:
    (WebCore::Document::processBaseElement): Condition updating the parsed
    base URL on whether is has an allowed scheme, if restrictions are enabled. Otherwise,
    do what we do now. If the scheme is disallowed then log a message to the console to
    explain this to web developers.
    * html/parser/HTMLPreloadScanner.cpp:
    (WebCore::TokenPreloadScanner::scan): Pass whether to apply restrictons to the base URL
    to updatePredictedBaseURL(). This depends on whether the setting is enabled or not.
    (WebCore::TokenPreloadScanner::updatePredictedBaseURL): Modifed to take a boolean as to
    whether to apply restrictions. If restrictions are not to be applied do what we do now.
    Otherwise, only do what we do now if the scheme for the predicated base URL is allowed.
    * html/parser/HTMLPreloadScanner.h:
    * page/SecurityPolicy.cpp:
    (WebCore::SecurityPolicy::isBaseURLSchemeAllowed): Added.
    * page/SecurityPolicy.h:
    * page/Settings.yaml: Add a setting to toggle restrictions on the base URL scheme.

    Source/WebKit:

    Reviewed by Brent Fulgham.

    Apply base URL restrictions to apps linked to a future WebKit to avoid breaking existing apps.

    * Shared/WebPreferences.yaml:
    * UIProcess/API/Cocoa/WKWebView.mm:
    (shouldRestrictBaseURLSchemes): Added.
    (-[WKWebView _setupPageConfiguration:]): Update settings.
    * UIProcess/Cocoa/VersionChecks.h:

    Source/WebKitLegacy/mac:

    Reviewed by Brent Fulgham.

    Apply base URL restrictions to apps linked to a future WebKit to avoid breaking existing apps.

    * Misc/WebKitVersionChecks.h:
    * WebView/WebView.mm:
    (shouldRestrictBaseURLSchemes): Added.
    (-[WebView _commonInitializationWithFrameName:groupName:]): Update settings.

    Source/WTF:

    Reviewed by Brent Fulgham.

    Add some more macro definitions.

    * wtf/spi/darwin/dyldSPI.h:

    LayoutTests:

    RReviewed by Brent Fulgham.

    Add some tests. Update others to toggle the setting to apply or unapply the new behavior.

    The test denied-base-url-javascript-url.html is derived from the test base-url-javascript.html,
    included in <https://chromium.googlesource.com/chromium/src.git/+/c133efa0b915430701930b76a7cfe35608b9a403>.

    * fast/url/relative-expected.txt:
    * fast/url/relative.html:
    * fast/url/relative2-expected.txt: Copied from LayoutTests/fast/url/relative-expected.txt.
    * fast/url/relative2.html: Copied from LayoutTests/fast/url/relative.html.
    * fast/url/resources/utilities.js:
    (setShouldEllipsizeFileURLPaths): Added. Toggles ellipsizing the path portion of a file URL to simplify matching.
    Otherwise, file URLs could be machine-specific.
    (canonicalizedPathname): Added.
    (segments): Modified to optionally call canonicalizedPathname.
    (canonicalize): Ditto.
    * fast/url/segments-from-data-url-expected.txt:
    * fast/url/segments-from-data-url.html:
    * fast/url/segments-from-data-url2-expected.txt: Copied from LayoutTests/fast/url/segments-from-data-url-expected.txt.
    * fast/url/segments-from-data-url2.html: Copied from LayoutTests/fast/url/segments-from-data-url.html.
    * fetch/fetch-url-serialization-expected.txt:
    * http/tests/plugins/navigation-during-load-embed.html:
    * http/tests/plugins/navigation-during-load.html:
    * http/tests/security/allowed-base-url-data-url-via-setting-expected.txt: Added.
    * http/tests/security/allowed-base-url-data-url-via-setting.html: Added.
    * http/tests/security/denied-base-url-data-url-expected.txt: Added.
    * http/tests/security/denied-base-url-data-url.html: Added.
    * http/tests/security/denied-base-url-javascript-url-expected.txt: Added.
    * http/tests/security/denied-base-url-javascript-url.html: Added.

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@256191 268f45cc-cd09-0410-ab3c-d52691b4dbfc

git-svn-id: http://svn.webkit.org/repository/webkit/branches/safari-609.1.20.0-branch@257015 268f45cc-cd09-0410-ab3c-d52691b4dbfc
ashkulz pushed a commit to qtwebkit/webkit-mirror that referenced this issue Apr 5, 2020
    Disallow setting base URL to a data or JavaScript URL
    https://bugs.webkit.org/show_bug.cgi?id=207136

    Source/WebCore:

    Reviewed by Brent Fulgham.

    Inspired by <https://bugs.chromium.org/p/chromium/issues/detail?id=679318>.

    Block setting the base URL to a data URL or JavaScript URL as such usage is questionable.
    This makes WebKit match the behavior of Chrome and Firefox and is in the spirit of the
    discussion in <whatwg/html#2249>.

    On Mac and iOS, this restriction is applied only to apps linked against a future SDK to
    avoid breaking shipped apps.

    For all other ports, this restriction is enabled by default.

    Tests: fast/url/relative2.html
           fast/url/segments-from-data-url2.html
           http/tests/security/allowed-base-url-data-url-via-setting.html
           http/tests/security/denied-base-url-data-url.html
           http/tests/security/denied-base-url-javascript-url.html

    * dom/Document.cpp:
    (WebCore::Document::processBaseElement): Condition updating the parsed
    base URL on whether is has an allowed scheme, if restrictions are enabled. Otherwise,
    do what we do now. If the scheme is disallowed then log a message to the console to
    explain this to web developers.
    * html/parser/HTMLPreloadScanner.cpp:
    (WebCore::TokenPreloadScanner::scan): Pass whether to apply restrictons to the base URL
    to updatePredictedBaseURL(). This depends on whether the setting is enabled or not.
    (WebCore::TokenPreloadScanner::updatePredictedBaseURL): Modifed to take a boolean as to
    whether to apply restrictions. If restrictions are not to be applied do what we do now.
    Otherwise, only do what we do now if the scheme for the predicated base URL is allowed.
    * html/parser/HTMLPreloadScanner.h:
    * page/SecurityPolicy.cpp:
    (WebCore::SecurityPolicy::isBaseURLSchemeAllowed): Added.
    * page/SecurityPolicy.h:
    * page/Settings.yaml: Add a setting to toggle restrictions on the base URL scheme.

    Source/WebKit:

    Reviewed by Brent Fulgham.

    Apply base URL restrictions to apps linked to a future WebKit to avoid breaking existing apps.

    * Shared/WebPreferences.yaml:
    * UIProcess/API/Cocoa/WKWebView.mm:
    (shouldRestrictBaseURLSchemes): Added.
    (-[WKWebView _setupPageConfiguration:]): Update settings.
    * UIProcess/Cocoa/VersionChecks.h:

    Source/WebKitLegacy/mac:

    Reviewed by Brent Fulgham.

    Apply base URL restrictions to apps linked to a future WebKit to avoid breaking existing apps.

    * Misc/WebKitVersionChecks.h:
    * WebView/WebView.mm:
    (shouldRestrictBaseURLSchemes): Added.
    (-[WebView _commonInitializationWithFrameName:groupName:]): Update settings.

    Source/WTF:

    Reviewed by Brent Fulgham.

    Add some more macro definitions.

    * wtf/spi/darwin/dyldSPI.h:

    LayoutTests:

    RReviewed by Brent Fulgham.

    Add some tests. Update others to toggle the setting to apply or unapply the new behavior.

    The test denied-base-url-javascript-url.html is derived from the test base-url-javascript.html,
    included in <https://chromium.googlesource.com/chromium/src.git/+/c133efa0b915430701930b76a7cfe35608b9a403>.

    * fast/url/relative-expected.txt:
    * fast/url/relative.html:
    * fast/url/relative2-expected.txt: Copied from LayoutTests/fast/url/relative-expected.txt.
    * fast/url/relative2.html: Copied from LayoutTests/fast/url/relative.html.
    * fast/url/resources/utilities.js:
    (setShouldEllipsizeFileURLPaths): Added. Toggles ellipsizing the path portion of a file URL to simplify matching.
    Otherwise, file URLs could be machine-specific.
    (canonicalizedPathname): Added.
    (segments): Modified to optionally call canonicalizedPathname.
    (canonicalize): Ditto.
    * fast/url/segments-from-data-url-expected.txt:
    * fast/url/segments-from-data-url.html:
    * fast/url/segments-from-data-url2-expected.txt: Copied from LayoutTests/fast/url/segments-from-data-url-expected.txt.
    * fast/url/segments-from-data-url2.html: Copied from LayoutTests/fast/url/segments-from-data-url.html.
    * fetch/fetch-url-serialization-expected.txt:
    * http/tests/plugins/navigation-during-load-embed.html:
    * http/tests/plugins/navigation-during-load.html:
    * http/tests/security/allowed-base-url-data-url-via-setting-expected.txt: Added.
    * http/tests/security/allowed-base-url-data-url-via-setting.html: Added.
    * http/tests/security/denied-base-url-data-url-expected.txt: Added.
    * http/tests/security/denied-base-url-data-url.html: Added.
    * http/tests/security/denied-base-url-javascript-url-expected.txt: Added.
    * http/tests/security/denied-base-url-javascript-url.html: Added.

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@256191 268f45cc-cd09-0410-ab3c-d52691b4dbfc

git-svn-id: http://svn.webkit.org/repository/webkit/branches/safari-609.1.20.3-branch@256945 268f45cc-cd09-0410-ab3c-d52691b4dbfc
ashkulz pushed a commit to qtwebkit/webkit-mirror that referenced this issue Apr 5, 2020
    Disallow setting base URL to a data or JavaScript URL
    https://bugs.webkit.org/show_bug.cgi?id=207136

    Source/WebCore:

    Reviewed by Brent Fulgham.

    Inspired by <https://bugs.chromium.org/p/chromium/issues/detail?id=679318>.

    Block setting the base URL to a data URL or JavaScript URL as such usage is questionable.
    This makes WebKit match the behavior of Chrome and Firefox and is in the spirit of the
    discussion in <whatwg/html#2249>.

    On Mac and iOS, this restriction is applied only to apps linked against a future SDK to
    avoid breaking shipped apps.

    For all other ports, this restriction is enabled by default.

    Tests: fast/url/relative2.html
           fast/url/segments-from-data-url2.html
           http/tests/security/allowed-base-url-data-url-via-setting.html
           http/tests/security/denied-base-url-data-url.html
           http/tests/security/denied-base-url-javascript-url.html

    * dom/Document.cpp:
    (WebCore::Document::processBaseElement): Condition updating the parsed
    base URL on whether is has an allowed scheme, if restrictions are enabled. Otherwise,
    do what we do now. If the scheme is disallowed then log a message to the console to
    explain this to web developers.
    * html/parser/HTMLPreloadScanner.cpp:
    (WebCore::TokenPreloadScanner::scan): Pass whether to apply restrictons to the base URL
    to updatePredictedBaseURL(). This depends on whether the setting is enabled or not.
    (WebCore::TokenPreloadScanner::updatePredictedBaseURL): Modifed to take a boolean as to
    whether to apply restrictions. If restrictions are not to be applied do what we do now.
    Otherwise, only do what we do now if the scheme for the predicated base URL is allowed.
    * html/parser/HTMLPreloadScanner.h:
    * page/SecurityPolicy.cpp:
    (WebCore::SecurityPolicy::isBaseURLSchemeAllowed): Added.
    * page/SecurityPolicy.h:
    * page/Settings.yaml: Add a setting to toggle restrictions on the base URL scheme.

    Source/WebKit:

    Reviewed by Brent Fulgham.

    Apply base URL restrictions to apps linked to a future WebKit to avoid breaking existing apps.

    * Shared/WebPreferences.yaml:
    * UIProcess/API/Cocoa/WKWebView.mm:
    (shouldRestrictBaseURLSchemes): Added.
    (-[WKWebView _setupPageConfiguration:]): Update settings.
    * UIProcess/Cocoa/VersionChecks.h:

    Source/WebKitLegacy/mac:

    Reviewed by Brent Fulgham.

    Apply base URL restrictions to apps linked to a future WebKit to avoid breaking existing apps.

    * Misc/WebKitVersionChecks.h:
    * WebView/WebView.mm:
    (shouldRestrictBaseURLSchemes): Added.
    (-[WebView _commonInitializationWithFrameName:groupName:]): Update settings.

    Source/WTF:

    Reviewed by Brent Fulgham.

    Add some more macro definitions.

    * wtf/spi/darwin/dyldSPI.h:

    LayoutTests:

    RReviewed by Brent Fulgham.

    Add some tests. Update others to toggle the setting to apply or unapply the new behavior.

    The test denied-base-url-javascript-url.html is derived from the test base-url-javascript.html,
    included in <https://chromium.googlesource.com/chromium/src.git/+/c133efa0b915430701930b76a7cfe35608b9a403>.

    * fast/url/relative-expected.txt:
    * fast/url/relative.html:
    * fast/url/relative2-expected.txt: Copied from LayoutTests/fast/url/relative-expected.txt.
    * fast/url/relative2.html: Copied from LayoutTests/fast/url/relative.html.
    * fast/url/resources/utilities.js:
    (setShouldEllipsizeFileURLPaths): Added. Toggles ellipsizing the path portion of a file URL to simplify matching.
    Otherwise, file URLs could be machine-specific.
    (canonicalizedPathname): Added.
    (segments): Modified to optionally call canonicalizedPathname.
    (canonicalize): Ditto.
    * fast/url/segments-from-data-url-expected.txt:
    * fast/url/segments-from-data-url.html:
    * fast/url/segments-from-data-url2-expected.txt: Copied from LayoutTests/fast/url/segments-from-data-url-expected.txt.
    * fast/url/segments-from-data-url2.html: Copied from LayoutTests/fast/url/segments-from-data-url.html.
    * fetch/fetch-url-serialization-expected.txt:
    * http/tests/plugins/navigation-during-load-embed.html:
    * http/tests/plugins/navigation-during-load.html:
    * http/tests/security/allowed-base-url-data-url-via-setting-expected.txt: Added.
    * http/tests/security/allowed-base-url-data-url-via-setting.html: Added.
    * http/tests/security/denied-base-url-data-url-expected.txt: Added.
    * http/tests/security/denied-base-url-data-url.html: Added.
    * http/tests/security/denied-base-url-javascript-url-expected.txt: Added.
    * http/tests/security/denied-base-url-javascript-url.html: Added.

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@256191 268f45cc-cd09-0410-ab3c-d52691b4dbfc

git-svn-id: http://svn.webkit.org/repository/webkit/branches/safari-609-branch@256796 268f45cc-cd09-0410-ab3c-d52691b4dbfc
ashkulz pushed a commit to qtwebkit/webkit-mirror that referenced this issue Apr 5, 2020
    Disallow setting base URL to a data or JavaScript URL
    https://bugs.webkit.org/show_bug.cgi?id=207136

    Source/WebCore:

    Reviewed by Brent Fulgham.

    Inspired by <https://bugs.chromium.org/p/chromium/issues/detail?id=679318>.

    Block setting the base URL to a data URL or JavaScript URL as such usage is questionable.
    This makes WebKit match the behavior of Chrome and Firefox and is in the spirit of the
    discussion in <whatwg/html#2249>.

    On Mac and iOS, this restriction is applied only to apps linked against a future SDK to
    avoid breaking shipped apps.

    For all other ports, this restriction is enabled by default.

    Tests: fast/url/relative2.html
           fast/url/segments-from-data-url2.html
           http/tests/security/allowed-base-url-data-url-via-setting.html
           http/tests/security/denied-base-url-data-url.html
           http/tests/security/denied-base-url-javascript-url.html

    * dom/Document.cpp:
    (WebCore::Document::processBaseElement): Condition updating the parsed
    base URL on whether is has an allowed scheme, if restrictions are enabled. Otherwise,
    do what we do now. If the scheme is disallowed then log a message to the console to
    explain this to web developers.
    * html/parser/HTMLPreloadScanner.cpp:
    (WebCore::TokenPreloadScanner::scan): Pass whether to apply restrictons to the base URL
    to updatePredictedBaseURL(). This depends on whether the setting is enabled or not.
    (WebCore::TokenPreloadScanner::updatePredictedBaseURL): Modifed to take a boolean as to
    whether to apply restrictions. If restrictions are not to be applied do what we do now.
    Otherwise, only do what we do now if the scheme for the predicated base URL is allowed.
    * html/parser/HTMLPreloadScanner.h:
    * page/SecurityPolicy.cpp:
    (WebCore::SecurityPolicy::isBaseURLSchemeAllowed): Added.
    * page/SecurityPolicy.h:
    * page/Settings.yaml: Add a setting to toggle restrictions on the base URL scheme.

    Source/WebKit:

    Reviewed by Brent Fulgham.

    Apply base URL restrictions to apps linked to a future WebKit to avoid breaking existing apps.

    * Shared/WebPreferences.yaml:
    * UIProcess/API/Cocoa/WKWebView.mm:
    (shouldRestrictBaseURLSchemes): Added.
    (-[WKWebView _setupPageConfiguration:]): Update settings.
    * UIProcess/Cocoa/VersionChecks.h:

    Source/WebKitLegacy/mac:

    Reviewed by Brent Fulgham.

    Apply base URL restrictions to apps linked to a future WebKit to avoid breaking existing apps.

    * Misc/WebKitVersionChecks.h:
    * WebView/WebView.mm:
    (shouldRestrictBaseURLSchemes): Added.
    (-[WebView _commonInitializationWithFrameName:groupName:]): Update settings.

    Source/WTF:

    Reviewed by Brent Fulgham.

    Add some more macro definitions.

    * wtf/spi/darwin/dyldSPI.h:

    LayoutTests:

    RReviewed by Brent Fulgham.

    Add some tests. Update others to toggle the setting to apply or unapply the new behavior.

    The test denied-base-url-javascript-url.html is derived from the test base-url-javascript.html,
    included in <https://chromium.googlesource.com/chromium/src.git/+/c133efa0b915430701930b76a7cfe35608b9a403>.

    * fast/url/relative-expected.txt:
    * fast/url/relative.html:
    * fast/url/relative2-expected.txt: Copied from LayoutTests/fast/url/relative-expected.txt.
    * fast/url/relative2.html: Copied from LayoutTests/fast/url/relative.html.
    * fast/url/resources/utilities.js:
    (setShouldEllipsizeFileURLPaths): Added. Toggles ellipsizing the path portion of a file URL to simplify matching.
    Otherwise, file URLs could be machine-specific.
    (canonicalizedPathname): Added.
    (segments): Modified to optionally call canonicalizedPathname.
    (canonicalize): Ditto.
    * fast/url/segments-from-data-url-expected.txt:
    * fast/url/segments-from-data-url.html:
    * fast/url/segments-from-data-url2-expected.txt: Copied from LayoutTests/fast/url/segments-from-data-url-expected.txt.
    * fast/url/segments-from-data-url2.html: Copied from LayoutTests/fast/url/segments-from-data-url.html.
    * fetch/fetch-url-serialization-expected.txt:
    * http/tests/plugins/navigation-during-load-embed.html:
    * http/tests/plugins/navigation-during-load.html:
    * http/tests/security/allowed-base-url-data-url-via-setting-expected.txt: Added.
    * http/tests/security/allowed-base-url-data-url-via-setting.html: Added.
    * http/tests/security/denied-base-url-data-url-expected.txt: Added.
    * http/tests/security/denied-base-url-data-url.html: Added.
    * http/tests/security/denied-base-url-javascript-url-expected.txt: Added.
    * http/tests/security/denied-base-url-javascript-url.html: Added.

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@256191 268f45cc-cd09-0410-ab3c-d52691b4dbfc

git-svn-id: http://svn.webkit.org/repository/webkit/branches/safari-609-branch@256896 268f45cc-cd09-0410-ab3c-d52691b4dbfc
JonWBedard pushed a commit to WebKit/WebKit that referenced this issue Dec 14, 2020
    Disallow setting base URL to a data or JavaScript URL
    https://bugs.webkit.org/show_bug.cgi?id=207136

    Source/WebCore:

    Reviewed by Brent Fulgham.

    Inspired by <https://bugs.chromium.org/p/chromium/issues/detail?id=679318>.

    Block setting the base URL to a data URL or JavaScript URL as such usage is questionable.
    This makes WebKit match the behavior of Chrome and Firefox and is in the spirit of the
    discussion in <whatwg/html#2249>.

    On Mac and iOS, this restriction is applied only to apps linked against a future SDK to
    avoid breaking shipped apps.

    For all other ports, this restriction is enabled by default.

    Tests: fast/url/relative2.html
           fast/url/segments-from-data-url2.html
           http/tests/security/allowed-base-url-data-url-via-setting.html
           http/tests/security/denied-base-url-data-url.html
           http/tests/security/denied-base-url-javascript-url.html

    * dom/Document.cpp:
    (WebCore::Document::processBaseElement): Condition updating the parsed
    base URL on whether is has an allowed scheme, if restrictions are enabled. Otherwise,
    do what we do now. If the scheme is disallowed then log a message to the console to
    explain this to web developers.
    * html/parser/HTMLPreloadScanner.cpp:
    (WebCore::TokenPreloadScanner::scan): Pass whether to apply restrictons to the base URL
    to updatePredictedBaseURL(). This depends on whether the setting is enabled or not.
    (WebCore::TokenPreloadScanner::updatePredictedBaseURL): Modifed to take a boolean as to
    whether to apply restrictions. If restrictions are not to be applied do what we do now.
    Otherwise, only do what we do now if the scheme for the predicated base URL is allowed.
    * html/parser/HTMLPreloadScanner.h:
    * page/SecurityPolicy.cpp:
    (WebCore::SecurityPolicy::isBaseURLSchemeAllowed): Added.
    * page/SecurityPolicy.h:
    * page/Settings.yaml: Add a setting to toggle restrictions on the base URL scheme.

    Source/WebKit:

    Reviewed by Brent Fulgham.

    Apply base URL restrictions to apps linked to a future WebKit to avoid breaking existing apps.

    * Shared/WebPreferences.yaml:
    * UIProcess/API/Cocoa/WKWebView.mm:
    (shouldRestrictBaseURLSchemes): Added.
    (-[WKWebView _setupPageConfiguration:]): Update settings.
    * UIProcess/Cocoa/VersionChecks.h:

    Source/WebKitLegacy/mac:

    Reviewed by Brent Fulgham.

    Apply base URL restrictions to apps linked to a future WebKit to avoid breaking existing apps.

    * Misc/WebKitVersionChecks.h:
    * WebView/WebView.mm:
    (shouldRestrictBaseURLSchemes): Added.
    (-[WebView _commonInitializationWithFrameName:groupName:]): Update settings.

    Source/WTF:

    Reviewed by Brent Fulgham.

    Add some more macro definitions.

    * wtf/spi/darwin/dyldSPI.h:

    LayoutTests:

    RReviewed by Brent Fulgham.

    Add some tests. Update others to toggle the setting to apply or unapply the new behavior.

    The test denied-base-url-javascript-url.html is derived from the test base-url-javascript.html,
    included in <https://chromium.googlesource.com/chromium/src.git/+/c133efa0b915430701930b76a7cfe35608b9a403>.

    * fast/url/relative-expected.txt:
    * fast/url/relative.html:
    * fast/url/relative2-expected.txt: Copied from LayoutTests/fast/url/relative-expected.txt.
    * fast/url/relative2.html: Copied from LayoutTests/fast/url/relative.html.
    * fast/url/resources/utilities.js:
    (setShouldEllipsizeFileURLPaths): Added. Toggles ellipsizing the path portion of a file URL to simplify matching.
    Otherwise, file URLs could be machine-specific.
    (canonicalizedPathname): Added.
    (segments): Modified to optionally call canonicalizedPathname.
    (canonicalize): Ditto.
    * fast/url/segments-from-data-url-expected.txt:
    * fast/url/segments-from-data-url.html:
    * fast/url/segments-from-data-url2-expected.txt: Copied from LayoutTests/fast/url/segments-from-data-url-expected.txt.
    * fast/url/segments-from-data-url2.html: Copied from LayoutTests/fast/url/segments-from-data-url.html.
    * fetch/fetch-url-serialization-expected.txt:
    * http/tests/plugins/navigation-during-load-embed.html:
    * http/tests/plugins/navigation-during-load.html:
    * http/tests/security/allowed-base-url-data-url-via-setting-expected.txt: Added.
    * http/tests/security/allowed-base-url-data-url-via-setting.html: Added.
    * http/tests/security/denied-base-url-data-url-expected.txt: Added.
    * http/tests/security/denied-base-url-data-url.html: Added.
    * http/tests/security/denied-base-url-javascript-url-expected.txt: Added.
    * http/tests/security/denied-base-url-javascript-url.html: Added.

    Identifier: 220473@main
    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@256191 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Identifier: 218903.363@safari-609-branch
git-svn-id: https://svn.webkit.org/repository/webkit/branches/safari-609-branch@256796 268f45cc-cd09-0410-ab3c-d52691b4dbfc
JonWBedard pushed a commit to WebKit/WebKit that referenced this issue Dec 14, 2020
    Disallow setting base URL to a data or JavaScript URL
    https://bugs.webkit.org/show_bug.cgi?id=207136

    Source/WebCore:

    Reviewed by Brent Fulgham.

    Inspired by <https://bugs.chromium.org/p/chromium/issues/detail?id=679318>.

    Block setting the base URL to a data URL or JavaScript URL as such usage is questionable.
    This makes WebKit match the behavior of Chrome and Firefox and is in the spirit of the
    discussion in <whatwg/html#2249>.

    On Mac and iOS, this restriction is applied only to apps linked against a future SDK to
    avoid breaking shipped apps.

    For all other ports, this restriction is enabled by default.

    Tests: fast/url/relative2.html
           fast/url/segments-from-data-url2.html
           http/tests/security/allowed-base-url-data-url-via-setting.html
           http/tests/security/denied-base-url-data-url.html
           http/tests/security/denied-base-url-javascript-url.html

    * dom/Document.cpp:
    (WebCore::Document::processBaseElement): Condition updating the parsed
    base URL on whether is has an allowed scheme, if restrictions are enabled. Otherwise,
    do what we do now. If the scheme is disallowed then log a message to the console to
    explain this to web developers.
    * html/parser/HTMLPreloadScanner.cpp:
    (WebCore::TokenPreloadScanner::scan): Pass whether to apply restrictons to the base URL
    to updatePredictedBaseURL(). This depends on whether the setting is enabled or not.
    (WebCore::TokenPreloadScanner::updatePredictedBaseURL): Modifed to take a boolean as to
    whether to apply restrictions. If restrictions are not to be applied do what we do now.
    Otherwise, only do what we do now if the scheme for the predicated base URL is allowed.
    * html/parser/HTMLPreloadScanner.h:
    * page/SecurityPolicy.cpp:
    (WebCore::SecurityPolicy::isBaseURLSchemeAllowed): Added.
    * page/SecurityPolicy.h:
    * page/Settings.yaml: Add a setting to toggle restrictions on the base URL scheme.

    Source/WebKit:

    Reviewed by Brent Fulgham.

    Apply base URL restrictions to apps linked to a future WebKit to avoid breaking existing apps.

    * Shared/WebPreferences.yaml:
    * UIProcess/API/Cocoa/WKWebView.mm:
    (shouldRestrictBaseURLSchemes): Added.
    (-[WKWebView _setupPageConfiguration:]): Update settings.
    * UIProcess/Cocoa/VersionChecks.h:

    Source/WebKitLegacy/mac:

    Reviewed by Brent Fulgham.

    Apply base URL restrictions to apps linked to a future WebKit to avoid breaking existing apps.

    * Misc/WebKitVersionChecks.h:
    * WebView/WebView.mm:
    (shouldRestrictBaseURLSchemes): Added.
    (-[WebView _commonInitializationWithFrameName:groupName:]): Update settings.

    Source/WTF:

    Reviewed by Brent Fulgham.

    Add some more macro definitions.

    * wtf/spi/darwin/dyldSPI.h:

    LayoutTests:

    RReviewed by Brent Fulgham.

    Add some tests. Update others to toggle the setting to apply or unapply the new behavior.

    The test denied-base-url-javascript-url.html is derived from the test base-url-javascript.html,
    included in <https://chromium.googlesource.com/chromium/src.git/+/c133efa0b915430701930b76a7cfe35608b9a403>.

    * fast/url/relative-expected.txt:
    * fast/url/relative.html:
    * fast/url/relative2-expected.txt: Copied from LayoutTests/fast/url/relative-expected.txt.
    * fast/url/relative2.html: Copied from LayoutTests/fast/url/relative.html.
    * fast/url/resources/utilities.js:
    (setShouldEllipsizeFileURLPaths): Added. Toggles ellipsizing the path portion of a file URL to simplify matching.
    Otherwise, file URLs could be machine-specific.
    (canonicalizedPathname): Added.
    (segments): Modified to optionally call canonicalizedPathname.
    (canonicalize): Ditto.
    * fast/url/segments-from-data-url-expected.txt:
    * fast/url/segments-from-data-url.html:
    * fast/url/segments-from-data-url2-expected.txt: Copied from LayoutTests/fast/url/segments-from-data-url-expected.txt.
    * fast/url/segments-from-data-url2.html: Copied from LayoutTests/fast/url/segments-from-data-url.html.
    * fetch/fetch-url-serialization-expected.txt:
    * http/tests/plugins/navigation-during-load-embed.html:
    * http/tests/plugins/navigation-during-load.html:
    * http/tests/security/allowed-base-url-data-url-via-setting-expected.txt: Added.
    * http/tests/security/allowed-base-url-data-url-via-setting.html: Added.
    * http/tests/security/denied-base-url-data-url-expected.txt: Added.
    * http/tests/security/denied-base-url-data-url.html: Added.
    * http/tests/security/denied-base-url-javascript-url-expected.txt: Added.
    * http/tests/security/denied-base-url-javascript-url.html: Added.

    Identifier: 220473@main
    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@256191 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Identifier: 218903.387@safari-609-branch
git-svn-id: https://svn.webkit.org/repository/webkit/branches/safari-609-branch@256896 268f45cc-cd09-0410-ab3c-d52691b4dbfc
JonWBedard pushed a commit to WebKit/WebKit that referenced this issue Jan 6, 2021
    Disallow setting base URL to a data or JavaScript URL
    https://bugs.webkit.org/show_bug.cgi?id=207136

    Source/WebCore:

    Reviewed by Brent Fulgham.

    Inspired by <https://bugs.chromium.org/p/chromium/issues/detail?id=679318>.

    Block setting the base URL to a data URL or JavaScript URL as such usage is questionable.
    This makes WebKit match the behavior of Chrome and Firefox and is in the spirit of the
    discussion in <whatwg/html#2249>.

    On Mac and iOS, this restriction is applied only to apps linked against a future SDK to
    avoid breaking shipped apps.

    For all other ports, this restriction is enabled by default.

    Tests: fast/url/relative2.html
           fast/url/segments-from-data-url2.html
           http/tests/security/allowed-base-url-data-url-via-setting.html
           http/tests/security/denied-base-url-data-url.html
           http/tests/security/denied-base-url-javascript-url.html

    * dom/Document.cpp:
    (WebCore::Document::processBaseElement): Condition updating the parsed
    base URL on whether is has an allowed scheme, if restrictions are enabled. Otherwise,
    do what we do now. If the scheme is disallowed then log a message to the console to
    explain this to web developers.
    * html/parser/HTMLPreloadScanner.cpp:
    (WebCore::TokenPreloadScanner::scan): Pass whether to apply restrictons to the base URL
    to updatePredictedBaseURL(). This depends on whether the setting is enabled or not.
    (WebCore::TokenPreloadScanner::updatePredictedBaseURL): Modifed to take a boolean as to
    whether to apply restrictions. If restrictions are not to be applied do what we do now.
    Otherwise, only do what we do now if the scheme for the predicated base URL is allowed.
    * html/parser/HTMLPreloadScanner.h:
    * page/SecurityPolicy.cpp:
    (WebCore::SecurityPolicy::isBaseURLSchemeAllowed): Added.
    * page/SecurityPolicy.h:
    * page/Settings.yaml: Add a setting to toggle restrictions on the base URL scheme.

    Source/WebKit:

    Reviewed by Brent Fulgham.

    Apply base URL restrictions to apps linked to a future WebKit to avoid breaking existing apps.

    * Shared/WebPreferences.yaml:
    * UIProcess/API/Cocoa/WKWebView.mm:
    (shouldRestrictBaseURLSchemes): Added.
    (-[WKWebView _setupPageConfiguration:]): Update settings.
    * UIProcess/Cocoa/VersionChecks.h:

    Source/WebKitLegacy/mac:

    Reviewed by Brent Fulgham.

    Apply base URL restrictions to apps linked to a future WebKit to avoid breaking existing apps.

    * Misc/WebKitVersionChecks.h:
    * WebView/WebView.mm:
    (shouldRestrictBaseURLSchemes): Added.
    (-[WebView _commonInitializationWithFrameName:groupName:]): Update settings.

    Source/WTF:

    Reviewed by Brent Fulgham.

    Add some more macro definitions.

    * wtf/spi/darwin/dyldSPI.h:

    LayoutTests:

    RReviewed by Brent Fulgham.

    Add some tests. Update others to toggle the setting to apply or unapply the new behavior.

    The test denied-base-url-javascript-url.html is derived from the test base-url-javascript.html,
    included in <https://chromium.googlesource.com/chromium/src.git/+/c133efa0b915430701930b76a7cfe35608b9a403>.

    * fast/url/relative-expected.txt:
    * fast/url/relative.html:
    * fast/url/relative2-expected.txt: Copied from LayoutTests/fast/url/relative-expected.txt.
    * fast/url/relative2.html: Copied from LayoutTests/fast/url/relative.html.
    * fast/url/resources/utilities.js:
    (setShouldEllipsizeFileURLPaths): Added. Toggles ellipsizing the path portion of a file URL to simplify matching.
    Otherwise, file URLs could be machine-specific.
    (canonicalizedPathname): Added.
    (segments): Modified to optionally call canonicalizedPathname.
    (canonicalize): Ditto.
    * fast/url/segments-from-data-url-expected.txt:
    * fast/url/segments-from-data-url.html:
    * fast/url/segments-from-data-url2-expected.txt: Copied from LayoutTests/fast/url/segments-from-data-url-expected.txt.
    * fast/url/segments-from-data-url2.html: Copied from LayoutTests/fast/url/segments-from-data-url.html.
    * fetch/fetch-url-serialization-expected.txt:
    * http/tests/plugins/navigation-during-load-embed.html:
    * http/tests/plugins/navigation-during-load.html:
    * http/tests/security/allowed-base-url-data-url-via-setting-expected.txt: Added.
    * http/tests/security/allowed-base-url-data-url-via-setting.html: Added.
    * http/tests/security/denied-base-url-data-url-expected.txt: Added.
    * http/tests/security/denied-base-url-data-url.html: Added.
    * http/tests/security/denied-base-url-javascript-url-expected.txt: Added.
    * http/tests/security/denied-base-url-javascript-url.html: Added.

    Canonical link: https://commits.webkit.org/220473@main
    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@256191 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Canonical link: https://commits.webkit.org/218903.363@safari-609-branch
git-svn-id: https://svn.webkit.org/repository/webkit/branches/safari-609-branch@256796 268f45cc-cd09-0410-ab3c-d52691b4dbfc
JonWBedard pushed a commit to WebKit/WebKit that referenced this issue Jan 6, 2021
    Disallow setting base URL to a data or JavaScript URL
    https://bugs.webkit.org/show_bug.cgi?id=207136

    Source/WebCore:

    Reviewed by Brent Fulgham.

    Inspired by <https://bugs.chromium.org/p/chromium/issues/detail?id=679318>.

    Block setting the base URL to a data URL or JavaScript URL as such usage is questionable.
    This makes WebKit match the behavior of Chrome and Firefox and is in the spirit of the
    discussion in <whatwg/html#2249>.

    On Mac and iOS, this restriction is applied only to apps linked against a future SDK to
    avoid breaking shipped apps.

    For all other ports, this restriction is enabled by default.

    Tests: fast/url/relative2.html
           fast/url/segments-from-data-url2.html
           http/tests/security/allowed-base-url-data-url-via-setting.html
           http/tests/security/denied-base-url-data-url.html
           http/tests/security/denied-base-url-javascript-url.html

    * dom/Document.cpp:
    (WebCore::Document::processBaseElement): Condition updating the parsed
    base URL on whether is has an allowed scheme, if restrictions are enabled. Otherwise,
    do what we do now. If the scheme is disallowed then log a message to the console to
    explain this to web developers.
    * html/parser/HTMLPreloadScanner.cpp:
    (WebCore::TokenPreloadScanner::scan): Pass whether to apply restrictons to the base URL
    to updatePredictedBaseURL(). This depends on whether the setting is enabled or not.
    (WebCore::TokenPreloadScanner::updatePredictedBaseURL): Modifed to take a boolean as to
    whether to apply restrictions. If restrictions are not to be applied do what we do now.
    Otherwise, only do what we do now if the scheme for the predicated base URL is allowed.
    * html/parser/HTMLPreloadScanner.h:
    * page/SecurityPolicy.cpp:
    (WebCore::SecurityPolicy::isBaseURLSchemeAllowed): Added.
    * page/SecurityPolicy.h:
    * page/Settings.yaml: Add a setting to toggle restrictions on the base URL scheme.

    Source/WebKit:

    Reviewed by Brent Fulgham.

    Apply base URL restrictions to apps linked to a future WebKit to avoid breaking existing apps.

    * Shared/WebPreferences.yaml:
    * UIProcess/API/Cocoa/WKWebView.mm:
    (shouldRestrictBaseURLSchemes): Added.
    (-[WKWebView _setupPageConfiguration:]): Update settings.
    * UIProcess/Cocoa/VersionChecks.h:

    Source/WebKitLegacy/mac:

    Reviewed by Brent Fulgham.

    Apply base URL restrictions to apps linked to a future WebKit to avoid breaking existing apps.

    * Misc/WebKitVersionChecks.h:
    * WebView/WebView.mm:
    (shouldRestrictBaseURLSchemes): Added.
    (-[WebView _commonInitializationWithFrameName:groupName:]): Update settings.

    Source/WTF:

    Reviewed by Brent Fulgham.

    Add some more macro definitions.

    * wtf/spi/darwin/dyldSPI.h:

    LayoutTests:

    RReviewed by Brent Fulgham.

    Add some tests. Update others to toggle the setting to apply or unapply the new behavior.

    The test denied-base-url-javascript-url.html is derived from the test base-url-javascript.html,
    included in <https://chromium.googlesource.com/chromium/src.git/+/c133efa0b915430701930b76a7cfe35608b9a403>.

    * fast/url/relative-expected.txt:
    * fast/url/relative.html:
    * fast/url/relative2-expected.txt: Copied from LayoutTests/fast/url/relative-expected.txt.
    * fast/url/relative2.html: Copied from LayoutTests/fast/url/relative.html.
    * fast/url/resources/utilities.js:
    (setShouldEllipsizeFileURLPaths): Added. Toggles ellipsizing the path portion of a file URL to simplify matching.
    Otherwise, file URLs could be machine-specific.
    (canonicalizedPathname): Added.
    (segments): Modified to optionally call canonicalizedPathname.
    (canonicalize): Ditto.
    * fast/url/segments-from-data-url-expected.txt:
    * fast/url/segments-from-data-url.html:
    * fast/url/segments-from-data-url2-expected.txt: Copied from LayoutTests/fast/url/segments-from-data-url-expected.txt.
    * fast/url/segments-from-data-url2.html: Copied from LayoutTests/fast/url/segments-from-data-url.html.
    * fetch/fetch-url-serialization-expected.txt:
    * http/tests/plugins/navigation-during-load-embed.html:
    * http/tests/plugins/navigation-during-load.html:
    * http/tests/security/allowed-base-url-data-url-via-setting-expected.txt: Added.
    * http/tests/security/allowed-base-url-data-url-via-setting.html: Added.
    * http/tests/security/denied-base-url-data-url-expected.txt: Added.
    * http/tests/security/denied-base-url-data-url.html: Added.
    * http/tests/security/denied-base-url-javascript-url-expected.txt: Added.
    * http/tests/security/denied-base-url-javascript-url.html: Added.

    Canonical link: https://commits.webkit.org/220473@main
    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@256191 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Canonical link: https://commits.webkit.org/218903.387@safari-609-branch
git-svn-id: https://svn.webkit.org/repository/webkit/branches/safari-609-branch@256896 268f45cc-cd09-0410-ab3c-d52691b4dbfc
JonWBedard pushed a commit to WebKit/WebKit that referenced this issue Jan 6, 2021
    Disallow setting base URL to a data or JavaScript URL
    https://bugs.webkit.org/show_bug.cgi?id=207136

    Source/WebCore:

    Reviewed by Brent Fulgham.

    Inspired by <https://bugs.chromium.org/p/chromium/issues/detail?id=679318>.

    Block setting the base URL to a data URL or JavaScript URL as such usage is questionable.
    This makes WebKit match the behavior of Chrome and Firefox and is in the spirit of the
    discussion in <whatwg/html#2249>.

    On Mac and iOS, this restriction is applied only to apps linked against a future SDK to
    avoid breaking shipped apps.

    For all other ports, this restriction is enabled by default.

    Tests: fast/url/relative2.html
           fast/url/segments-from-data-url2.html
           http/tests/security/allowed-base-url-data-url-via-setting.html
           http/tests/security/denied-base-url-data-url.html
           http/tests/security/denied-base-url-javascript-url.html

    * dom/Document.cpp:
    (WebCore::Document::processBaseElement): Condition updating the parsed
    base URL on whether is has an allowed scheme, if restrictions are enabled. Otherwise,
    do what we do now. If the scheme is disallowed then log a message to the console to
    explain this to web developers.
    * html/parser/HTMLPreloadScanner.cpp:
    (WebCore::TokenPreloadScanner::scan): Pass whether to apply restrictons to the base URL
    to updatePredictedBaseURL(). This depends on whether the setting is enabled or not.
    (WebCore::TokenPreloadScanner::updatePredictedBaseURL): Modifed to take a boolean as to
    whether to apply restrictions. If restrictions are not to be applied do what we do now.
    Otherwise, only do what we do now if the scheme for the predicated base URL is allowed.
    * html/parser/HTMLPreloadScanner.h:
    * page/SecurityPolicy.cpp:
    (WebCore::SecurityPolicy::isBaseURLSchemeAllowed): Added.
    * page/SecurityPolicy.h:
    * page/Settings.yaml: Add a setting to toggle restrictions on the base URL scheme.

    Source/WebKit:

    Reviewed by Brent Fulgham.

    Apply base URL restrictions to apps linked to a future WebKit to avoid breaking existing apps.

    * Shared/WebPreferences.yaml:
    * UIProcess/API/Cocoa/WKWebView.mm:
    (shouldRestrictBaseURLSchemes): Added.
    (-[WKWebView _setupPageConfiguration:]): Update settings.
    * UIProcess/Cocoa/VersionChecks.h:

    Source/WebKitLegacy/mac:

    Reviewed by Brent Fulgham.

    Apply base URL restrictions to apps linked to a future WebKit to avoid breaking existing apps.

    * Misc/WebKitVersionChecks.h:
    * WebView/WebView.mm:
    (shouldRestrictBaseURLSchemes): Added.
    (-[WebView _commonInitializationWithFrameName:groupName:]): Update settings.

    Source/WTF:

    Reviewed by Brent Fulgham.

    Add some more macro definitions.

    * wtf/spi/darwin/dyldSPI.h:

    LayoutTests:

    RReviewed by Brent Fulgham.

    Add some tests. Update others to toggle the setting to apply or unapply the new behavior.

    The test denied-base-url-javascript-url.html is derived from the test base-url-javascript.html,
    included in <https://chromium.googlesource.com/chromium/src.git/+/c133efa0b915430701930b76a7cfe35608b9a403>.

    * fast/url/relative-expected.txt:
    * fast/url/relative.html:
    * fast/url/relative2-expected.txt: Copied from LayoutTests/fast/url/relative-expected.txt.
    * fast/url/relative2.html: Copied from LayoutTests/fast/url/relative.html.
    * fast/url/resources/utilities.js:
    (setShouldEllipsizeFileURLPaths): Added. Toggles ellipsizing the path portion of a file URL to simplify matching.
    Otherwise, file URLs could be machine-specific.
    (canonicalizedPathname): Added.
    (segments): Modified to optionally call canonicalizedPathname.
    (canonicalize): Ditto.
    * fast/url/segments-from-data-url-expected.txt:
    * fast/url/segments-from-data-url.html:
    * fast/url/segments-from-data-url2-expected.txt: Copied from LayoutTests/fast/url/segments-from-data-url-expected.txt.
    * fast/url/segments-from-data-url2.html: Copied from LayoutTests/fast/url/segments-from-data-url.html.
    * fetch/fetch-url-serialization-expected.txt:
    * http/tests/plugins/navigation-during-load-embed.html:
    * http/tests/plugins/navigation-during-load.html:
    * http/tests/security/allowed-base-url-data-url-via-setting-expected.txt: Added.
    * http/tests/security/allowed-base-url-data-url-via-setting.html: Added.
    * http/tests/security/denied-base-url-data-url-expected.txt: Added.
    * http/tests/security/denied-base-url-data-url.html: Added.
    * http/tests/security/denied-base-url-javascript-url-expected.txt: Added.
    * http/tests/security/denied-base-url-javascript-url.html: Added.

    Canonical link: https://commits.webkit.org/220473@main
    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@256191 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Canonical link: https://commits.webkit.org/218903.381@safari-609.1.20.0-branch
git-svn-id: https://svn.webkit.org/repository/webkit/branches/safari-609.1.20.0-branch@257015 268f45cc-cd09-0410-ab3c-d52691b4dbfc
JonWBedard pushed a commit to WebKit/WebKit that referenced this issue Jan 6, 2021
    Disallow setting base URL to a data or JavaScript URL
    https://bugs.webkit.org/show_bug.cgi?id=207136

    Source/WebCore:

    Reviewed by Brent Fulgham.

    Inspired by <https://bugs.chromium.org/p/chromium/issues/detail?id=679318>.

    Block setting the base URL to a data URL or JavaScript URL as such usage is questionable.
    This makes WebKit match the behavior of Chrome and Firefox and is in the spirit of the
    discussion in <whatwg/html#2249>.

    On Mac and iOS, this restriction is applied only to apps linked against a future SDK to
    avoid breaking shipped apps.

    For all other ports, this restriction is enabled by default.

    Tests: fast/url/relative2.html
           fast/url/segments-from-data-url2.html
           http/tests/security/allowed-base-url-data-url-via-setting.html
           http/tests/security/denied-base-url-data-url.html
           http/tests/security/denied-base-url-javascript-url.html

    * dom/Document.cpp:
    (WebCore::Document::processBaseElement): Condition updating the parsed
    base URL on whether is has an allowed scheme, if restrictions are enabled. Otherwise,
    do what we do now. If the scheme is disallowed then log a message to the console to
    explain this to web developers.
    * html/parser/HTMLPreloadScanner.cpp:
    (WebCore::TokenPreloadScanner::scan): Pass whether to apply restrictons to the base URL
    to updatePredictedBaseURL(). This depends on whether the setting is enabled or not.
    (WebCore::TokenPreloadScanner::updatePredictedBaseURL): Modifed to take a boolean as to
    whether to apply restrictions. If restrictions are not to be applied do what we do now.
    Otherwise, only do what we do now if the scheme for the predicated base URL is allowed.
    * html/parser/HTMLPreloadScanner.h:
    * page/SecurityPolicy.cpp:
    (WebCore::SecurityPolicy::isBaseURLSchemeAllowed): Added.
    * page/SecurityPolicy.h:
    * page/Settings.yaml: Add a setting to toggle restrictions on the base URL scheme.

    Source/WebKit:

    Reviewed by Brent Fulgham.

    Apply base URL restrictions to apps linked to a future WebKit to avoid breaking existing apps.

    * Shared/WebPreferences.yaml:
    * UIProcess/API/Cocoa/WKWebView.mm:
    (shouldRestrictBaseURLSchemes): Added.
    (-[WKWebView _setupPageConfiguration:]): Update settings.
    * UIProcess/Cocoa/VersionChecks.h:

    Source/WebKitLegacy/mac:

    Reviewed by Brent Fulgham.

    Apply base URL restrictions to apps linked to a future WebKit to avoid breaking existing apps.

    * Misc/WebKitVersionChecks.h:
    * WebView/WebView.mm:
    (shouldRestrictBaseURLSchemes): Added.
    (-[WebView _commonInitializationWithFrameName:groupName:]): Update settings.

    Source/WTF:

    Reviewed by Brent Fulgham.

    Add some more macro definitions.

    * wtf/spi/darwin/dyldSPI.h:

    LayoutTests:

    RReviewed by Brent Fulgham.

    Add some tests. Update others to toggle the setting to apply or unapply the new behavior.

    The test denied-base-url-javascript-url.html is derived from the test base-url-javascript.html,
    included in <https://chromium.googlesource.com/chromium/src.git/+/c133efa0b915430701930b76a7cfe35608b9a403>.

    * fast/url/relative-expected.txt:
    * fast/url/relative.html:
    * fast/url/relative2-expected.txt: Copied from LayoutTests/fast/url/relative-expected.txt.
    * fast/url/relative2.html: Copied from LayoutTests/fast/url/relative.html.
    * fast/url/resources/utilities.js:
    (setShouldEllipsizeFileURLPaths): Added. Toggles ellipsizing the path portion of a file URL to simplify matching.
    Otherwise, file URLs could be machine-specific.
    (canonicalizedPathname): Added.
    (segments): Modified to optionally call canonicalizedPathname.
    (canonicalize): Ditto.
    * fast/url/segments-from-data-url-expected.txt:
    * fast/url/segments-from-data-url.html:
    * fast/url/segments-from-data-url2-expected.txt: Copied from LayoutTests/fast/url/segments-from-data-url-expected.txt.
    * fast/url/segments-from-data-url2.html: Copied from LayoutTests/fast/url/segments-from-data-url.html.
    * fetch/fetch-url-serialization-expected.txt:
    * http/tests/plugins/navigation-during-load-embed.html:
    * http/tests/plugins/navigation-during-load.html:
    * http/tests/security/allowed-base-url-data-url-via-setting-expected.txt: Added.
    * http/tests/security/allowed-base-url-data-url-via-setting.html: Added.
    * http/tests/security/denied-base-url-data-url-expected.txt: Added.
    * http/tests/security/denied-base-url-data-url.html: Added.
    * http/tests/security/denied-base-url-javascript-url-expected.txt: Added.
    * http/tests/security/denied-base-url-javascript-url.html: Added.

    Canonical link: https://commits.webkit.org/220473@main
    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@256191 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Canonical link: https://commits.webkit.org/218903.363@safari-609.1.20.1-branch
git-svn-id: https://svn.webkit.org/repository/webkit/branches/safari-609.1.20.1-branch@256969 268f45cc-cd09-0410-ab3c-d52691b4dbfc
JonWBedard pushed a commit to WebKit/WebKit that referenced this issue Jan 6, 2021
    Disallow setting base URL to a data or JavaScript URL
    https://bugs.webkit.org/show_bug.cgi?id=207136

    Source/WebCore:

    Reviewed by Brent Fulgham.

    Inspired by <https://bugs.chromium.org/p/chromium/issues/detail?id=679318>.

    Block setting the base URL to a data URL or JavaScript URL as such usage is questionable.
    This makes WebKit match the behavior of Chrome and Firefox and is in the spirit of the
    discussion in <whatwg/html#2249>.

    On Mac and iOS, this restriction is applied only to apps linked against a future SDK to
    avoid breaking shipped apps.

    For all other ports, this restriction is enabled by default.

    Tests: fast/url/relative2.html
           fast/url/segments-from-data-url2.html
           http/tests/security/allowed-base-url-data-url-via-setting.html
           http/tests/security/denied-base-url-data-url.html
           http/tests/security/denied-base-url-javascript-url.html

    * dom/Document.cpp:
    (WebCore::Document::processBaseElement): Condition updating the parsed
    base URL on whether is has an allowed scheme, if restrictions are enabled. Otherwise,
    do what we do now. If the scheme is disallowed then log a message to the console to
    explain this to web developers.
    * html/parser/HTMLPreloadScanner.cpp:
    (WebCore::TokenPreloadScanner::scan): Pass whether to apply restrictons to the base URL
    to updatePredictedBaseURL(). This depends on whether the setting is enabled or not.
    (WebCore::TokenPreloadScanner::updatePredictedBaseURL): Modifed to take a boolean as to
    whether to apply restrictions. If restrictions are not to be applied do what we do now.
    Otherwise, only do what we do now if the scheme for the predicated base URL is allowed.
    * html/parser/HTMLPreloadScanner.h:
    * page/SecurityPolicy.cpp:
    (WebCore::SecurityPolicy::isBaseURLSchemeAllowed): Added.
    * page/SecurityPolicy.h:
    * page/Settings.yaml: Add a setting to toggle restrictions on the base URL scheme.

    Source/WebKit:

    Reviewed by Brent Fulgham.

    Apply base URL restrictions to apps linked to a future WebKit to avoid breaking existing apps.

    * Shared/WebPreferences.yaml:
    * UIProcess/API/Cocoa/WKWebView.mm:
    (shouldRestrictBaseURLSchemes): Added.
    (-[WKWebView _setupPageConfiguration:]): Update settings.
    * UIProcess/Cocoa/VersionChecks.h:

    Source/WebKitLegacy/mac:

    Reviewed by Brent Fulgham.

    Apply base URL restrictions to apps linked to a future WebKit to avoid breaking existing apps.

    * Misc/WebKitVersionChecks.h:
    * WebView/WebView.mm:
    (shouldRestrictBaseURLSchemes): Added.
    (-[WebView _commonInitializationWithFrameName:groupName:]): Update settings.

    Source/WTF:

    Reviewed by Brent Fulgham.

    Add some more macro definitions.

    * wtf/spi/darwin/dyldSPI.h:

    LayoutTests:

    RReviewed by Brent Fulgham.

    Add some tests. Update others to toggle the setting to apply or unapply the new behavior.

    The test denied-base-url-javascript-url.html is derived from the test base-url-javascript.html,
    included in <https://chromium.googlesource.com/chromium/src.git/+/c133efa0b915430701930b76a7cfe35608b9a403>.

    * fast/url/relative-expected.txt:
    * fast/url/relative.html:
    * fast/url/relative2-expected.txt: Copied from LayoutTests/fast/url/relative-expected.txt.
    * fast/url/relative2.html: Copied from LayoutTests/fast/url/relative.html.
    * fast/url/resources/utilities.js:
    (setShouldEllipsizeFileURLPaths): Added. Toggles ellipsizing the path portion of a file URL to simplify matching.
    Otherwise, file URLs could be machine-specific.
    (canonicalizedPathname): Added.
    (segments): Modified to optionally call canonicalizedPathname.
    (canonicalize): Ditto.
    * fast/url/segments-from-data-url-expected.txt:
    * fast/url/segments-from-data-url.html:
    * fast/url/segments-from-data-url2-expected.txt: Copied from LayoutTests/fast/url/segments-from-data-url-expected.txt.
    * fast/url/segments-from-data-url2.html: Copied from LayoutTests/fast/url/segments-from-data-url.html.
    * fetch/fetch-url-serialization-expected.txt:
    * http/tests/plugins/navigation-during-load-embed.html:
    * http/tests/plugins/navigation-during-load.html:
    * http/tests/security/allowed-base-url-data-url-via-setting-expected.txt: Added.
    * http/tests/security/allowed-base-url-data-url-via-setting.html: Added.
    * http/tests/security/denied-base-url-data-url-expected.txt: Added.
    * http/tests/security/denied-base-url-data-url.html: Added.
    * http/tests/security/denied-base-url-javascript-url-expected.txt: Added.
    * http/tests/security/denied-base-url-javascript-url.html: Added.

    Canonical link: https://commits.webkit.org/220473@main
    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@256191 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Canonical link: https://commits.webkit.org/218903.369@safari-609.1.20.3-branch
git-svn-id: https://svn.webkit.org/repository/webkit/branches/safari-609.1.20.3-branch@256945 268f45cc-cd09-0410-ab3c-d52691b4dbfc
JonWBedard pushed a commit to WebKit/WebKit that referenced this issue Jan 27, 2022
    Disallow setting base URL to a data or JavaScript URL
    https://bugs.webkit.org/show_bug.cgi?id=207136

    Source/WebCore:

    Reviewed by Brent Fulgham.

    Inspired by <https://bugs.chromium.org/p/chromium/issues/detail?id=679318>.

    Block setting the base URL to a data URL or JavaScript URL as such usage is questionable.
    This makes WebKit match the behavior of Chrome and Firefox and is in the spirit of the
    discussion in <whatwg/html#2249>.

    On Mac and iOS, this restriction is applied only to apps linked against a future SDK to
    avoid breaking shipped apps.

    For all other ports, this restriction is enabled by default.

    Tests: fast/url/relative2.html
           fast/url/segments-from-data-url2.html
           http/tests/security/allowed-base-url-data-url-via-setting.html
           http/tests/security/denied-base-url-data-url.html
           http/tests/security/denied-base-url-javascript-url.html

    * dom/Document.cpp:
    (WebCore::Document::processBaseElement): Condition updating the parsed
    base URL on whether is has an allowed scheme, if restrictions are enabled. Otherwise,
    do what we do now. If the scheme is disallowed then log a message to the console to
    explain this to web developers.
    * html/parser/HTMLPreloadScanner.cpp:
    (WebCore::TokenPreloadScanner::scan): Pass whether to apply restrictons to the base URL
    to updatePredictedBaseURL(). This depends on whether the setting is enabled or not.
    (WebCore::TokenPreloadScanner::updatePredictedBaseURL): Modifed to take a boolean as to
    whether to apply restrictions. If restrictions are not to be applied do what we do now.
    Otherwise, only do what we do now if the scheme for the predicated base URL is allowed.
    * html/parser/HTMLPreloadScanner.h:
    * page/SecurityPolicy.cpp:
    (WebCore::SecurityPolicy::isBaseURLSchemeAllowed): Added.
    * page/SecurityPolicy.h:
    * page/Settings.yaml: Add a setting to toggle restrictions on the base URL scheme.

    Source/WebKit:

    Reviewed by Brent Fulgham.

    Apply base URL restrictions to apps linked to a future WebKit to avoid breaking existing apps.

    * Shared/WebPreferences.yaml:
    * UIProcess/API/Cocoa/WKWebView.mm:
    (shouldRestrictBaseURLSchemes): Added.
    (-[WKWebView _setupPageConfiguration:]): Update settings.
    * UIProcess/Cocoa/VersionChecks.h:

    Source/WebKitLegacy/mac:

    Reviewed by Brent Fulgham.

    Apply base URL restrictions to apps linked to a future WebKit to avoid breaking existing apps.

    * Misc/WebKitVersionChecks.h:
    * WebView/WebView.mm:
    (shouldRestrictBaseURLSchemes): Added.
    (-[WebView _commonInitializationWithFrameName:groupName:]): Update settings.

    Source/WTF:

    Reviewed by Brent Fulgham.

    Add some more macro definitions.

    * wtf/spi/darwin/dyldSPI.h:

    LayoutTests:

    RReviewed by Brent Fulgham.

    Add some tests. Update others to toggle the setting to apply or unapply the new behavior.

    The test denied-base-url-javascript-url.html is derived from the test base-url-javascript.html,
    included in <https://chromium.googlesource.com/chromium/src.git/+/c133efa0b915430701930b76a7cfe35608b9a403>.

    * fast/url/relative-expected.txt:
    * fast/url/relative.html:
    * fast/url/relative2-expected.txt: Copied from LayoutTests/fast/url/relative-expected.txt.
    * fast/url/relative2.html: Copied from LayoutTests/fast/url/relative.html.
    * fast/url/resources/utilities.js:
    (setShouldEllipsizeFileURLPaths): Added. Toggles ellipsizing the path portion of a file URL to simplify matching.
    Otherwise, file URLs could be machine-specific.
    (canonicalizedPathname): Added.
    (segments): Modified to optionally call canonicalizedPathname.
    (canonicalize): Ditto.
    * fast/url/segments-from-data-url-expected.txt:
    * fast/url/segments-from-data-url.html:
    * fast/url/segments-from-data-url2-expected.txt: Copied from LayoutTests/fast/url/segments-from-data-url-expected.txt.
    * fast/url/segments-from-data-url2.html: Copied from LayoutTests/fast/url/segments-from-data-url.html.
    * fetch/fetch-url-serialization-expected.txt:
    * http/tests/plugins/navigation-during-load-embed.html:
    * http/tests/plugins/navigation-during-load.html:
    * http/tests/security/allowed-base-url-data-url-via-setting-expected.txt: Added.
    * http/tests/security/allowed-base-url-data-url-via-setting.html: Added.
    * http/tests/security/denied-base-url-data-url-expected.txt: Added.
    * http/tests/security/denied-base-url-data-url.html: Added.
    * http/tests/security/denied-base-url-javascript-url-expected.txt: Added.
    * http/tests/security/denied-base-url-javascript-url.html: Added.

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@256191 268f45cc-cd09-0410-ab3c-d52691b4dbfc

git-svn-id: https://svn.webkit.org/repository/webkit/branches/safari-609-branch@256796 268f45cc-cd09-0410-ab3c-d52691b4dbfc
JonWBedard pushed a commit to WebKit/WebKit that referenced this issue Jan 27, 2022
    Disallow setting base URL to a data or JavaScript URL
    https://bugs.webkit.org/show_bug.cgi?id=207136

    Source/WebCore:

    Reviewed by Brent Fulgham.

    Inspired by <https://bugs.chromium.org/p/chromium/issues/detail?id=679318>.

    Block setting the base URL to a data URL or JavaScript URL as such usage is questionable.
    This makes WebKit match the behavior of Chrome and Firefox and is in the spirit of the
    discussion in <whatwg/html#2249>.

    On Mac and iOS, this restriction is applied only to apps linked against a future SDK to
    avoid breaking shipped apps.

    For all other ports, this restriction is enabled by default.

    Tests: fast/url/relative2.html
           fast/url/segments-from-data-url2.html
           http/tests/security/allowed-base-url-data-url-via-setting.html
           http/tests/security/denied-base-url-data-url.html
           http/tests/security/denied-base-url-javascript-url.html

    * dom/Document.cpp:
    (WebCore::Document::processBaseElement): Condition updating the parsed
    base URL on whether is has an allowed scheme, if restrictions are enabled. Otherwise,
    do what we do now. If the scheme is disallowed then log a message to the console to
    explain this to web developers.
    * html/parser/HTMLPreloadScanner.cpp:
    (WebCore::TokenPreloadScanner::scan): Pass whether to apply restrictons to the base URL
    to updatePredictedBaseURL(). This depends on whether the setting is enabled or not.
    (WebCore::TokenPreloadScanner::updatePredictedBaseURL): Modifed to take a boolean as to
    whether to apply restrictions. If restrictions are not to be applied do what we do now.
    Otherwise, only do what we do now if the scheme for the predicated base URL is allowed.
    * html/parser/HTMLPreloadScanner.h:
    * page/SecurityPolicy.cpp:
    (WebCore::SecurityPolicy::isBaseURLSchemeAllowed): Added.
    * page/SecurityPolicy.h:
    * page/Settings.yaml: Add a setting to toggle restrictions on the base URL scheme.

    Source/WebKit:

    Reviewed by Brent Fulgham.

    Apply base URL restrictions to apps linked to a future WebKit to avoid breaking existing apps.

    * Shared/WebPreferences.yaml:
    * UIProcess/API/Cocoa/WKWebView.mm:
    (shouldRestrictBaseURLSchemes): Added.
    (-[WKWebView _setupPageConfiguration:]): Update settings.
    * UIProcess/Cocoa/VersionChecks.h:

    Source/WebKitLegacy/mac:

    Reviewed by Brent Fulgham.

    Apply base URL restrictions to apps linked to a future WebKit to avoid breaking existing apps.

    * Misc/WebKitVersionChecks.h:
    * WebView/WebView.mm:
    (shouldRestrictBaseURLSchemes): Added.
    (-[WebView _commonInitializationWithFrameName:groupName:]): Update settings.

    Source/WTF:

    Reviewed by Brent Fulgham.

    Add some more macro definitions.

    * wtf/spi/darwin/dyldSPI.h:

    LayoutTests:

    RReviewed by Brent Fulgham.

    Add some tests. Update others to toggle the setting to apply or unapply the new behavior.

    The test denied-base-url-javascript-url.html is derived from the test base-url-javascript.html,
    included in <https://chromium.googlesource.com/chromium/src.git/+/c133efa0b915430701930b76a7cfe35608b9a403>.

    * fast/url/relative-expected.txt:
    * fast/url/relative.html:
    * fast/url/relative2-expected.txt: Copied from LayoutTests/fast/url/relative-expected.txt.
    * fast/url/relative2.html: Copied from LayoutTests/fast/url/relative.html.
    * fast/url/resources/utilities.js:
    (setShouldEllipsizeFileURLPaths): Added. Toggles ellipsizing the path portion of a file URL to simplify matching.
    Otherwise, file URLs could be machine-specific.
    (canonicalizedPathname): Added.
    (segments): Modified to optionally call canonicalizedPathname.
    (canonicalize): Ditto.
    * fast/url/segments-from-data-url-expected.txt:
    * fast/url/segments-from-data-url.html:
    * fast/url/segments-from-data-url2-expected.txt: Copied from LayoutTests/fast/url/segments-from-data-url-expected.txt.
    * fast/url/segments-from-data-url2.html: Copied from LayoutTests/fast/url/segments-from-data-url.html.
    * fetch/fetch-url-serialization-expected.txt:
    * http/tests/plugins/navigation-during-load-embed.html:
    * http/tests/plugins/navigation-during-load.html:
    * http/tests/security/allowed-base-url-data-url-via-setting-expected.txt: Added.
    * http/tests/security/allowed-base-url-data-url-via-setting.html: Added.
    * http/tests/security/denied-base-url-data-url-expected.txt: Added.
    * http/tests/security/denied-base-url-data-url.html: Added.
    * http/tests/security/denied-base-url-javascript-url-expected.txt: Added.
    * http/tests/security/denied-base-url-javascript-url.html: Added.

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@256191 268f45cc-cd09-0410-ab3c-d52691b4dbfc

git-svn-id: https://svn.webkit.org/repository/webkit/branches/safari-609-branch@256896 268f45cc-cd09-0410-ab3c-d52691b4dbfc
JonWBedard pushed a commit to WebKit/WebKit that referenced this issue Dec 1, 2022
https://bugs.webkit.org/show_bug.cgi?id=207136

Source/WebCore:

Reviewed by Brent Fulgham.

Inspired by <https://bugs.chromium.org/p/chromium/issues/detail?id=679318>.

Block setting the base URL to a data URL or JavaScript URL as such usage is questionable.
This makes WebKit match the behavior of Chrome and Firefox and is in the spirit of the
discussion in <whatwg/html#2249>.

On Mac and iOS, this restriction is applied only to apps linked against a future SDK to
avoid breaking shipped apps.

For all other ports, this restriction is enabled by default.

Tests: fast/url/relative2.html
       fast/url/segments-from-data-url2.html
       http/tests/security/allowed-base-url-data-url-via-setting.html
       http/tests/security/denied-base-url-data-url.html
       http/tests/security/denied-base-url-javascript-url.html

* dom/Document.cpp:
(WebCore::Document::processBaseElement): Condition updating the parsed
base URL on whether is has an allowed scheme, if restrictions are enabled. Otherwise,
do what we do now. If the scheme is disallowed then log a message to the console to
explain this to web developers.
* html/parser/HTMLPreloadScanner.cpp:
(WebCore::TokenPreloadScanner::scan): Pass whether to apply restrictons to the base URL
to updatePredictedBaseURL(). This depends on whether the setting is enabled or not.
(WebCore::TokenPreloadScanner::updatePredictedBaseURL): Modifed to take a boolean as to
whether to apply restrictions. If restrictions are not to be applied do what we do now.
Otherwise, only do what we do now if the scheme for the predicated base URL is allowed.
* html/parser/HTMLPreloadScanner.h:
* page/SecurityPolicy.cpp:
(WebCore::SecurityPolicy::isBaseURLSchemeAllowed): Added.
* page/SecurityPolicy.h:
* page/Settings.yaml: Add a setting to toggle restrictions on the base URL scheme.

Source/WebKit:

Reviewed by Brent Fulgham.

Apply base URL restrictions to apps linked to a future WebKit to avoid breaking existing apps.

* Shared/WebPreferences.yaml:
* UIProcess/API/Cocoa/WKWebView.mm:
(shouldRestrictBaseURLSchemes): Added.
(-[WKWebView _setupPageConfiguration:]): Update settings.
* UIProcess/Cocoa/VersionChecks.h:

Source/WebKitLegacy/mac:

Reviewed by Brent Fulgham.

Apply base URL restrictions to apps linked to a future WebKit to avoid breaking existing apps.

* Misc/WebKitVersionChecks.h:
* WebView/WebView.mm:
(shouldRestrictBaseURLSchemes): Added.
(-[WebView _commonInitializationWithFrameName:groupName:]): Update settings.

Source/WTF:

Reviewed by Brent Fulgham.

Add some more macro definitions.

* wtf/spi/darwin/dyldSPI.h:

LayoutTests:

RReviewed by Brent Fulgham.

Add some tests. Update others to toggle the setting to apply or unapply the new behavior.

The test denied-base-url-javascript-url.html is derived from the test base-url-javascript.html,
included in <https://chromium.googlesource.com/chromium/src.git/+/c133efa0b915430701930b76a7cfe35608b9a403>.

* fast/url/relative-expected.txt:
* fast/url/relative.html:
* fast/url/relative2-expected.txt: Copied from LayoutTests/fast/url/relative-expected.txt.
* fast/url/relative2.html: Copied from LayoutTests/fast/url/relative.html.
* fast/url/resources/utilities.js:
(setShouldEllipsizeFileURLPaths): Added. Toggles ellipsizing the path portion of a file URL to simplify matching.
Otherwise, file URLs could be machine-specific.
(canonicalizedPathname): Added.
(segments): Modified to optionally call canonicalizedPathname.
(canonicalize): Ditto.
* fast/url/segments-from-data-url-expected.txt:
* fast/url/segments-from-data-url.html:
* fast/url/segments-from-data-url2-expected.txt: Copied from LayoutTests/fast/url/segments-from-data-url-expected.txt.
* fast/url/segments-from-data-url2.html: Copied from LayoutTests/fast/url/segments-from-data-url.html.
* fetch/fetch-url-serialization-expected.txt:
* http/tests/plugins/navigation-during-load-embed.html:
* http/tests/plugins/navigation-during-load.html:
* http/tests/security/allowed-base-url-data-url-via-setting-expected.txt: Added.
* http/tests/security/allowed-base-url-data-url-via-setting.html: Added.
* http/tests/security/denied-base-url-data-url-expected.txt: Added.
* http/tests/security/denied-base-url-data-url.html: Added.
* http/tests/security/denied-base-url-javascript-url-expected.txt: Added.
* http/tests/security/denied-base-url-javascript-url.html: Added.
@annevk
Copy link
Member

annevk commented Aug 31, 2023

Coming back to this, I don't see how the CSS case is a security problem. The <base> case is a marginal security problem as it can lead to script execution, assuming the attacker can inject data: but not https:. Consider that cross-origin scripts could be banned through CSP.

The moment Gecko aligns its URL parser it would also end up being vulnerable to that case.

Given that Chromium and WebKit already implement a mitigation I think we should standardize on that and have Gecko align to prevent it from introducing a novel XSS angle for itself once it aligns its URL parser.

Persuasive enough @zcorpan @mozfreddyb?

(I discovered that a single url/ test in Interop 2023 leads back to this issue. Currently failing in Chromium and WebKit. https://wpt.fyi/results/url/a-element.html%3Fexclude%3D(file%7Cjavascript%7Cmailto) search for <#x> against <data:,>.)

@zcorpan
Copy link
Member

zcorpan commented Aug 31, 2023

My preference would have been to disallow data: etc as base URLs, but it didn't happen. So, at this point, I agree.

For #2249 (comment) maybe we could have a depth limit for @import?

@annevk
Copy link
Member

annevk commented Aug 31, 2023

Great, I'll work on a PR.

I wonder why the @import case doesn't result in recursion in WebKit, but it does seem reasonable to add a check if Chromium's behavior is indeed correct as you could have a website hang without script and I vaguely recall us preventing that in other cases.

@zcorpan
Copy link
Member

zcorpan commented Aug 31, 2023

In STP I get this message in the console:

Did not parse stylesheet at 'data:/,%20@import%20url('x%20/**/');' because non CSS MIME types are not allowed for cross-origin stylesheets.

annevk added a commit that referenced this issue Aug 31, 2023
Also correct a minor mistake in the invocation of "Is base allowed for Document?".

Tests: web-platform-tests/wpt#41731.

Fixes #2249.
annevk added a commit that referenced this issue Aug 31, 2023
Also correct a minor mistake in the invocation of "Is base allowed for Document?".

Tests: web-platform-tests/wpt#41731.

Fixes #2249.
@annevk
Copy link
Member

annevk commented Aug 31, 2023

We discussed the CSS issue further on Chat and as a result Simon filed these bugs:

No specification change should be needed for that scenario. (The main scenario was fixed in #9665.)

zcorpan added a commit to web-platform-tests/wpt that referenced this issue Aug 31, 2023
The origin of the stylesheet's URL should be checked for being same-origin with the document, per spec. A data: URL's origin is an opaque origin, which is not same origin with the document.

Also see whatwg/html#2249 (comment)
zcorpan added a commit to web-platform-tests/wpt that referenced this issue Aug 31, 2023
The origin of the stylesheet's URL should be checked for being same-origin with the document, per spec. A data: URL's origin is an opaque origin, which is not same origin with the document.

Also see whatwg/html#2249 (comment)
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Sep 13, 2023
…quirk origin check, a=testonly

Automatic update from web-platform-tests
HTML: stylesheet with non-CSS MIME type quirk origin check

The origin of the stylesheet's URL should be checked for being same-origin with the document, per spec. A data: URL's origin is an opaque origin, which is not same origin with the document.

Also see whatwg/html#2249 (comment)

--

wpt-commits: a0d5528d8a601e34bec85e34ce8a033d4c3fc192
wpt-pr: 41744
vinnydiehl pushed a commit to vinnydiehl/mozilla-unified that referenced this issue Sep 14, 2023
…quirk origin check, a=testonly

Automatic update from web-platform-tests
HTML: stylesheet with non-CSS MIME type quirk origin check

The origin of the stylesheet's URL should be checked for being same-origin with the document, per spec. A data: URL's origin is an opaque origin, which is not same origin with the document.

Also see whatwg/html#2249 (comment)

--

wpt-commits: a0d5528d8a601e34bec85e34ce8a033d4c3fc192
wpt-pr: 41744
Lightning00Blade pushed a commit to Lightning00Blade/wpt that referenced this issue Dec 11, 2023
The origin of the stylesheet's URL should be checked for being same-origin with the document, per spec. A data: URL's origin is an opaque origin, which is not same origin with the document.

Also see whatwg/html#2249 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

8 participants