Makes the offline-first vault installable as a standalone PWA, and enforces "no network access aside from the app's own resources" once installed. PWA: - public/manifest.webmanifest: scope ./ (confined to the app's own dir), three icons (192/512 + transparent maskable), standalone display, brand theme. No push/shortcuts (deliberate: offline-first vault, nothing to push). - public/sw.js: a NETWORK SANDBOX service worker. Allows only same-origin requests inside the worker's own directory (index, manifest, icons); returns 403 for every cross-origin request and for same-origin paths outside the app dir. This blocks in-app <img>/<script>/fetch exfiltration at the source. - src/lib/pwa.js + main.js: register the worker (relative path, works at / in dev and under /password_manager/ in prod). - index.html: dev CSP (permits Vite HMR WebSocket) + PWA meta/link tags. Security: - scripts/inline-assets.js swaps the dev CSP for the STRICT production CSP in the shipped dist: connect-src 'none' (no fetch/XHR/WebSockets anywhere), form-action 'none', object-src/base-uri 'none', img/font/media 'self' data:. The browser-native connect-src closes the WebSocket gap the SW cannot see. - Known boundary documented in-file: frame-ancestors / X-Frame-Options is HTTP-header-only (ignored in meta) and not set by the static host, so clickjacking is permissive; all exfiltration channels are closed regardless. Build/deploy: - inline-assets.js now PRESERVES manifest/sw.js/icons in dist (was deleting). - deploy.yml uploads + byte-verifies index.html, manifest, sw.js, and all three icons to WebDAV. Tests: - tests/lib/sw-policy.test.js: 5 tests for the sandbox allow/deny logic (in-scope allowed; cross-origin, out-of-scope, scheme/port mismatch denied). - Verified in headless Chromium against the built dist: SW registers + is active, and both a cross-origin fetch and a same-origin-out-of-scope fetch are refused by the CSP before leaving the device. Fixup: dropped 'frame-ancestors' from the meta CSP after confirming the browser ignores it there (it is a header-only directive).
118 lines
4.9 KiB
YAML
118 lines
4.9 KiB
YAML
name: Test, Build & Deploy
|
|
|
|
# Tests + build run on every push/PR; the deploy (WebDAV publish of the
|
|
# single-file dist/index.html) runs only on the default branch (main).
|
|
"on":
|
|
push:
|
|
branches:
|
|
- '**'
|
|
pull_request:
|
|
|
|
jobs:
|
|
test-and-build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Setup Node
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '20'
|
|
|
|
- name: Install dependencies
|
|
run: npm ci
|
|
|
|
- name: Run tests
|
|
run: npm run test:run
|
|
|
|
- name: Build (single-file bundle)
|
|
env:
|
|
VITE_COMMIT_HASH: ${{ github.sha }}
|
|
run: npm run build
|
|
|
|
- name: Verify build output
|
|
run: test -f dist/index.html
|
|
|
|
deploy:
|
|
# Release the built app only when a commit lands on the default branch.
|
|
needs: test-and-build
|
|
if: github.ref == 'refs/heads/main'
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Setup Node
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '20'
|
|
|
|
- name: Install dependencies
|
|
run: npm ci
|
|
|
|
- name: Build (single-file bundle)
|
|
env:
|
|
VITE_COMMIT_HASH: ${{ github.sha }}
|
|
run: npm run build
|
|
|
|
- name: Verify build output
|
|
run: test -f dist/index.html
|
|
|
|
# Publish index.html + PWA companion files (manifest, sandbox service
|
|
# worker, icons) to the WebDAV mirror. The pretty URL
|
|
# (…/password_manager/index.html) 401s without auth; files live at
|
|
# www/static/password_manager/<name> with basic auth.
|
|
- name: Publish to WebDAV (/password_manager)
|
|
env:
|
|
WEBDAV_USER: ${{ secrets.WEBDAV_USER }}
|
|
WEBDAV_PASS: ${{ secrets.WEBDAV_PASS }}
|
|
WEBDAV_BASE: https://files.thecookiejar.me/www/static/password_manager
|
|
run: |
|
|
set -e
|
|
if [ -z "$WEBDAV_USER" ] || [ -z "$WEBDAV_PASS" ]; then
|
|
echo "::error::WEBDAV_USER / WEBDAV_PASS repo secrets are not set."
|
|
echo "::error::Add them under Settings -> Actions -> Secrets, then re-run this job."
|
|
exit 1
|
|
fi
|
|
publish() {
|
|
local src="$1" dst="$2" ctype="$3"
|
|
# DELETE-then-PUT: the serving layer caches uploaded files, so a plain
|
|
# PUT over an existing file keeps serving the OLD copy.
|
|
curl -sS -u "$WEBDAV_USER:$WEBDAV_PASS" -X DELETE "$dst" || echo "(DELETE non-zero; may be a new file -- continuing)"
|
|
curl -sS --fail -u "$WEBDAV_USER:$WEBDAV_PASS" -X PUT -T "$src" -H "Content-Type: $ctype" "$dst"
|
|
echo "Published $src -> $dst"
|
|
}
|
|
# Ensure the icons/ subfolder exists.
|
|
curl -sS -u "$WEBDAV_USER:$WEBDAV_PASS" -X MKCOL "$WEBDAV_BASE/icons" -o /dev/null || echo "(icons dir exists or MKCOL unsupported -- continuing)"
|
|
publish dist/index.html "$WEBDAV_BASE/index.html" 'text/html'
|
|
publish dist/manifest.webmanifest "$WEBDAV_BASE/manifest.webmanifest" 'application/manifest+json'
|
|
publish dist/sw.js "$WEBDAV_BASE/sw.js" 'application/javascript; charset=utf-8'
|
|
publish dist/icons/icon-192.png "$WEBDAV_BASE/icons/icon-192.png" 'image/png'
|
|
publish dist/icons/icon-512.png "$WEBDAV_BASE/icons/icon-512.png" 'image/png'
|
|
publish dist/icons/icon-maskable-512.png "$WEBDAV_BASE/icons/icon-maskable-512.png" 'image/png'
|
|
|
|
# Pull the freshly uploaded files back and compare bytes, so a successful
|
|
# deploy isn't just "curl returned 0" but the served copy actually matches.
|
|
- name: Verify deployed files match build
|
|
env:
|
|
WEBDAV_USER: ${{ secrets.WEBDAV_USER }}
|
|
WEBDAV_PASS: ${{ secrets.WEBDAV_PASS }}
|
|
WEBDAV_BASE: https://files.thecookiejar.me/www/static/password_manager
|
|
run: |
|
|
set -e
|
|
verify() {
|
|
local src="$1" dst="$2"
|
|
curl -sS --fail -u "$WEBDAV_USER:$WEBDAV_PASS" "$dst" -o "/tmp/deployed_$(basename "$src")"
|
|
sha1sum "$src" "/tmp/deployed_$(basename "$src")"
|
|
test "$(sha1sum "$src" | cut -d' ' -f1)" = \
|
|
"$(sha1sum "/tmp/deployed_$(basename "$src")" | cut -d' ' -f1)" \
|
|
|| { echo "::error::Deployed $src does not match build"; exit 1; }
|
|
echo "Verified $src bytes match"
|
|
}
|
|
verify dist/index.html "$WEBDAV_BASE/index.html"
|
|
verify dist/manifest.webmanifest "$WEBDAV_BASE/manifest.webmanifest"
|
|
verify dist/sw.js "$WEBDAV_BASE/sw.js"
|
|
verify dist/icons/icon-192.png "$WEBDAV_BASE/icons/icon-192.png"
|
|
verify dist/icons/icon-512.png "$WEBDAV_BASE/icons/icon-512.png"
|
|
verify dist/icons/icon-maskable-512.png "$WEBDAV_BASE/icons/icon-maskable-512.png"
|
|
echo "All deployed files verified"
|