Exercise 10 worked solution
Compare after completing your own attempt. Only update-policy.mjs differs from the student application's code; the helper, public key, fixtures, service, page, and checks are shared.
Repair
import { verifyPublisherSignature } from './update-helpers.mjs';
export function acceptUpdate(update) {
return verifyPublisherSignature(update);
}
The starter accepts a schema-valid payload if its computed SHA-256 checksum matches the checksum delivered alongside it. Someone who changes that payload can also calculate a matching checksum. The repaired policy instead requires a signature that verifies with the trusted publisher public key bundled with the app.
The supplied helper uses Node's built-in Ed25519 verification on the exact UTF-8 payload string. It does not trust a public key supplied by the envelope. It rejects missing, malformed, or invalid signatures safely. The surrounding service still validates the envelope and announcement before acceptance and preserves the previous announcement on rejection. No private signing key is shipped with either app or the student kit.
Run and verify
From the repository root:
cd exercises/10-software-data-integrity/solution
node checks.mjs
node server.mjs
Use Node.js 22+. Expect all 12 checks to pass, ending with 12 passed; 0 failed, exit code 0. The unchanged starter has 7 passed; 5 failed. Stop other lesson servers and open http://127.0.0.1:3000.
Click Genuine update, inspect it, and apply it: HTTP 200. Then click Rehashed tampering, inspect the matching checksum and invalid signature, and apply: HTTP 403. The current title, message, and version must remain the genuine values; do not reset or restart between these requests. Apply the second genuine update through More examples and Load example: HTTP 200. Applying that genuine example again remains valid.
The checks also cover an untrusted signer, unsigned updates, malformed signatures, malformed JSON, invalid announcement shape, and malformed envelopes. Genuine acceptance prevents an always-deny answer from passing. A second genuine update prevents treating a single known message as the publisher policy.
What the repair proves
A signature verified under the pinned key establishes authenticity of those payload bytes relative to that key. It does not establish whether the publisher's content is helpful, whether the update is newest, or whether the publisher's signing key remains uncompromised. Genuine replay and rollback are permitted here. Key rotation, freshness policy, and production update delivery require further design.
Keep use on loopback with fictional data. This is a focused example of OWASP A08:2025 Software or Data Integrity Failures; the implementation uses Node.js cryptography. CVE Lite dependency scans do not detect this application policy flaw.