Bug 162254

Summary: Non-special URLs should have an opaque origin
Product: WebKit Reporter: Alex Christensen <achristensen>
Component: New BugsAssignee: Alex Christensen <achristensen>
Status: RESOLVED FIXED    
Severity: Normal CC: ap, benjamin, buildbot, cdumez, cgarcia, cmarcelo, commit-queue, eric.carlson, ews-watchlist, ggaren, glenn, hi, jer.noble, mcatanzaro, mike, philipj, rniwa, sergio, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=162387
https://bugs.webkit.org/show_bug.cgi?id=162475
https://bugs.webkit.org/show_bug.cgi?id=222943
https://bugs.webkit.org/show_bug.cgi?id=225036
Bug Depends on: 162492    
Bug Blocks:    
Attachments:
Description Flags
Patch
none
Archive of layout-test-results from ews101 for mac-yosemite
none
Archive of layout-test-results from ews117 for mac-yosemite
none
Archive of layout-test-results from ews107 for mac-yosemite-wk2
none
Patch
none
Archive of layout-test-results from ews101 for mac-yosemite
none
Archive of layout-test-results from ews104 for mac-yosemite-wk2
none
Archive of layout-test-results from ews117 for mac-yosemite
none
Patch
none
Archive of layout-test-results from ews103 for mac-yosemite
none
Archive of layout-test-results from ews107 for mac-yosemite-wk2
none
Archive of layout-test-results from ews117 for mac-yosemite
none
Archive of layout-test-results from ews123 for ios-simulator-elcapitan-wk2
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
ews-feeder: commit-queue-
Patch
none
Patch
none
Patch
none
[Image] screenshot of current behavior of custom origin in Web Inspector
none
Patch
none
Patch none

Description Alex Christensen 2016-09-19 21:58:48 PDT
Non-special URLs should have an opaque origin
Comment 1 Alex Christensen 2016-09-19 22:00:41 PDT
Created attachment 289315 [details]
Patch
Comment 2 Build Bot 2016-09-19 22:19:21 PDT
Comment on attachment 289315 [details]
Patch

Attachment 289315 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.webkit.org/results/2110036

Number of test failures exceeded the failure limit.
Comment 3 Build Bot 2016-09-19 22:19:24 PDT
Created attachment 289322 [details]
Archive of layout-test-results from ews101 for mac-yosemite

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews101  Port: mac-yosemite  Platform: Mac OS X 10.10.5
Comment 4 Build Bot 2016-09-19 22:37:47 PDT
Comment on attachment 289315 [details]
Patch

Attachment 289315 [details] did not pass mac-debug-ews (mac):
Output: http://webkit-queues.webkit.org/results/2110155

Number of test failures exceeded the failure limit.
Comment 5 Build Bot 2016-09-19 22:37:50 PDT
Created attachment 289323 [details]
Archive of layout-test-results from ews117 for mac-yosemite

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews117  Port: mac-yosemite  Platform: Mac OS X 10.10.5
Comment 6 Build Bot 2016-09-19 22:37:57 PDT
Comment on attachment 289315 [details]
Patch

Attachment 289315 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/2110160

Number of test failures exceeded the failure limit.
Comment 7 Build Bot 2016-09-19 22:37:59 PDT
Created attachment 289324 [details]
Archive of layout-test-results from ews107 for mac-yosemite-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews107  Port: mac-yosemite-wk2  Platform: Mac OS X 10.10.5
Comment 8 Sam Weinig 2016-09-20 02:34:06 PDT
Comment on attachment 289315 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=289315&action=review

> Source/WebCore/page/SecurityOrigin.cpp:182
> +    if (url.protocolIsInHTTPFamily()

This could use a either a comment, or a helper predicate that explains why this set. I would prefer a static shouldUseUniqueOrigin(url) or something.
Comment 9 Alex Christensen 2016-09-20 08:11:37 PDT
Created attachment 289345 [details]
Patch
Comment 10 Sam Weinig 2016-09-20 08:28:20 PDT
Comment on attachment 289345 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=289345&action=review

I'm a little concerned that this is changing the behavior of file: URLs here, but I am honestly not sure what the old behavior was.  Also, how does this differ from SchemeRegistry::shouldTreatURLSchemeAsNoAccess()?

> Source/WebCore/page/SecurityOrigin.cpp:105
> +        && !url.protocolIs("gopher")

GOPHER!
Comment 11 Build Bot 2016-09-20 08:51:14 PDT
Comment on attachment 289345 [details]
Patch

Attachment 289345 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.webkit.org/results/2112734

Number of test failures exceeded the failure limit.
Comment 12 Build Bot 2016-09-20 08:51:17 PDT
Created attachment 289351 [details]
Archive of layout-test-results from ews101 for mac-yosemite

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews101  Port: mac-yosemite  Platform: Mac OS X 10.10.5
Comment 13 Build Bot 2016-09-20 08:57:02 PDT
Comment on attachment 289345 [details]
Patch

Attachment 289345 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/2112742

Number of test failures exceeded the failure limit.
Comment 14 Build Bot 2016-09-20 08:57:05 PDT
Created attachment 289352 [details]
Archive of layout-test-results from ews104 for mac-yosemite-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews104  Port: mac-yosemite-wk2  Platform: Mac OS X 10.10.5
Comment 15 Build Bot 2016-09-20 08:59:32 PDT
Comment on attachment 289345 [details]
Patch

Attachment 289345 [details] did not pass mac-debug-ews (mac):
Output: http://webkit-queues.webkit.org/results/2112740

Number of test failures exceeded the failure limit.
Comment 16 Build Bot 2016-09-20 08:59:35 PDT
Created attachment 289353 [details]
Archive of layout-test-results from ews117 for mac-yosemite

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews117  Port: mac-yosemite  Platform: Mac OS X 10.10.5
Comment 17 Alex Christensen 2016-09-20 09:01:32 PDT
Created attachment 289356 [details]
Patch
Comment 18 Alex Christensen 2016-09-20 09:09:21 PDT
(In reply to comment #10)
> Comment on attachment 289345 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=289345&action=review
> 
> I'm a little concerned that this is changing the behavior of file: URLs
> here, but I am honestly not sure what the old behavior was.  Also, how does
> this differ from SchemeRegistry::shouldTreatURLSchemeAsNoAccess()?
File URLs are in the list of unchanged schemes.  This makes it so all non-special schemes have opaque security origin.  I guess SchemeRegistry::shouldTreatURLSchemeAsNoAccess could be used to make a scheme like http have opaque security origins, but I'm not sure if it's ever used for that.  Maybe SchemeRegistry::shouldTreatURLSchemeAsNoAccess should be removed because of this.
> 
> > Source/WebCore/page/SecurityOrigin.cpp:105
> > +        && !url.protocolIs("gopher")
> 
> GOPHER!
It's in the spec.
Comment 19 Build Bot 2016-09-20 09:50:22 PDT
Comment on attachment 289356 [details]
Patch

Attachment 289356 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.webkit.org/results/2113011

New failing tests:
http/tests/security/postMessage/invalid-origin-throws-exception.html
Comment 20 Build Bot 2016-09-20 09:50:25 PDT
Created attachment 289362 [details]
Archive of layout-test-results from ews103 for mac-yosemite

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews103  Port: mac-yosemite  Platform: Mac OS X 10.10.5
Comment 21 Build Bot 2016-09-20 09:59:26 PDT
Comment on attachment 289356 [details]
Patch

Attachment 289356 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/2113030

New failing tests:
http/tests/security/postMessage/invalid-origin-throws-exception.html
Comment 22 Build Bot 2016-09-20 09:59:29 PDT
Created attachment 289366 [details]
Archive of layout-test-results from ews107 for mac-yosemite-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews107  Port: mac-yosemite-wk2  Platform: Mac OS X 10.10.5
Comment 23 Build Bot 2016-09-20 10:04:11 PDT
Comment on attachment 289356 [details]
Patch

Attachment 289356 [details] did not pass mac-debug-ews (mac):
Output: http://webkit-queues.webkit.org/results/2113027

New failing tests:
http/tests/security/postMessage/invalid-origin-throws-exception.html
Comment 24 Build Bot 2016-09-20 10:04:14 PDT
Created attachment 289368 [details]
Archive of layout-test-results from ews117 for mac-yosemite

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews117  Port: mac-yosemite  Platform: Mac OS X 10.10.5
Comment 25 Build Bot 2016-09-20 10:11:22 PDT
Comment on attachment 289356 [details]
Patch

Attachment 289356 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: http://webkit-queues.webkit.org/results/2113040

New failing tests:
http/tests/security/postMessage/invalid-origin-throws-exception.html
Comment 26 Build Bot 2016-09-20 10:11:26 PDT
Created attachment 289370 [details]
Archive of layout-test-results from ews123 for ios-simulator-elcapitan-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews123  Port: ios-simulator-elcapitan-wk2  Platform: Mac OS X 10.11.6
Comment 27 Alex Christensen 2016-09-20 10:59:30 PDT
Created attachment 289384 [details]
Patch
Comment 28 Alex Christensen 2016-09-20 13:03:36 PDT
http://trac.webkit.org/changeset/206165
Comment 29 WebKit Commit Bot 2016-09-23 09:02:12 PDT
Re-opened since this is blocked by bug 162492
Comment 30 Alex Christensen 2016-09-23 09:21:11 PDT
Comment on attachment 289384 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=289384&action=review

> Source/WebCore/page/SecurityOrigin.cpp:106
> +    return !innerURL.protocolIsInHTTPFamily()
> +        && !innerURL.protocolIs("file")
> +        && !innerURL.protocolIs("ftp")
> +        && !innerURL.protocolIs("gopher")
> +        && !innerURL.protocolIs("ws")
> +        && !innerURL.protocolIs("wss");

When I reland this, I plan to add this:
#if PLATFORM(GTK)
    // Comment explaining why this is needed...
    && !innerURL.protocolIs("resource")
#endif
Comment 31 Carlos Garcia Campos 2016-09-27 04:35:05 PDT
(In reply to comment #30)
> Comment on attachment 289384 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=289384&action=review
> 
> > Source/WebCore/page/SecurityOrigin.cpp:106
> > +    return !innerURL.protocolIsInHTTPFamily()
> > +        && !innerURL.protocolIs("file")
> > +        && !innerURL.protocolIs("ftp")
> > +        && !innerURL.protocolIs("gopher")
> > +        && !innerURL.protocolIs("ws")
> > +        && !innerURL.protocolIs("wss");
> 
> When I reland this, I plan to add this:
> #if PLATFORM(GTK)
>     // Comment explaining why this is needed...
>     && !innerURL.protocolIs("resource")
> #endif

We would still need the new api to mark custom uri schemes as non-unique when registered.
Comment 32 Alex Christensen 2016-09-27 13:28:39 PDT
(In reply to comment #31)
> (In reply to comment #30)
> > Comment on attachment 289384 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=289384&action=review
> > 
> > > Source/WebCore/page/SecurityOrigin.cpp:106
> > > +    return !innerURL.protocolIsInHTTPFamily()
> > > +        && !innerURL.protocolIs("file")
> > > +        && !innerURL.protocolIs("ftp")
> > > +        && !innerURL.protocolIs("gopher")
> > > +        && !innerURL.protocolIs("ws")
> > > +        && !innerURL.protocolIs("wss");
> > 
> > When I reland this, I plan to add this:
> > #if PLATFORM(GTK)
> >     // Comment explaining why this is needed...
> >     && !innerURL.protocolIs("resource")
> > #endif
> 
> We would still need the new api to mark custom uri schemes as non-unique
> when registered.
Yes, and I think that api should be automatically called when making a new GTK WebProcess or when opening the Web Inspector instead of putting this layering violation here.
Comment 33 Alex Christensen 2016-10-14 18:47:07 PDT
Created attachment 291698 [details]
Patch
Comment 34 WebKit Commit Bot 2016-10-14 18:48:22 PDT
Attachment 291698 [details] did not pass style-queue:


ERROR: Source/WebKit2/UIProcess/API/Cocoa/WKProcessPoolPrivate.h:0:  Use #pragma once header guard.  [build/header_guard] [5]
ERROR: Source/WebKit/mac/WebView/WebViewPrivate.h:0:  Use #pragma once header guard.  [build/header_guard] [5]
Total errors found: 2 in 34 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 35 Alex Christensen 2016-10-14 18:50:03 PDT
Carlos or Michael, could you deprecate the old GTK API and add new GTK API like I tried to do in https://bugs.webkit.org/show_bug.cgi?id=162475 and use it to register the "resource" scheme when opening the web inspector so we don't have another https://bugs.webkit.org/show_bug.cgi?id=162387 ?
Comment 36 Carlos Garcia Campos 2016-10-15 01:55:29 PDT
(In reply to comment #35)
> Carlos or Michael, could you deprecate the old GTK API and add new GTK API
> like I tried to do in https://bugs.webkit.org/show_bug.cgi?id=162475 and use
> it to register the "resource" scheme when opening the web inspector so we
> don't have another https://bugs.webkit.org/show_bug.cgi?id=162387 ?

Yes, I'll do it, but to not break anything until I write the patch, could you please do a couple of things?

 1- In Source/WebKit2/UIProcess/API/gtk/WebKitSecurityManager.cpp remove the uses of removed API from registerSecurityPolicyForURIScheme() and checkSecurityPolicyForURIScheme() just to fix the build. Do nothing when registering, and return false when checking, adding a FIXME in both cases.

 2- In SchemeRegistry.cpp add "resource" unconditionally to schemesForNonNullOrigins map inside a #if USE(SOUP) block. No need for FIXME here, we always want this.

Maybe that still breaks a unit tests, but that's not a problem. At least it will build and the inspector will be usable.
Comment 37 Darin Adler 2016-10-15 15:56:08 PDT
Comment on attachment 291698 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=291698&action=review

I’d like someone else, Anders maybe, to review the new SPI parts of this. I reviewed the rest.

> Source/WebCore/page/SecurityOrigin.cpp:107
> +    if (innerURL.protocolIsInHTTPFamily()
> +        || innerURL.protocolIs("file")
> +        || innerURL.protocolIs("ftp")
> +        || innerURL.protocolIs("gopher")
> +        || innerURL.protocolIs("ws")
> +        || innerURL.protocolIs("wss"))

Do we have this list anywhere else? I would have expected isSpecialProtocol instead of this list written out like this.

> Source/WebCore/platform/SchemeRegistry.cpp:77
> +static URLSchemesMap& schemesForNonNullOrigins()

Why call this NonNullOrigins when the code below calls it "TupleSecurityOrigin"?

> Source/WebCore/platform/SchemeRegistry.h:52
> -    WEBCORE_EXPORT static void registerURLSchemeAsNoAccess(const String&);
> -    static bool shouldTreatURLSchemeAsNoAccess(const String&);
> +    WEBCORE_EXPORT static void registerURLSchemeForTupleSecurityOrigin(const String&);
> +    static bool schemeShouldReceiveTupleSecurityOrigin(const String&);

GTK port was using this, needs to be fixed.

> LayoutTests/http/tests/security/postMessage/invalid-origin-throws-exception.html:32
> +    // URLs without an origin should fail witha syntax error.

Missing space between "with" and "a".
Comment 38 Alex Christensen 2016-10-15 19:00:51 PDT
(In reply to comment #37)
> Comment on attachment 291698 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=291698&action=review
> 
> I’d like someone else, Anders maybe, to review the new SPI parts of this. I
> reviewed the rest.
Anders said SchemeRegistry should be per Page instead of global.  Then we could put this new API on WKWebView.  I'm not sure if we can get away with a change like this without doing that.
> 
> > Source/WebCore/page/SecurityOrigin.cpp:107
> > +    if (innerURL.protocolIsInHTTPFamily()
> > +        || innerURL.protocolIs("file")
> > +        || innerURL.protocolIs("ftp")
> > +        || innerURL.protocolIs("gopher")
> > +        || innerURL.protocolIs("ws")
> > +        || innerURL.protocolIs("wss"))
> 
> Do we have this list anywhere else? I would have expected isSpecialProtocol
> instead of this list written out like this.
We do!  We should make URL::protocol return a StringView then use the same scheme function from URLParser.cpp.
> 
> > Source/WebCore/platform/SchemeRegistry.cpp:77
> > +static URLSchemesMap& schemesForNonNullOrigins()
> 
> Why call this NonNullOrigins when the code below calls it
> "TupleSecurityOrigin"?
Oh, this was from before I decided on a name.  I decided on "tuple" based on the spec, but I'm not sure if that's a good name.
> 
> > Source/WebCore/platform/SchemeRegistry.h:52
> > -    WEBCORE_EXPORT static void registerURLSchemeAsNoAccess(const String&);
> > -    static bool shouldTreatURLSchemeAsNoAccess(const String&);
> > +    WEBCORE_EXPORT static void registerURLSchemeForTupleSecurityOrigin(const String&);
> > +    static bool schemeShouldReceiveTupleSecurityOrigin(const String&);
> 
> GTK port was using this, needs to be fixed.
> 
> > LayoutTests/http/tests/security/postMessage/invalid-origin-throws-exception.html:32
> > +    // URLs without an origin should fail witha syntax error.
> 
> Missing space between "with" and "a".
Comment 39 Alex Christensen 2020-11-06 10:32:44 PST
Created attachment 413444 [details]
Patch
Comment 40 Alex Christensen 2020-11-06 11:33:59 PST
Comment on attachment 413444 [details]
Patch

Looks like I do need to organize this per-page and inform the network process by adding to NetworkSchemeRegistry
Comment 41 Alex Christensen 2020-11-06 12:05:26 PST
Just kidding.  I need to add blob to the list according to https://url.spec.whatwg.org/#origin
Comment 42 Alex Christensen 2020-11-06 12:07:55 PST
Created attachment 413460 [details]
Patch
Comment 43 Alex Christensen 2020-11-06 13:19:19 PST
Created attachment 413473 [details]
Patch
Comment 44 Alex Christensen 2020-11-06 19:35:39 PST
Created attachment 413505 [details]
Patch
Comment 45 Alex Christensen 2020-11-10 07:51:25 PST
Created attachment 413696 [details]
Patch
Comment 46 Alex Christensen 2020-11-10 12:09:09 PST
Created attachment 413721 [details]
Patch
Comment 47 Devin Rousso 2020-11-10 12:51:27 PST
Comment on attachment 413721 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=413721&action=review

> LayoutTests/inspector/unit-tests/url-utilities.html:202
> -                origin: "app-specific://example.com",
> +                origin: "null",

I think this will modify the behavior of Web Inspector.  Web Inspector should always show the origin of URLs.  As-is, I think this change would cause all custom-origin URLs to be shown at the top-level of the navigation sidebar in the Sources Tab instead of being organized underneath a tree element for that custom-origin.

This would likely require minor adjustments to `parseURL` in `Source/WebInspectorUI/UserInterface/Base/URLUtilities.js`.
Comment 48 Alex Christensen 2020-11-10 13:11:32 PST
Devin, could you look into what problems that would cause?  I made it so if there are WKURLSchemeHandlers registered, it allows non-null origins.  I believe that should prevent such problems in practice.  If someone has a URL with an unrecognized scheme that has no scheme handler, then the origin should change to become null.  I'm open to learning what problems that may cause.
Comment 49 Devin Rousso 2020-11-10 13:34:33 PST
Created attachment 413731 [details]
[Image] screenshot of current behavior of custom origin in Web Inspector

(In reply to Alex Christensen from comment #48)
> Devin, could you look into what problems that would cause?  I made it so if there are WKURLSchemeHandlers registered, it allows non-null origins.  I believe that should prevent such problems in practice.  If someone has a URL with an unrecognized scheme that has no scheme handler, then the origin should change to become null.  I'm open to learning what problems that may cause.

Attached an example screenshot of what a custom origin looks like right now in Web Inspector.  You can reproduce this yourself by
1. inspecting <https://webkit.org/>
2. switching to "By Path" in the Sources Tab
3. evaluating `(new Image).src = "app-specific://example.com"` in the Web Inspector console

If the `origin` of the object returned by `parseURL` is `null`, then I think that would instead appear at the top-level instead of nested underneath a tree element for "app-specific://example.com".

FWIW, I'm not sure how often this will actually happen and/or be an issue, because as you said this only affects custom origins that do not have a scheme handler.  And even then, I think the only problem it would cause is that the resource is not placed in the same spot it was before.

It may be worth leaving the test as-is and just changing the expected file to `FAIL` with a followup bug for adjusting Web Inspector so that it can still recognize the origin.
Comment 50 Alex Christensen 2020-11-10 13:39:23 PST
I think that's an intentional change in behavior, and I don't think any followup is necessary with the web inspector.  I think the test correctly reflects that if you need the origin of an unrecognized scheme it will now be null.  I have added an API test that verifies that if a scheme handler is registered in the app, the origin will continue to be non-null.  If you feel strongly that I should leave the inspector test as failing and file another bug I will, but I don't think it's necessary.
Comment 51 Devin Rousso 2020-11-10 13:45:43 PST
(In reply to Alex Christensen from comment #50)
> I think that's an intentional change in behavior, and I don't think any followup is necessary with the web inspector.  I think the test correctly reflects that if you need the origin of an unrecognized scheme it will now be null.
I agree that as far as JavaScript is concerned, this is an intentional change in behavior, but for the purposes of Web Inspector as a developer tool, we should always show the origin even when it's hidden from JavaScript.  As an example, if a page tries to load `a://example.com/foo.js` and `b://example.com/foo.js`, they should not appear under the same top-level item when "By Path".  Web Inspector intentionally displays data that is hidden from JavaScript/native APIs all the time, as that's one of the reasons why it exists in the first place.

> I have added an API test that verifies that if a scheme handler is registered in the app, the origin will continue to be non-null.
Awesome!  That's I think why this is likely to be an extremely rare issue in production.

> If you feel strongly that I should leave the inspector test as failing and file another bug I will, but I don't think it's necessary.
Eh, I don't have a strong opinion one way or the other how you leave the test, but I do think this warrants a followup bug (and maybe a FIXME comment in the test) to ensure that this change in behavior does not negatively affect Web Inspector.  Maybe something like "Web Inspector: ensure that `parseURL` is able to derive an origin for non-registered schemes"?
Comment 52 Alex Christensen 2020-11-10 13:48:11 PST
The whole point of this is that neither Web Inspector nor web content should be able to derive an origin for non-registered schemes.  Only registered schemes should be able to be an origin.
Comment 53 Devin Rousso 2020-11-10 14:10:54 PST
(In reply to Alex Christensen from comment #52)
> The whole point of this is that neither Web Inspector nor web content should be able to derive an origin for non-registered schemes.  Only registered schemes should be able to be an origin.

To clarify something, I'm not suggesting that you modify `URL` when in Web Inspector to allow the `origin` for non-registered schemes.  Web Inspector should not be given any special functionality unless absolutely necessary.  I'm suggesting that the `parseURL` function that Web Inspector has defined be modified to derive the origin on its own.  I agree that as far as the JavaScript `URL` is concerned, the origin should not be shown for non-registered schemes.

The purpose of Web Inspector is to expose information to the developer that aids them in introspecting/debugging their web content.  This often takes the form of exposing information that is not normally available via web APIs.  If a developer has written code for `app-specific://example.com`, Web Inspector should show the information as it was actually used in the engine.

Also, even with your patch I believe Web Inspector will still show the custom scheme in other places like the table in the Network Tab (right click on the header and check Scheme).  Those places follow different code paths, so they are likely unaffected by your changes to `URL`.  I'm just asking that Web Inspector be consistent in what information it shows regardless of where it gets the data (which usually involves Web Inspector doing extra work on top of what is exposed via web APIs, which is one of the reasons why the Web Inspector protocol exists).  And to be clear, this is not something that needs to be changed in WebCore/WebKit/etc., it's purely something that Web Inspector will need to do on its own (`parseURL` inside `Source/WebInspectorUI/UserInterface/Base/URLUtilities.js`).
Comment 54 Alex Christensen 2020-11-10 16:24:32 PST
I filed https://bugs.webkit.org/show_bug.cgi?id=218780
Comment 55 Alex Christensen 2020-11-12 09:11:40 PST
Created attachment 413940 [details]
Patch
Comment 56 Alex Christensen 2020-11-12 09:26:23 PST
Comment on attachment 413940 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=413940&action=review

> Source/WebInspectorUI/UserInterface/Base/URLUtilities.js:136
> +    if (parsed.origin && parsed.origin != "null")

I did this tweak to parseURL instead, which preserves the WebInspector behavior.
Comment 57 Devin Rousso 2020-11-12 09:54:33 PST
Comment on attachment 413940 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=413940&action=review

>> Source/WebInspectorUI/UserInterface/Base/URLUtilities.js:136
>> +    if (parsed.origin && parsed.origin != "null")
> 
> I did this tweak to parseURL instead, which preserves the WebInspector behavior.

NIT: this should be `!==`

Thanks for fixing this! :)
Comment 58 Alex Christensen 2020-11-12 15:12:30 PST
(In reply to Devin Rousso from comment #57)
> NIT: this should be `!==`
Will tweak when landing.
Comment 59 Geoffrey Garen 2021-02-03 13:20:50 PST
Comment on attachment 413940 [details]
Patch

r=me with the !== change
Comment 60 Alex Christensen 2021-02-06 20:56:45 PST
Created attachment 419525 [details]
Patch
Comment 61 EWS 2021-02-06 22:02:41 PST
Committed r272469: <https://commits.webkit.org/r272469>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 419525 [details].
Comment 62 Radar WebKit Bug Importer 2021-02-06 22:03:16 PST
<rdar://problem/74068207>
Comment 63 Michael Catanzaro 2021-03-06 13:18:50 PST
Hm, I think this caused Epiphany to crash when attempting to download any PDF. webkit_security_origin_new_for_uri() returns NULL for ephy-pdf: URIs, but the return value is not nullable, so Epiphany correctly dereferences it and crashes.

"""
In order to allow things like web extensions to continue to work, we allow non-null origins for schemes for which a WKURLSchemeHandler has been registered. We learned this lesson 4 years ago when we tried this change. This also makes sense conceptually because those schemes will be handled by the containing application, so they can be an "origin" for a page.
"""

That sounds good to me, Epiphany registers ephy-pdf: using webkit_web_context_register_uri_scheme(), so in theory it ought to work, but it doesn't. I'll look closer on Monday.
Comment 64 Michael Catanzaro 2021-03-08 15:08:44 PST
Bug #222943