Bug 183911 - Warn against cookie access in the WebContent process using ProcessPrivilege assertions
Summary: Warn against cookie access in the WebContent process using ProcessPrivilege a...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Brent Fulgham
URL:
Keywords: InRadar
Depends on: 183806
Blocks:
  Show dependency treegraph
 
Reported: 2018-03-22 12:38 PDT by Brent Fulgham
Modified: 2018-03-26 10:55 PDT (History)
17 users (show)

See Also:


Attachments
Patch (50.50 KB, patch)
2018-03-22 18:58 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch (52.76 KB, patch)
2018-03-22 19:23 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch (52.74 KB, patch)
2018-03-22 20:32 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch (54.94 KB, patch)
2018-03-23 08:35 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch (56.30 KB, patch)
2018-03-23 12:47 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch (49.26 KB, patch)
2018-03-23 15:31 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff
Patch (47.51 KB, patch)
2018-03-23 16:10 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews204 for win-future (42.23 KB, application/zip)
2018-03-23 18:18 PDT, EWS Watchlist
no flags Details
Patch for landing (51.08 KB, patch)
2018-03-26 10:18 PDT, Brent Fulgham
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brent Fulgham 2018-03-22 12:38:18 PDT
Use the new ProcessPrivilege concept (see Bug 183806) to enforce our goal of prohibiting Cookie API access inside the WebContent process.
Comment 1 Radar WebKit Bug Importer 2018-03-22 12:38:42 PDT
<rdar://problem/38762306>
Comment 2 Brent Fulgham 2018-03-22 18:58:17 PDT
Created attachment 336344 [details]
Patch
Comment 3 EWS Watchlist 2018-03-22 19:00:21 PDT
Attachment 336344 [details] did not pass style-queue:


ERROR: Source/WebKit/WebProcess/WebProcess.cpp:223:  Too many spaces inside { }.  [whitespace/braces] [5]
ERROR: Source/WebCore/platform/network/NetworkStorageSession.h:94:  The parameter name "cookieAPI" adds no information, so it should be removed.  [readability/parameter_name] [5]
Total errors found: 2 in 28 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 4 Brent Fulgham 2018-03-22 19:23:42 PDT
Created attachment 336345 [details]
Patch
Comment 5 Brent Fulgham 2018-03-22 20:32:51 PDT
Created attachment 336350 [details]
Patch
Comment 6 Brent Fulgham 2018-03-23 08:35:36 PDT
Created attachment 336375 [details]
Patch
Comment 7 Brent Fulgham 2018-03-23 08:51:06 PDT
WebContent really only uses NetworkStorageSession objects to know which Session ID to use when talking to the Network process.

It would be nice if NetworkStorageSession had two flavors -- one for use in the WebContent process, which didn't have any networking features in it, and another for the Network process, which could own the various platform networking API objects.
Comment 8 youenn fablet 2018-03-23 10:37:50 PDT
Comment on attachment 336375 [details]
Patch

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

> Source/WebCore/platform/network/NetworkStorageSession.h:73
> +    enum class CookieAPI { Allowed, NotAllowed };

Maybe CookieAPIAccess would be clearer?

> Source/WebCore/platform/network/NetworkStorageSession.h:94
> +    NetworkStorageSession(PAL::SessionID, RetainPtr<CFURLStorageSessionRef>&&, RetainPtr<CFHTTPCookieStorageRef>&&, CookieAPI);

With this API, it seems that we could have in the same process some NetworkStorageSession that have Cookie API access and some NetworkStorageSession that do not have Cookie API access. Is it what we want?

If not, I wonder whether, instead of passing a parameter, we could have a process wide singleton telling whether CookieAPI access is allowed.
Then we could check it at the right places without passing this value.

Something like a static CookieAPI::isAllowed() and a corresponding setter that would also check the assertion.
Or directly using the hasPriviledge function.

> Source/WebCore/platform/network/NetworkStorageSession.h:95
> +    NetworkStorageSession(PAL::SessionID);

explicit

> Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp:82
> +    m_platformCookieStorage = platformCookieStorage ? WTFMove(platformCookieStorage) : cookieAPI == CookieAPI::Allowed ? cookieStorage() : nullptr;

If cookieAPI access is not allowed, should platformCookieStorage be null? Should we assert it?
Comment 9 Brent Fulgham 2018-03-23 12:47:57 PDT
Created attachment 336407 [details]
Patch
Comment 10 Brent Fulgham 2018-03-23 15:31:16 PDT
Created attachment 336433 [details]
Patch
Comment 11 youenn fablet 2018-03-23 15:41:17 PDT
Comment on attachment 336433 [details]
Patch

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

> Source/WebKit/UIProcess/WebProcessPool.cpp:248
> +    WebCore::NetworkStorageSession::permitProcessToUseCookieAPI(true);

We could probably use std::call_once here.
Is it soon enough though?
Can there be a way to use some Cookie API that would need that permission before creating a WebProcessPool?
Comment 12 Brent Fulgham 2018-03-23 16:10:09 PDT
Created attachment 336437 [details]
Patch
Comment 13 youenn fablet 2018-03-23 16:52:00 PDT
Comment on attachment 336437 [details]
Patch

r=me.
It would be nice to check that if we create a website data store, get a cookie store and modify it, we do not hit those assertions. The WebProcessPool relaxing code is probably happening too late in that scenario.
An API test would tell us.
Comment 14 EWS Watchlist 2018-03-23 18:18:08 PDT
Comment on attachment 336437 [details]
Patch

Attachment 336437 [details] did not pass win-ews (win):
Output: http://webkit-queues.webkit.org/results/7081747

Number of test failures exceeded the failure limit.
Comment 15 EWS Watchlist 2018-03-23 18:18:10 PDT
Created attachment 336449 [details]
Archive of layout-test-results from ews204 for win-future

The attached test failures were seen while running run-webkit-tests on the win-ews.
Bot: ews204  Port: win-future  Platform: CYGWIN_NT-6.1-2.9.0-0.318-5-3-x86_64-64bit
Comment 16 Brent Fulgham 2018-03-26 10:18:12 PDT
Created attachment 336523 [details]
Patch for landing
Comment 17 WebKit Commit Bot 2018-03-26 10:55:50 PDT
Comment on attachment 336523 [details]
Patch for landing

Clearing flags on attachment: 336523

Committed r229978: <https://trac.webkit.org/changeset/229978>
Comment 18 WebKit Commit Bot 2018-03-26 10:55:52 PDT
All reviewed patches have been landed.  Closing bug.