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:
@@ -559,29 +559,57 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
window.addEventListener('pagehide', 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(/[ | ||||