<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>207545</bug_id>
          
          <creation_ts>2020-02-11 06:44:49 -0800</creation_ts>
          <short_desc>Blocking Access to LocalStorage and SessionStorage for specific web-sites or for all websites doesn&apos;t work 100% of the time</short_desc>
          <delta_ts>2024-07-09 07:23:20 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebKit API</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>iPhone / iPad</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Enhancement</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Brandon">bthomas</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>achristensen</cc>
    
    <cc>appledeveloper</cc>
    
    <cc>beidson</cc>
    
    <cc>krzysztof.modras</cc>
    
    <cc>mjs</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1617362</commentid>
    <comment_count>0</comment_count>
    <who name="Brandon">bthomas</who>
    <bug_when>2020-02-11 06:44:49 -0800</bug_when>
    <thetext>In order to block LocalStorage access or SessionStorage, developers need to inject some Javascript like like:
```
var localStorage = Object.getOwnPropertyDescriptor(window, &apos;localStorage&apos;);
if (localStorage) {
    Object.defineProperty(window, &apos;localStorage&apos;, {
        get: function() {
            console.error(&quot;Local Storage Blocked&quot;)
            return null;
        },
    });
}

var sessionStorage = Object.getOwnPropertyDescriptor(window, &apos;sessionStorage&apos;);
if (sessionStorage) {
    Object.defineProperty(window, &apos;sessionStorage&apos;, {
        get: function() {
            console.error(&quot;Session Storage Blocked&quot;)
            return null;
        },
    });
}
```

There should be a simpler way to deny a website or anything access to the storage. Currently, there is none.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1617422</commentid>
    <comment_count>1</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2020-02-11 09:23:58 -0800</bug_when>
    <thetext>Thank you for the report!

The title says &quot;... doesn&apos;t work 100% of the time&quot;, can you elaborate on that?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1617423</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2020-02-11 09:24:11 -0800</bug_when>
    <thetext>&lt;rdar://problem/59350812&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1620583</commentid>
    <comment_count>3</comment_count>
    <who name="Maciej Stachowiak">mjs</who>
    <bug_when>2020-02-19 02:24:52 -0800</bug_when>
    <thetext>If you add the cited script as WKUserScript using a WKUserContentController, it should be guaranteed to run before the page does anything. Using `evaluateJavaScript:` and friends instead would race with page loading.

Is there any other way in which the JS solution is not adequate?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2045301</commentid>
    <comment_count>4</comment_count>
    <who name="Brandon">bthomas</who>
    <bug_when>2024-07-09 07:23:20 -0700</bug_when>
    <thetext>The problem is the page can grab the `localStorage` variable from an iFrame.

Example, if you inject the above script into the MAIN frame, but not all frames, then the following is possible:


```
var localStorage = document.querySelector(&apos;iframe&apos;).contentWindow.localStorage;
// Use localStorage to set values
```

This bypass currently works even on iOS 17. So even though you&apos;ve blocked local storage for the main-frame, the main-frame can still access local storage via a secondary frame.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>