diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5389475604..044ec64ee4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -237,6 +237,8 @@ jobs: done mysql -h "$DATASOURCES_TEST_HOST" -u root -p"$MYSQL_ROOT_PASSWORD" -e "ALTER USER '$DATASOURCES_TEST_USERNAME'@'%' IDENTIFIED BY '$DATASOURCES_TEST_PASSWORD';" mysql -h "$DATASOURCES_TEST_HOST" -u root -p"$MYSQL_ROOT_PASSWORD" -e "GRANT ALL ON *.* TO '$DATASOURCES_TEST_USERNAME'@'%';" + mysql -h "$DATASOURCES_TEST_HOST" -u root -p"$MYSQL_ROOT_PASSWORD" -e "GRANT PROCESS ON *.* TO '$DATASOURCES_TEST_USERNAME'@'%';" + mysql -h "$DATASOURCES_TEST_HOST" -u root -p"$MYSQL_ROOT_PASSWORD" -e "FLUSH PRIVILEGES;" mysql -h "$DATASOURCES_TEST_HOST" -u root -p"$MYSQL_ROOT_PASSWORD" -e "SET GLOBAL log_bin_trust_function_creators = 1;" env: MYSQL_ROOT_PASSWORD: testing-password2 @@ -547,6 +549,7 @@ jobs: mysql -h "$DATASOURCES_TEST_HOST" -u root -p"$MARIADB_ROOT_PASSWORD" -e "ALTER USER '$DATASOURCES_TEST_USERNAME'@'%' IDENTIFIED BY '$DATASOURCES_TEST_PASSWORD';" mysql -h "$DATASOURCES_TEST_HOST" -u root -p"$MARIADB_ROOT_PASSWORD" -e "GRANT ALL ON *.* TO '$DATASOURCES_TEST_USERNAME'@'%';" mysql -h "$DATASOURCES_TEST_HOST" -u root -p"$MARIADB_ROOT_PASSWORD" -e "GRANT PROCESS ON *.* TO '$DATASOURCES_TEST_USERNAME'@'%';" + mysql -h "$DATASOURCES_TEST_HOST" -u root -p"$MARIADB_ROOT_PASSWORD" -e "FLUSH PRIVILEGES;" mysql -h "$DATASOURCES_TEST_HOST" -u root -p"$MARIADB_ROOT_PASSWORD" -e "SET GLOBAL log_bin_trust_function_creators = 1;" env: MARIADB_ROOT_PASSWORD: testing-password2 diff --git a/CHANGELOG.md b/CHANGELOG.md index fa28eb155a..b65a554e45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,17 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [6.1.3] - 2026-10-26 +### Fixed +- Fix CSP violation by extracting Service Worker registration into standalone `/js/app/service-worker-register.js` +- Bump App Shell cache to `passly-app-shell-v3` with precache registration script + +## [6.1.2] - 2026-10-25 +### Added +- Enhance App Shell Service Worker v2 with complete precache suite (api-vendors, api-triage, api-app, stylesheets) +- Implement quick network timeout and instant App Shell fallback to eliminate ERR_INTERNET_DISCONNECTED +- Register Service Worker across all layouts including login and default templates + ## [6.1.0] - 2026-10-15 ### Added - Add perpetual offline mode settings and defaults for unlimited session duration, retention, and items diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 4b442b7f7b..d1668f35fa 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,15 +1,15 @@ -Passly 6.1.0 introduces perpetual offline mode support, delta synchronization endpoints, recoverable resource trash API, and CakePHP 5.4 framework upgrades. +Passly 6.1.3 delivers standalone Service Worker registration conforming to strict Content Security Policies, App Shell precache enhancements, and offline resilience improvements. -This release delivers the backend capabilities for offline vault access with perpetual defaults (unlimited session duration, data retention, and item counts), high-efficiency sync endpoints (/sync/meta and /sync/changes) with change journaling, and recoverable trash for resources. - -## Highlights -Perpetual offline mode defaults are enabled, supporting unlimited session duration, unlimited data retention, and unlimited items. - -Delta synchronization endpoints (/sync/meta and /sync/changes) and change journal logging are introduced to accelerate client sync. - -Recoverable resource trash API allows moving resources to trash and restoring them. +## [6.1.3] - 2026-10-26 +### Fixed +- Fix CSP violation by extracting Service Worker registration into standalone `/js/app/service-worker-register.js` +- Bump App Shell cache to `passly-app-shell-v3` with precache registration script -Framework upgraded to CakePHP 5.4 with automatic Request to DTO mapping and refreshed upstream CE core logic. +## [6.1.2] - 2026-10-25 +### Added +- Enhance App Shell Service Worker v2 with complete precache suite (api-vendors, api-triage, api-app, stylesheets) +- Implement quick network timeout and instant App Shell fallback to eliminate ERR_INTERNET_DISCONNECTED +- Register Service Worker across all layouts including login and default templates ## [6.1.0] - 2026-10-15 ### Added diff --git a/config/version.php b/config/version.php index 7d6698b435..c5420a7436 100644 --- a/config/version.php +++ b/config/version.php @@ -1,8 +1,8 @@ [ - 'version' => '6.1.0', - 'name' => 'Passly 6.1.0', + 'version' => '6.1.3', + 'name' => 'Passly 6.1.3', 'edition' => 'ce', ], 'php' => [ diff --git a/templates/layout/default.php b/templates/layout/default.php index daec152c4c..a473e82ec4 100644 --- a/templates/layout/default.php +++ b/templates/layout/default.php @@ -30,5 +30,6 @@ fetch('content'); ?> fetch('scriptBottom'); ?> + diff --git a/templates/layout/login.php b/templates/layout/login.php index 47b6fc9996..6fcc7787ac 100644 --- a/templates/layout/login.php +++ b/templates/layout/login.php @@ -33,5 +33,6 @@ element('Footer/default'); ?> + diff --git a/webroot/js/app/service-worker-register.js b/webroot/js/app/service-worker-register.js new file mode 100644 index 0000000000..0b036177c0 --- /dev/null +++ b/webroot/js/app/service-worker-register.js @@ -0,0 +1,24 @@ +/** + * Passly - Open source password manager for teams + * Copyright (c) 2026 Svaroh + * + * Licensed under GNU Affero General Public License version 3 of the or any later version. + * For full copyright and license information, please see the LICENSE.txt + * Redistributions of files must retain the above copyright notice. + * + * @copyright Copyright (c) Svaroh + * @license https://opensource.org/licenses/AGPL-3.0 AGPL License + * @link https://passly.svaroh.net Passly + */ + +if ('serviceWorker' in navigator) { + window.addEventListener('load', function() { + navigator.serviceWorker.register('/service-worker.js', { scope: '/' }) + .then(function(registration) { + console.debug('Passly App Shell Service Worker registered successfully with scope:', registration.scope); + }) + .catch(function(error) { + console.warn('Passly App Shell Service Worker registration failed:', error); + }); + }); +} diff --git a/webroot/service-worker.js b/webroot/service-worker.js new file mode 100644 index 0000000000..e010ff5b5b --- /dev/null +++ b/webroot/service-worker.js @@ -0,0 +1,210 @@ +/** + * Passly - Open source password manager for teams + * Copyright (c) 2026 Svaroh + * + * Licensed under GNU Affero General Public License version 3 of the or any later version. + * For full copyright and license information, please see the LICENSE.txt + * Redistributions of files must retain the above copyright notice. + * + * @copyright Copyright (c) Svaroh + * @license https://opensource.org/licenses/AGPL-3.0 AGPL License + * @link https://passly.svaroh.net Passly + */ + +const CACHE_NAME = 'passly-app-shell-v3'; + +const PRECACHE_ASSETS = [ + '/', + '/auth/login', + '/app/passwords', + '/favicon.ico', + '/favicon.svg', + '/favicon_32.png', + '/favicon_57.png', + '/favicon_76.png', + '/favicon_96.png', + '/favicon_128.png', + '/favicon_192.png', + '/favicon_228.png', + '/js/app/service-worker-register.js', + '/js/app/stylesheet.js', + '/js/app/api-vendors.js', + '/js/app/api-triage.js', + '/js/app/api-app.js', + '/css/themes/default/api_main.min.css', + '/css/themes/default/api_authentication.min.css', + '/css/themes/default/ext_authentication.min.css', + '/css/themes/midgar/api_main.min.css', + '/css/themes/midgar/api_authentication.min.css' +]; + +self.addEventListener('install', (event) => { + self.skipWaiting(); + event.waitUntil( + caches.open(CACHE_NAME).then((cache) => { + return Promise.allSettled( + PRECACHE_ASSETS.map((url) => + cache.add(new Request(url, { credentials: 'same-origin' })).catch((err) => { + console.warn(`[ServiceWorker] Failed to precache asset ${url}:`, err); + }) + ) + ); + }) + ); +}); + +self.addEventListener('activate', (event) => { + event.waitUntil( + Promise.all([ + self.clients.claim(), + caches.keys().then((cacheNames) => + Promise.all( + cacheNames.map((name) => { + if (name.startsWith('passly-') && name !== CACHE_NAME) { + return caches.delete(name); + } + return null; + }) + ) + ) + ]) + ); +}); + +self.addEventListener('fetch', (event) => { + const request = event.request; + + // Only handle GET requests + if (request.method !== 'GET') { + return; + } + + const url = new URL(request.url); + + // Ignore cross-origin requests + if (url.origin !== self.location.origin) { + return; + } + + // API endpoints and dynamic json calls must not be served stale from cache + const isApiRequest = + url.pathname.endsWith('.json') || + url.pathname.startsWith('/auth/is-authenticated') || + url.pathname.startsWith('/auth/verify') || + url.pathname.startsWith('/healthcheck'); + + if (isApiRequest) { + event.respondWith( + fetch(request).catch(() => { + return new Response( + JSON.stringify({ + header: { + status: 'error', + title: 'Offline', + message: 'You are currently offline. Local replica and cached vault state are active.', + code: 503 + }, + body: { + isOffline: true + } + }), + { + status: 503, + headers: { 'Content-Type': 'application/json; charset=utf-8' } + } + ); + }) + ); + return; + } + + // Navigation requests: Network-First with quick timeout and fallback to cached App Shell + if ( + request.mode === 'navigate' || + (request.headers.get('accept') && request.headers.get('accept').includes('text/html')) + ) { + event.respondWith( + (async () => { + try { + const fetchPromise = fetch(request); + // 2.5s network timeout for sluggish/offline connections before falling back to cached shell + const timeoutPromise = new Promise((_, reject) => + setTimeout(() => reject(new Error('Network timeout')), 2500) + ); + + const networkResponse = await Promise.race([fetchPromise, timeoutPromise]); + if (networkResponse && networkResponse.status === 200) { + const cache = await caches.open(CACHE_NAME); + cache.put(request, networkResponse.clone()); + return networkResponse; + } + if (networkResponse && networkResponse.status >= 400) { + // In case server returns 404/500, check if we have a valid cached shell + const cache = await caches.open(CACHE_NAME); + const cached = (await cache.match(request)) || (await cache.match('/auth/login')) || (await cache.match('/')); + if (cached) { + return cached; + } + } + return networkResponse; + } catch (_err) { + // Network failed or offline: serve cached App Shell immediately + const cache = await caches.open(CACHE_NAME); + + // 1. Try exact match + const exactMatch = await cache.match(request); + if (exactMatch) { + return exactMatch; + } + + // 2. Route to relevant cached App Shell + if (url.pathname.startsWith('/auth/login') || url.pathname === '/') { + const loginPage = (await cache.match('/auth/login')) || (await cache.match('/')); + if (loginPage) { + return loginPage; + } + } + + const appShell = + (await cache.match('/app/passwords')) || + (await cache.match('/auth/login')) || + (await cache.match('/')); + + if (appShell) { + return appShell; + } + + return new Response( + 'Passly Offline

Passly Offline App Shell

Server is offline. Vault cache is available.

', + { + status: 200, + headers: { 'Content-Type': 'text/html; charset=utf-8' } + } + ); + } + })() + ); + return; + } + + // Static assets (CSS, JS, fonts, images): Cache-First with background revalidation + const isStaticAsset = url.pathname.match(/\.(css|js|png|svg|ico|woff|woff2|ttf|eot)$/i); + if (isStaticAsset) { + event.respondWith( + caches.open(CACHE_NAME).then(async (cache) => { + // Strip cache busters query string if needed for matching + const cachedResponse = (await cache.match(request)) || (await cache.match(url.pathname)); + const fetchPromise = fetch(request) + .then((networkResponse) => { + if (networkResponse && networkResponse.status === 200) { + cache.put(request, networkResponse.clone()); + } + return networkResponse; + }) + .catch(() => null); + + return cachedResponse || (await fetchPromise); + }) + ); + } +});