// ───────────────────────────────────────────────────────────────────────────── // A08:2025 SOFTWARE OR DATA INTEGRITY FAILURES (2021: A08 Software and Data Integrity Failures) // ───────────────────────────────────────────────────────────────────────────── // WHAT : Code or data is trusted without verifying it hasn't been tampered // with — by the client, the network, or the pipeline. // HAPPENS : insecure deserialization (eval / node-serialize / JSON with // __proto__ -> prototype pollution in JS); unsigned auto-updates; // CI/CD pipeline that builds from unverified sources or lets PRs // mutate the pipeline; CDN scripts without SRI; trusting client-side // state (price in hidden field, role in cookie, isAdmin in JWT body // that isn't verified); JWT signature skipped (`jwt.decode`); // cache poisoning; unsigned webhooks. // SPOT : eval / new Function / vm.runInContext on input; `JSON.parse` then // deep merge / Object.assign into defaults; lodash.merge / _.set // with user keys; // CDN compromise => XSS on every page // FIXED: function sriTag(src, bytes) { const hash = crypto.createHash('sha384').update(bytes).digest('base64'); return ``; } const tag = sriTag('https://cdn.example.com/lib.js', Buffer.from('console.log(1)')); assert.match(tag, /integrity="sha384-[A-Za-z0-9+/=]{64}"/); assert.match(tag, /crossorigin="anonymous"/); // Browser recomputes the hash of the fetched bytes; mismatch => script refused. // ── 6. Pipeline / update integrity (checklist) // Auto-update: fetch over TLS, verify detached signature (minisign/Sigstore cosign) before install. // CI: protected branches, required reviews, pipeline-as-code reviewed, no secrets exposed to fork PRs, // artifacts hashed + attested (SLSA provenance), deploy only artifacts built by CI (no laptop builds). // Webhooks: verify X-Hub-Signature-256 (HMAC of raw body) with timingSafeEqual before parsing. console.log('ok: owasp/a08-software-data-integrity-failures.js');