-
Notifications
You must be signed in to change notification settings - Fork 434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proxy calls to localStorage.getItem()
for sandboxing and ensuring value is current
#293
Comments
Hey any update on this issue? I find it makes a lot of sense, considering we can control the cookies, I wonder what is the reason to leave localStorage untracked? |
Hi @n0th1ng-else I didn't look at this issue. would you like to drop a PR for that? |
n0th1ng-else
pushed a commit
to n0th1ng-else/partytown
that referenced
this issue
Jan 31, 2024
In the current implementation, we cache both storages (localStorage and sessionStorage) at the moment of worker creation. Although this could be considered as performance optimization, it leads to the implementation inconsistency: - Storages easily go out of sync as there is no proper synchronization with main window setup. - One can not override the storage access easily. FOr the latter point, this means we can not take on the methods like `localStorage.getItem()` in the Partytown proxy methods (specifically in `apply`). Hence there is no way to shield the storage data from 3rd party scripts. In this commit we fully rely on the storage values the main window sends into the worker. As the result, we can always receive relevant value and also can override the storage api with `apply` and `get` hooks
n0th1ng-else
pushed a commit
to n0th1ng-else/partytown
that referenced
this issue
Jan 31, 2024
In the current implementation, we cache both storages (localStorage and sessionStorage) at the moment of worker creation. Although this could be considered as performance optimization, it leads to the implementation inconsistency: - Storages easily go out of sync as there is no proper synchronization with main window setup. - One can not override the storage access easily. For the latter point, this means we can not take on the methods like `localStorage.getItem()` in the Partytown proxy methods (specifically in `apply`). Hence there is no way to shield the storage data from 3rd party scripts. In this commit we fully rely on the storage values the main window sends into the worker. As the result, we can always receive relevant value and also can override the storage api with `apply` and `get` hooks
n0th1ng-else
pushed a commit
to n0th1ng-else/partytown
that referenced
this issue
Jan 31, 2024
In the current implementation, we cache both storages (localStorage and sessionStorage) at the moment of worker creation. Although this could be considered as performance optimization, it leads to the implementation inconsistency: - Storage data leaks into 3rd party script - Storages easily go out of sync as there is no proper synchronization with main window setup. - One can not override the storage access easily. For the latter point, this means we can not take on the methods like `localStorage.getItem()` in the Partytown proxy methods (specifically in `apply`). Hence there is no way to shield the storage data from 3rd party scripts. In this commit we fully rely on the storage values the main window sends into the worker. As the result, we can always receive relevant value and also can override the storage api with `apply` and `get` hooks
n0th1ng-else
added a commit
to n0th1ng-else/partytown
that referenced
this issue
Jan 31, 2024
In the current implementation, we cache both storages (localStorage and sessionStorage) at the moment of worker creation. Although this could be considered as performance optimization, it leads to the implementation inconsistency: - Storages data leaks into 3rd party script - Storages easily go out of sync as there is no proper synchronization with main window setup. - One can not override the storage access easily. For the latter point, this means we can not take on the methods like `localStorage.getItem()` in the Partytown proxy methods (specifically in `apply`). Hence there is no way to shield the storage data from 3rd party scripts. In this commit we fully rely on the storage values the main window sends into the worker. As the result, we can always receive relevant value and also can override the storage api with `apply` and `get` hooks
n0th1ng-else
added a commit
to n0th1ng-else/partytown
that referenced
this issue
Jan 31, 2024
In the current implementation, we cache both storages (localStorage and sessionStorage) at the moment of worker creation. Although this could be considered as performance optimization, it leads to the implementation inconsistency: - Storages data leaks into 3rd party script - Storages easily go out of sync as there is no proper synchronization with main window setup. - One can not override the storage access easily. For the latter point, this means we can not take on the methods like `localStorage.getItem()` in the Partytown proxy methods (specifically in `apply`). Hence there is no way to shield the storage data from 3rd party scripts. In this commit we fully rely on the storage values the main window sends into the worker. As the result, we can always receive relevant value and also can override the storage api with `apply` and `get` hooks
@gioboa could you please check the PR when you have time? looking forward to hear what you think |
n0th1ng-else
added a commit
to n0th1ng-else/partytown
that referenced
this issue
Feb 1, 2024
In the current implementation, we cache both storages (localStorage and sessionStorage) at the moment of worker creation. Although this could be considered as performance optimization, it leads to the implementation inconsistency: - Storages data leaks into 3rd party script - Storages easily go out of sync as there is no proper synchronization with main window setup. - One can not override the storage access easily. For the latter point, this means we can not take on the methods like `localStorage.getItem()` in the Partytown proxy methods (specifically in `apply`). Hence there is no way to shield the storage data from 3rd party scripts. In this commit we fully rely on the storage values the main window sends into the worker. As the result, we can always receive relevant value and also can override the storage api with `apply` and `get` hooks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
I was experimenting with sandboxing a script to block access to
localStorage
, but I found that this was not currently possible. Namely I configured Partytown as follows:I then had this script on the page:
In the console I then see only these calls logged out:
The call to
localStorage.getItem
is missing. This appears to have been done intentionally, as the entirelocalStorage
data is sent to the worker when it is initialized:partytown/src/lib/sandbox/read-main-platform.ts
Lines 74 to 81 in ab532e6
The initially-synced value is then referred referenced locally instead of invoking
callMethod
to obtain the value from the main thread:partytown/src/lib/web-worker/worker-storage.ts
Lines 24 to 42 in 4740cea
Was this done for the sake of performance?
As it stands right now, it is quite possible for the storage in the worker to get out of sync with the storage in the main thread. If the main thread calls
localStorage.setItem()
after the worker is initialized, the stored value is not seen in the worker. There would seem at least a need to add astorage
event listener on the main thread and continuously sync changes back to the copy in the worker. Nevertheless, this could be avoided if calls tolocalStorage.getItem()
were proxied. This would also eliminate duplication of thelocalStorage
data, reducing memory usage (although at the cost of slower execution time).Describe the solution you'd like
Discontinue sending the entire
localStorage
andsessionStorage
datasets into the worker at initialization, and instead proxy all calls togetItem
to obtain the canonical current value from the main thread.The text was updated successfully, but these errors were encountered: