Bug 238158

Summary: Check if origin can access storage in Storage API
Product: WebKit Reporter: Sihui Liu <sihui_liu>
Component: Website StorageAssignee: Sihui Liu <sihui_liu>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, cdumez, sihui_liu, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch for landing ews-feeder: commit-queue-

Comment 1 Sihui Liu 2022-03-21 15:44:26 PDT
Created attachment 455287 [details]
Patch
Comment 2 Sihui Liu 2022-03-21 15:47:07 PDT
Created attachment 455288 [details]
Patch
Comment 3 Chris Dumez 2022-03-21 19:54:22 PDT
Comment on attachment 455288 [details]
Patch

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

> Source/WebCore/Modules/storage/StorageManager.cpp:73
> +    if (!origin->canAccessStorage())

The spec merely says to check if the origin is opaque (which we call unique in WebKit). Why not simply check `origin->isUnique()` ?

> Source/WebCore/page/SecurityOrigin.h:154
> +    bool canAccessStorage() const { return canAccessStorage(nullptr); }

There is a comment inside canAccessStorage() saying that we should stop passing nullptr so this may not be a change in the right direction.
Comment 4 Sihui Liu 2022-03-22 09:45:00 PDT
(In reply to Chris Dumez from comment #3)
> Comment on attachment 455288 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=455288&action=review
> 
> > Source/WebCore/Modules/storage/StorageManager.cpp:73
> > +    if (!origin->canAccessStorage())
> 
> The spec merely says to check if the origin is opaque (which we call unique
> in WebKit). Why not simply check `origin->isUnique()` ?

I see the other APIs using canAccessStorage to check so I use it for consistency.
I guess we can only check if origin is unique, though I don't know why we can ignore storage blocking policy for Storage API.

> 
> > Source/WebCore/page/SecurityOrigin.h:154
> > +    bool canAccessStorage() const { return canAccessStorage(nullptr); }
> 
> There is a comment inside canAccessStorage() saying that we should stop
> passing nullptr so this may not be a change in the right direction.
Comment 5 Chris Dumez 2022-03-22 09:54:43 PDT
Comment on attachment 455288 [details]
Patch

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

>>> Source/WebCore/Modules/storage/StorageManager.cpp:73
>>> +    if (!origin->canAccessStorage())
>> 
>> The spec merely says to check if the origin is opaque (which we call unique in WebKit). Why not simply check `origin->isUnique()` ?
> 
> I see the other APIs using canAccessStorage to check so I use it for consistency.
> I guess we can only check if origin is unique, though I don't know why we can ignore storage blocking policy for Storage API.

Ok, so you want to do more checks that simply opaque origin, is that right? The change log doesn't say anything about that (and neither does the spec).

The change may well be correct if so.
Comment 6 Sihui Liu 2022-03-22 10:23:05 PDT
(In reply to Chris Dumez from comment #5)
> Comment on attachment 455288 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=455288&action=review
> 
> >>> Source/WebCore/Modules/storage/StorageManager.cpp:73
> >>> +    if (!origin->canAccessStorage())
> >> 
> >> The spec merely says to check if the origin is opaque (which we call unique in WebKit). Why not simply check `origin->isUnique()` ?
> > 
> > I see the other APIs using canAccessStorage to check so I use it for consistency.
> > I guess we can only check if origin is unique, though I don't know why we can ignore storage blocking policy for Storage API.
> 
> Ok, so you want to do more checks that simply opaque origin, is that right?
> The change log doesn't say anything about that (and neither does the spec).
> 
> The change may well be correct if so.

Yes, I would like to make this consistent with IndexedDB, whose spec only says about opaque origin(https://www.w3.org/TR/IndexedDB/#dom-idbfactory-open), but we also check storage blocking policy of the origin (we don't check its top origin, so we pass nullptr). I will update changelog to include this.
Comment 7 Chris Dumez 2022-03-22 10:23:38 PDT
Comment on attachment 455288 [details]
Patch

Ok.
Comment 8 Sihui Liu 2022-03-22 14:40:09 PDT
Created attachment 455429 [details]
Patch for landing
Comment 9 EWS 2022-03-22 16:54:30 PDT
Committed r291726 (248758@main): <https://commits.webkit.org/248758@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 455429 [details].
Comment 10 Radar WebKit Bug Importer 2022-03-22 16:55:15 PDT
<rdar://problem/90667430>