Bug 196870 - Add a WebsiteDataStore delegate to handle AuthenticationChallenge that do not come from pages
Summary: Add a WebsiteDataStore delegate to handle AuthenticationChallenge that do not...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Service Workers (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: youenn fablet
URL:
Keywords: InRadar
Depends on:
Blocks: 266189
  Show dependency treegraph
 
Reported: 2019-04-12 11:24 PDT by youenn fablet
Modified: 2023-12-10 10:26 PST (History)
6 users (show)

See Also:


Attachments
Patch (23.34 KB, patch)
2019-04-12 11:51 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (26.11 KB, patch)
2019-04-12 14:53 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (30.56 KB, patch)
2019-04-12 15:45 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (52.33 KB, patch)
2019-04-22 22:05 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (51.63 KB, patch)
2019-04-23 08:30 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch for landing (52.77 KB, patch)
2019-08-22 02:09 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Relanding (55.12 KB, patch)
2019-08-26 05:23 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch for landing (55.12 KB, patch)
2019-08-26 06:00 PDT, youenn fablet
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description youenn fablet 2019-04-12 11:24:02 PDT
Add a WebsiteDataStore delegate to handle AuthenticationChallenge that do not come from pages
Comment 1 youenn fablet 2019-04-12 11:51:49 PDT
Created attachment 367337 [details]
Patch
Comment 2 youenn fablet 2019-04-12 11:52:36 PDT
@wilander, this should take care of your issue with HTTPS ping loads.
Comment 3 John Wilander 2019-04-12 12:26:57 PDT
Comment on attachment 367337 [details]
Patch

Nice. Could you add a Ping layout test with testRunner.setAllowsAnySSLCertificate(true) and the ping endpoint as https? Should be easy.
Comment 4 youenn fablet 2019-04-12 14:53:00 PDT
Created attachment 367347 [details]
Patch
Comment 5 youenn fablet 2019-04-12 14:53:23 PDT
(In reply to John Wilander from comment #3)
> Comment on attachment 367337 [details]
> Patch
> 
> Nice. Could you add a Ping layout test with
> testRunner.setAllowsAnySSLCertificate(true) and the ping endpoint as https?
> Should be easy.

Yep, probably need to terminate network process and then do a ping.
Comment 6 youenn fablet 2019-04-12 15:45:47 PDT
Created attachment 367351 [details]
Patch
Comment 7 Alex Christensen 2019-04-22 15:10:59 PDT
Comment on attachment 367351 [details]
Patch

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

I think this needs an API test that verifies this delegate is being called under the correct circumstances and the credentials are used as expected.

> Source/WebKit/NetworkProcess/PingLoad.cpp:135
> -        completionHandler(AuthenticationChallengeDisposition::PerformDefaultHandling, { });
> +        m_networkLoadChecker->networkProcess().authenticationManager().didReceiveAuthenticationChallenge(m_parameters.sessionID, 0, 0, challenge, WTFMove(completionHandler));

We almost certainly don't want ping loads to handle authentication challenges.  Then there would be random popups asking for credentials.

> Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm:82
> +        case NSURLSessionAuthChallengeUseCredential:

This is duplicate code with NavigationState.mm

> LayoutTests/ChangeLog:8
> +        * http/wpt/beacon/cors/crossorigin-arraybufferview-no-preflight.html:

Wouldn't this changed test have passed before because we performed default behavior?  Now we're just performing default behavior in a different place, so this test does not verify the change works.
Comment 8 Alex Christensen 2019-04-22 15:12:15 PDT
Challenge.mm has a growing number of similar authentication unit tests.
Comment 9 youenn fablet 2019-04-22 16:25:13 PDT
(In reply to Alex Christensen from comment #7)
> Comment on attachment 367351 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=367351&action=review
> 
> I think this needs an API test that verifies this delegate is being called
> under the correct circumstances and the credentials are used as expected.

I'll add one.
 
> > Source/WebKit/NetworkProcess/PingLoad.cpp:135
> > -        completionHandler(AuthenticationChallengeDisposition::PerformDefaultHandling, { });
> > +        m_networkLoadChecker->networkProcess().authenticationManager().didReceiveAuthenticationChallenge(m_parameters.sessionID, 0, 0, challenge, WTFMove(completionHandler));
> 
> We almost certainly don't want ping loads to handle authentication
> challenges.  Then there would be random popups asking for credentials.

This is limited to server trust evaluation, there is no need to ask user for credentials.
There might be a need for prompt to ask whether user trusts the site or not, but this is really an application decision.
Overall, the design I see is that this additional delegate would only be about asking whether the given certificate is already granted, not whether user is granting it.

Also, ping loads are no different from service worker fetches in that respect.
In the future, ping loads might just be regular fetch until their context is destroyed.
See https://bugs.webkit.org/show_bug.cgi?id=196807

> > LayoutTests/ChangeLog:8
> > +        * http/wpt/beacon/cors/crossorigin-arraybufferview-no-preflight.html:
> 
> Wouldn't this changed test have passed before because we performed default
> behavior?  Now we're just performing default behavior in a different place,
> so this test does not verify the change works.

Before the patch, the test would be broken.
By killing the network process, we are sure there is no connection.
The ping triggers a new connection, thus a server trust evaluation.
The default behavior will be done in network process and will cancel the creation of the connection.
After the patch, we go to UIProcess and ask WTR whether to proceed with the load.
Comment 10 youenn fablet 2019-04-22 22:05:33 PDT
Created attachment 368012 [details]
Patch
Comment 11 youenn fablet 2019-04-23 08:30:52 PDT
Created attachment 368033 [details]
Patch
Comment 12 Alex Christensen 2019-08-20 12:55:27 PDT
Comment on attachment 368033 [details]
Patch

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

> Source/WebKit/NetworkProcess/PingLoad.cpp:151
> +        m_networkLoadChecker->networkProcess().authenticationManager().didReceiveAuthenticationChallenge(m_parameters.sessionID, 0, 0, challenge, WTFMove(completionHandler));

This needs rebasing.  The 0's are now empty identifiers.  We might need to make them nullopt's.

> Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm:54
> +        , m_hasAuthenticationChallengeSelector([m_delegate.get() respondsToSelector:@selector(didReceiveAuthenticationChallenge: completionHandler:)])

extra space
Comment 13 youenn fablet 2019-08-22 02:09:03 PDT
Created attachment 376999 [details]
Patch for landing
Comment 14 WebKit Commit Bot 2019-08-22 04:05:18 PDT
Comment on attachment 376999 [details]
Patch for landing

Clearing flags on attachment: 376999

Committed r249001: <https://trac.webkit.org/changeset/249001>
Comment 15 WebKit Commit Bot 2019-08-22 04:05:20 PDT
All reviewed patches have been landed.  Closing bug.
Comment 16 Radar WebKit Bug Importer 2019-08-22 04:06:41 PDT
<rdar://problem/54593556>
Comment 17 Truitt Savell 2019-08-23 08:29:26 PDT
It looks like the changes in https://trac.webkit.org/changeset/249001/webkit

caused this test to fail constantly: imported/w3c/web-platform-tests/service-workers/service-worker/websocket-in-service-worker.https.html

it was a flakey failure before. The diff makes it look like this is just a rebasline, can you confirm? 

History:
https://webkit-test-results.webkit.org/dashboards/flakiness_dashboard.html#showAllRuns=true&tests=imported%2Fw3c%2Fweb-platform-tests%2Fservice-workers%2Fservice-worker%2Fwebsocket-in-service-worker.https.html

Diff:
--- /Volumes/Data/slave/highsierra-release-tests-wk2/build/layout-test-results/imported/w3c/web-platform-tests/service-workers/service-worker/websocket-in-service-worker.https-expected.txt
+++ /Volumes/Data/slave/highsierra-release-tests-wk2/build/layout-test-results/imported/w3c/web-platform-tests/service-workers/service-worker/websocket-in-service-worker.https-actual.txt
@@ -1,3 +1,3 @@
 
-FAIL Verify WebSockets can be created in a Service Worker assert_equals: expected "PASS" but got "FAIL: Got an error event"
+PASS Verify WebSockets can be created in a Service Worker
Comment 18 Ryan Haddad 2019-08-23 13:23:28 PDT
Reverted r249001 for reason:

Caused one layout test to fail on all configurations and another to time out on Catalina / iOS 13.

Committed r249063: <https://trac.webkit.org/changeset/249063>
Comment 19 youenn fablet 2019-08-26 05:23:41 PDT
Created attachment 377238 [details]
Relanding
Comment 20 youenn fablet 2019-08-26 05:54:50 PDT
(In reply to Ryan Haddad from comment #18)
> Reverted r249001 for reason:
> 
> Caused one layout test to fail on all configurations and another to time out
> on Catalina / iOS 13.

Layout test was going from FAIL to PASS.
The other test was updated to cope with the more accurate handling of window.testRunner.setAllowsAnySSLCertificate
Comment 21 WebKit Commit Bot 2019-08-26 05:57:28 PDT
Comment on attachment 377238 [details]
Relanding

Rejecting attachment 377238 [details] from commit-queue.

Failed to run "['/Volumes/Data/EWS/WebKit/Tools/Scripts/webkit-patch', '--status-host=webkit-queues.webkit.org', '--bot-id=webkit-cq-03', 'validate-changelog', '--check-oops', '--non-interactive', 377238, '--port=mac']" exit_code: 1 cwd: /Volumes/Data/EWS/WebKit

ChangeLog entry in LayoutTests/imported/w3c/ChangeLog contains OOPS!.

Full output: https://webkit-queues.webkit.org/results/12968665
Comment 22 youenn fablet 2019-08-26 06:00:13 PDT
Created attachment 377241 [details]
Patch for landing
Comment 23 WebKit Commit Bot 2019-08-26 08:00:12 PDT
Comment on attachment 377241 [details]
Patch for landing

Clearing flags on attachment: 377241

Committed r249096: <https://trac.webkit.org/changeset/249096>
Comment 24 WebKit Commit Bot 2019-08-26 08:00:14 PDT
All reviewed patches have been landed.  Closing bug.