Bug 183577

Summary: Resource Load Statistics: Immediately forward cookie access at user interaction when there's an opener document
Product: WebKit Reporter: John Wilander <wilander>
Component: WebKit Misc.Assignee: John Wilander <wilander>
Status: RESOLVED FIXED    
Severity: Normal CC: bfulgham, cdumez, commit-queue, dbates, esprehn+autocc, ews-watchlist, japhet, kangil.han, 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=183578
https://bugs.webkit.org/show_bug.cgi?id=183620
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch for landing none

Description John Wilander 2018-03-12 13:41:47 PDT
We should shortcut forwarding of user interaction when there's an opener document instead of capturing the interaction as "statistics." This will fix compatibility issues where popups talk to a cross-origin opener document.
Comment 1 John Wilander 2018-03-12 13:42:11 PDT
<rdar://problem/38266987>
Comment 2 John Wilander 2018-03-12 14:19:45 PDT
Created attachment 335639 [details]
Patch
Comment 3 Brent Fulgham 2018-03-12 14:50:03 PDT
/Volumes/Data/EWS/WebKit/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp:776:73: error: no member named 'hasStorageAccess' in 'WebCore::NetworkStorageSession'
    bool hasStorageAccess = (frameID && pageID) ? networkStorageSession.hasStorageAccess(url.string(), partition.string(), frameID.value(), pageID.value()) : false;
                                                  ~~~~~~~~~~~~~~~~~~~~~ ^
1 error generated.
Comment 4 Brent Fulgham 2018-03-12 14:52:30 PDT
Comment on attachment 335639 [details]
Patch

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

Looks like the patch is missing NetworkStorageSession changes!

> Source/WebKit/NetworkProcess/NetworkProcess.cpp:371
> +        parentProcessConnection()->send(Messages::NetworkProcessProxy::StorageAccessRequestResult(networkStorageSession->hasStorageAccess(resourceDomain, firstPartyDomain, frameID, pageID), contextId), 0);

It looks like you are missing the change to NetworkStorageSession that renames 'hasStorageAccessForFrame' -> 'hasStorageAccess'.
Comment 5 John Wilander 2018-03-12 16:03:59 PDT
:) I was in the Source/WebKit directory when I uploaded. Sorry about that. New patch coming up.
Comment 6 John Wilander 2018-03-12 16:04:40 PDT
Created attachment 335659 [details]
Patch
Comment 7 John Wilander 2018-03-12 16:23:40 PDT
I'll put the opener check behind #if HAVE(CFNETWORK_STORAGE_PARTITIONING) to fix the GTK issue.
Comment 8 John Wilander 2018-03-12 16:24:43 PDT
Created attachment 335661 [details]
Patch
Comment 9 Brent Fulgham 2018-03-12 16:45:35 PDT
Comment on attachment 335661 [details]
Patch

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

This looks good, but I'm worried you have a mistake in iterator handling in NetworkStorageSession::grantStorageAccess. Can you please fix that before landing?

> Source/WebCore/ChangeLog:12
> +        in the popup.

I would mention that there are manual tests for this, just to make it clear that this is not untested code. :-)

> Source/WebCore/loader/ResourceLoadObserver.cpp:324
> +                if (std::optional<uint64_t> openerPageID = openerFrame->loader().client().pageID()) {

auto openerPageID = ...

> Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp:319
> +        auto it1 = m_pagesGrantedStorageAccess.find(pageID);

auto pagesGrantedIterator = ...

> Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp:325
> +            auto it2 = it1->value.find(firstPartyDomain);

What if it2 is it1->value.end()? Crash!

Should you ASSERT here (if it's unthinkable that will happen)? Or, just check we aren't past the end of the container before trying to set the value.

> Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp:337
> +        auto it2 = it1->value.find(frameID.value());

What if it2 is it1->value.end()? This will crash!

Ditto recommendations above.
Comment 10 John Wilander 2018-03-12 18:03:40 PDT
Created attachment 335669 [details]
Patch for landing
Comment 11 John Wilander 2018-03-12 18:04:49 PDT
(In reply to Brent Fulgham from comment #9)
> Comment on attachment 335661 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=335661&action=review
> 
> This looks good, but I'm worried you have a mistake in iterator handling in
> NetworkStorageSession::grantStorageAccess. Can you please fix that before
> landing?
> 
> > Source/WebCore/ChangeLog:12
> > +        in the popup.
> 
> I would mention that there are manual tests for this, just to make it clear
> that this is not untested code. :-)

Fixed.
 
> > Source/WebCore/loader/ResourceLoadObserver.cpp:324
> > +                if (std::optional<uint64_t> openerPageID = openerFrame->loader().client().pageID()) {
> 
> auto openerPageID = ...

Fixed.

> > Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp:319
> > +        auto it1 = m_pagesGrantedStorageAccess.find(pageID);
> 
> auto pagesGrantedIterator = ...

Fixed.

> 
> > Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp:325
> > +            auto it2 = it1->value.find(firstPartyDomain);
> 
> What if it2 is it1->value.end()? Crash!
> 
> Should you ASSERT here (if it's unthinkable that will happen)? Or, just
> check we aren't past the end of the container before trying to set the value.

Fixed.

> 
> > Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp:337
> > +        auto it2 = it1->value.find(frameID.value());
> 
> What if it2 is it1->value.end()? This will crash!
> 
> Ditto recommendations above.

Fixed.

Thanks, Brent!
Comment 12 WebKit Commit Bot 2018-03-12 19:06:01 PDT
Comment on attachment 335669 [details]
Patch for landing

Clearing flags on attachment: 335669

Committed r229569: <https://trac.webkit.org/changeset/229569>
Comment 13 WebKit Commit Bot 2018-03-12 19:06:03 PDT
All reviewed patches have been landed.  Closing bug.