Bug 238158 - Check if origin can access storage in Storage API
Summary: Check if origin can access storage in Storage API
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Website Storage (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Sihui Liu
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-03-21 15:41 PDT by Sihui Liu
Modified: 2022-03-22 16:59 PDT (History)
4 users (show)

See Also:


Attachments
Patch (6.38 KB, patch)
2022-03-21 15:44 PDT, Sihui Liu
no flags Details | Formatted Diff | Diff
Patch (6.37 KB, patch)
2022-03-21 15:47 PDT, Sihui Liu
no flags Details | Formatted Diff | Diff
Patch for landing (6.76 KB, patch)
2022-03-22 14:40 PDT, Sihui Liu
ews-feeder: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
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>