Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Fix #5860: Add window.caches blocking when cookie blocking is enabled #5870

Merged
merged 1 commit into from
Aug 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Client/Frontend/UserContent/UserScripts/CookieControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,24 @@ if (Object.getOwnPropertyDescriptor(window, 'sessionStorage')) {
},
});
}

(() => {
// Access to caches should be denied when user has blocked all Cookies.
const makeFailingPromiseFunction = () => {
cuba marked this conversation as resolved.
Show resolved Hide resolved
return function () {
return Promise.reject(
new DOMException('An attempt was made to break through the security policy of the user agent.')
)
}
}

// We need to check that window.caches is defined as this API was only added in iOS 15
// Later on we can probably remove this check.
if (window.caches !== undefined) {
window.CacheStorage.prototype.match = makeFailingPromiseFunction()
window.CacheStorage.prototype.has = makeFailingPromiseFunction()
window.CacheStorage.prototype.delete = makeFailingPromiseFunction()
window.CacheStorage.prototype.open = makeFailingPromiseFunction()
window.CacheStorage.prototype.keys = makeFailingPromiseFunction()
}
})()