Security hardening: CSP headers, SW scope gating, save validation
- _headers: add CSP, X-Frame-Options, X-Content-Type-Options, Referrer-Policy, Permissions-Policy, HSTS, COOP, CORP, COEP - sw.js: gate fetch handler to GET + http(s) + same-origin; return 504 on offline non-document failures; bump cache to v11 - app.js: validate every field of the localStorage save (allowlist species, clamp stats, coerce age, reject oversized payloads, strip HTML-relevant chars from name); apply same sanitizer to rename input
This commit is contained in:
@@ -1,3 +1,14 @@
|
|||||||
|
/*
|
||||||
|
Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; img-src 'self' data:; connect-src 'self'; manifest-src 'self'; worker-src 'self'; frame-ancestors 'none'; base-uri 'self'; form-action 'self'; object-src 'none'; upgrade-insecure-requests
|
||||||
|
X-Frame-Options: DENY
|
||||||
|
X-Content-Type-Options: nosniff
|
||||||
|
Referrer-Policy: no-referrer
|
||||||
|
Permissions-Policy: accelerometer=(), camera=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), payment=(), usb=(), interest-cohort=()
|
||||||
|
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
|
||||||
|
Cross-Origin-Opener-Policy: same-origin
|
||||||
|
Cross-Origin-Resource-Policy: same-origin
|
||||||
|
Cross-Origin-Embedder-Policy: credentialless
|
||||||
|
|
||||||
/sw.js
|
/sw.js
|
||||||
Cache-Control: no-cache, no-store, must-revalidate
|
Cache-Control: no-cache, no-store, must-revalidate
|
||||||
Service-Worker-Allowed: /
|
Service-Worker-Allowed: /
|
||||||
|
|||||||
@@ -559,29 +559,57 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
window.addEventListener('pagehide', saveProgress);
|
window.addEventListener('pagehide', saveProgress);
|
||||||
window.addEventListener('beforeunload', saveProgress);
|
window.addEventListener('beforeunload', saveProgress);
|
||||||
|
|
||||||
|
const ALLOWED_SPECIES = ['green', 'loggerhead', 'leatherback'];
|
||||||
|
function clampStat(n) {
|
||||||
|
const v = Number(n);
|
||||||
|
if (!Number.isFinite(v)) return 0;
|
||||||
|
return Math.max(0, Math.min(100, v));
|
||||||
|
}
|
||||||
|
function sanitizeName(n) {
|
||||||
|
if (typeof n !== 'string') return 'Shelly';
|
||||||
|
// Strip control chars and HTML-relevant punctuation; cap at 12 like the input.
|
||||||
|
const cleaned = n.replace(/[ | ||||||