Skip to main content

Exercise 10 instructor walkthrough

Preflight​

Read the teaching plan and rubric. From the repository root, export a fresh kit to a destination that does not exist:

node tooling/package-student-kit.mjs 10-software-data-integrity node ./dist/signed-updates-class
cd dist/signed-updates-class/app
node --version
node checks.mjs
node server.mjs

Use Node.js 22+. The unchanged starter prints 7 passed; 5 failed and exits with code 1; these are expected teaching failures. Run the server afterward and open http://127.0.0.1:3000. No dependency installation is needed. Stop any other server using port 3000.

Demonstrate the problem​

  1. Click Genuine update, then Inspect update. The checksum and publisher signature are valid. Click Apply update: HTTP 200, with “Library study evening,” version 1, as the current announcement.
  2. Click Genuine update again. Change only the message in the payload editor to a harmless fictional message. Inspect it: both checks fail. Apply it: HTTP 403 because the old checksum no longer matches.
  3. Click Recompute checksum, then Inspect update. The checksum now matches but the signature is invalid. Click Apply update: the starter returns HTTP 200 and changes the announcement.
  4. Record that contrast. The supplied Rehashed tampering button loads a ready-made equivalent; learners should also perform the edit and recomputation themselves.

The unchanged starter fails five checks: rehashed tampering, an untrusted signer, an unsigned update, a malformed signature, and preservation of the genuine announcement when rehashed tampering is attempted. It rejects malformed data and a changed payload with an old checksum, which is why “it rejected some tampering” is inadequate evidence of publisher verification.

Explain before repairing​

The checksum comes from the same untrusted envelope as the payload, so an attacker can replace both. A signature is checked against the exact UTF-8 payload bytes using a trusted publisher public key bundled with the app. The corresponding private signing key remains with the publisher and is not shipped. An envelope's optional publicKey is ignored: a correctly signed message from a different key is still not a campus-publisher update.

The supplied helper handles Ed25519 and malformed signatures. The surrounding service validates the envelope and announcement before modifying state. Students repair the policy decision, not the cryptographic implementation.

Worked repair​

Replace only update-policy.mjs:

import { verifyPublisherSignature } from './update-helpers.mjs';

export function acceptUpdate(update) {
return verifyPublisherSignature(update);
}

Keep helpers, keys, fixtures, server, UI, and checks unchanged. Always allowing accepts tampering; always denying blocks genuine updates. Accepting an envelope-provided key lets an attacker choose the alleged publisher.

Verify the repair​

Save, stop and restart the server, and refresh. In one uninterrupted run:

  1. Load and apply Genuine update: HTTP 200. Record the exact current announcement.
  2. Load Rehashed tampering and inspect it: checksum matches, publisher signature invalid.
  3. Apply: HTTP 403. The current announcement must remain identical to step 1; do not reset or restart between these steps.
  4. Try Untrusted signer and Unsigned update: both must be rejected with HTTP 403.
  5. Select Another genuine update under More examples, click Load example, then apply it: HTTP 200, version 2, “Welcome workshop.” Apply the same genuine update again: HTTP 200, because authentic replay is permitted.
  6. Run node checks.mjs: expect 12 passed; 0 failed, exit code 0.

Malformed envelopes, malformed payload JSON, or invalid announcement shape are rejected with HTTP 400, before policy acceptance can change state. Reset restores “Campus noticeboard,” version 0; that is a starting state, not an incoming valid update. Restart also restores the starting state. Neither is evidence that a rejected update preserved the previous accepted announcement.

Grade submitted policies​

From the repository root, point the grader at the submitted app folder:

node tooling/check-submission.mjs 10 path/to/submission/app --json

The full exercise ID 10-software-data-integrity also works. The grader copies only the submitted update-policy.mjs into an isolated temporary app and uses trusted repository helpers and fixtures. The parent grader compares returned observations with trusted expected behavior; it does not accept a student-supplied list of passing checks. Review the actual report and use the rubric for explanations and browser evidence; a check count alone is not the full assessment. The grader executes submitted JavaScript in a restricted child process; it is a classroom assessment aid, not a sandbox or anti-cheating guarantee for actively hostile code. Review the small policy change before running it.

Reference explanations​

  • Why does recalculating the hash not prove authenticity? Anyone who controls the data can calculate a new hash. The expected checksum has no independent trusted source here.
  • Why pin the public key? Verification only establishes the signer relative to a key. The app must already know which key represents its publisher.
  • Why verify exact bytes? Parsing and reformatting JSON can change the signed text. The helper verifies the original payload string.
  • Why retain schema checks? Authenticity does not establish usable data shape. Malformed signed content must not corrupt state.
  • Why accept a second genuine update? The repair must implement verification, not a hard-coded allowlist for one known message.
  • Why allow genuine replay? Signature verification alone does not establish freshness. Rollback and replay prevention need additional policy and are outside this lesson.

Use the worksheet troubleshooting for setup and JSON issues. Preserve the intentionally vulnerable starter for comparison and keep all runs on loopback.

Screenshot preview