fix: enforce service worker cache allowlist
CodeQL Analysis / Analyze CodeQL (push) Has been cancelled
Deploy Application / deploy (push) Has been cancelled
Mirror to Codeberg / mirror (push) Has been cancelled
Mirror to PrivacyGuides / mirror (push) Has been cancelled

This commit is contained in:
lockbitchat
2026-05-17 23:22:46 -04:00
parent f2a4276b31
commit ad3bee5f2e
+14 -2
View File
@@ -286,7 +286,12 @@ async function handleRequest(request) {
try {
// Strategy 1: Cache First (only for essential PWA assets)
if (CACHE_FIRST_PATTERNS.some(pattern => pattern.test(url.pathname))) {
if (
url.origin === self.location.origin &&
isCacheableStaticPath(url.pathname) &&
!isSensitivePath(url.pathname) &&
CACHE_FIRST_PATTERNS.some(pattern => pattern.test(url.pathname))
) {
return await cacheFirst(request);
}
@@ -306,6 +311,7 @@ async function handleRequest(request) {
// Cache First strategy with Response cloning fix
async function cacheFirst(request) {
const url = new URL(request.url);
const cachedResponse = await caches.match(request);
if (cachedResponse) {
return cachedResponse;
@@ -313,7 +319,13 @@ async function cacheFirst(request) {
try {
const networkResponse = await fetch(request);
if (networkResponse && networkResponse.ok) {
if (
networkResponse &&
networkResponse.ok &&
url.origin === self.location.origin &&
isCacheableStaticPath(url.pathname) &&
!isSensitivePath(url.pathname)
) {
// Clone the response before using it
const responseToCache = networkResponse.clone();
const cache = await caches.open(STATIC_CACHE);