Skip to main content

Exercise 10 worksheet: Can you trust this update?

CVE Lite Classroom · CVE Lite

Work only on the supplied local app with fictional campus announcements. Read safety. You need Node.js 22+, a desktop browser, and a text editor. No packages or earlier lesson are required. Allow 75–90 minutes after setup. Record observations in the submission template.

1. Prepare your workspace (10 minutes)​

Extract the repository or student kit. Open exercises/10-software-data-integrity/student, or app in an exported kit, in your editor. Open a terminal in that folder; in VS Code use Terminal → New Terminal.

node --version
node server.mjs

The version must be 22 or newer. Leave the server running and open http://127.0.0.1:3000. Stop other exercise servers first. Do not double-click index.html: the local server decides which updates to accept. Updates are JSON announcements, never executable programs.

2. Observe the checksum trap (10 minutes)​

An update envelope contains payload, checksum, and signature. The payload is a JSON string containing a title, a message, and a positive integer version. The checksum and signature describe those exact payload bytes.

  1. Click Genuine update, then Inspect update, then Apply update. Record the accepted result (HTTP 200) and the current announcement.
  2. Click Genuine update again. In the payload editor change only the message to a harmless fictional statement, such as “The campus reading room opens at noon.” Keep valid JSON, the title, and the version.
  3. Click Inspect update before recomputing anything. Both the old checksum and the publisher signature should fail to match the edited payload. Click Apply update: the starter rejects this simple tampering (HTTP 403). Record that response and confirm the current announcement still matches step 1.
  4. Click Recompute checksum. Do not alter the signature. Click Inspect update again: the checksum now matches, but the publisher signature remains invalid.
  5. Click Apply update. The starter accepts this rehashed tampering (HTTP 200) and displays your changed message. Record the actual result and inspection values.

The interesting failure is step 5: anyone who controls the payload and the adjacent checksum can change both. A failed checksum in step 3 alone does not prove that the publisher is checked.

The Rehashed tampering button loads a ready-made version of this case. Reset announcement restores the initial noticeboard and clears the editor's results. Loading or editing an example clears the previous response evidence without changing the stored announcement. Copy each result into your submission before changing the editor. Use reset to start over, but never between the accepted and rejected updates you compare as repair evidence.

If available, try the optional Signed Update Lab on the lesson website before this local activity. It uses recorded results from the real services. It does not check your edited file; your submission needs your own local results.

3. Understand what establishes trust (10 minutes)​

TermMeaning in this app
Exact bytesThe precise UTF-8 text of payload, including spaces, punctuation, and key order.
SHA-256 hash or checksumA value calculated from those bytes. Anyone can calculate it; matching an untrusted accompanying checksum does not identify a publisher.
Digital signatureA value created with a private signing key and checked against the signed bytes with its corresponding public key.
Private signing keyA secret held by the publisher. It is not included in this app or kit.
Trusted public keyA nonsecret verification key bundled with the app before it receives an update. It is the app's trust anchor.
Pinned keyThe particular public key the app is configured to trust, rather than whichever key an incoming update offers.
Schema validationChecking that the data has the expected title, message, and positive integer version. Valid shape does not establish a trusted source.

The helper verifies an Ed25519 signature over the exact UTF-8 payload string. Reformatting JSON, even without changing its meaning, changes those signed bytes. Verification must use the original string, not parse and re-serialize it first. The checksum is hexadecimal text; the signature is base64 text. You do not need to calculate signatures or write cryptographic code.

An attacker could generate their own signing key and sign their own message correctly. That still does not make them the campus publisher. An optional publicKey field in the update is untrusted input; the helper ignores it and uses the key already bundled with the app.

Before editing, answer: Which information comes from the update, and which trusted information must already belong to the app? Predict whether a newly recomputed checksum can repair a broken publisher signature.

4. Repair the acceptance policy (15 minutes)​

Save a before-copy of update-policy.mjs outside the app folder. Open the original. You will change only acceptUpdate(update), using the supplied verifyPublisherSignature(update) helper from update-helpers.mjs.

JavaScriptMeaning
import { verifyPublisherSignature } from './update-helpers.mjs';Makes the supplied helper available in this file.
updateThe incoming envelope whose publisher needs checking.
A function callRuns a named operation with its input in parentheses.
true / falseThe policy's accept or reject decision.
returnEnds the function and gives its result to the caller.

Keep the function name and argument. Use this scaffold and fill the blank with the helper named above:

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

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

Save only update-policy.mjs. The surrounding service already validates the envelope and announcement before changing state. Leave the helper, trusted public key, fixtures, service, UI, and checks unchanged. Explain why always returning true or always returning false would fail the objective.

5. Restart and prove the repair (10 minutes)​

Save the policy, stop the server with Ctrl+C, run node server.mjs again, and refresh the page. The server loads the policy when it starts. Restarting also restores its initial announcement, so a reset screen alone proves nothing about verification.

Collect this evidence in one uninterrupted run:

  1. Click Genuine update, Inspect update, and Apply update. It must be accepted (HTTP 200). Record the current title, message, and version.
  2. Load the same example, change its message, and recompute its checksum as before. Inspect: matching checksum, invalid publisher signature.
  3. Apply that rehashed tampered update. It must be rejected (HTTP 403).
  4. Compare the current announcement with step 1. All its fields must be unchanged. Do not reset or restart between steps 1 and 4.
  5. Select Another genuine update under More examples, click Load example, and apply it. It must also be accepted (HTTP 200). Apply that genuine example again: this exercise permits authentic replay.

Record both acceptance and rejection. Rejecting everything is not a repair. A valid signature establishes publisher authenticity under the trusted key; it does not establish freshness. The version field is data here, not a rollback-prevention rule.

6. Run the checks (10–15 minutes)​

Stop the server or open a second terminal in the same app folder:

node checks.mjs

The twelve checks create isolated state and do not inspect your browser. They cover genuine updates, changed payloads, rehashed tampering, an untrusted signer, missing or malformed signatures, malformed JSON, invalid announcement shape, unchanged state after rejection, a second genuine update, permitted genuine replay, and malformed envelopes.

The unchanged starter prints 7 passed; 5 failed, with exit code 1. Its expected failures are rehashed tampering, an untrusted signer, an unsigned update, a malformed signature, and preservation of the genuine announcement when rehashed tampering is attempted. After the repair, all 12 checks must pass, ending with 12 passed; 0 failed, with exit code 0. Record the actual output and any remaining failures. Checks exercise this specific lesson boundary; passing them does not prove an entire application secure. If you stopped the server, start it again before returning to the browser.

7. Explain and submit (10 minutes)​

Complete the submission template. Include the changed policy, before-and-after evidence for a rehashed update, successful genuine updates, unchanged state after rejection, and your actual check output. Explain why the pinned public key matters and why an update cannot choose its own trusted key.

Troubleshooting​

  • Address already in use: stop the other lesson server with Ctrl+C; only one can use port 3000.
  • Page cannot connect: keep node server.mjs running and use the exact loopback URL.
  • Repair seems ineffective: save the correct policy file, restart that folder's server, refresh, and repeat the genuine-then-rehashed sequence.
  • Tampering rejected before recomputing: expected; recompute the checksum to expose the missing publisher check.
  • Tampering rejected even after recomputing in the starter: check JSON syntax and keep the required title, message, and positive integer version. The starter still validates data shape.
  • A genuine signature fails after formatting JSON: load the original genuine fixture again. Whitespace changes the signed bytes.
  • Current announcement is unchanged after rejection: expected; rejection must preserve state. The payload editor shows a proposed update, not necessarily the current accepted announcement.
  • Syntax error after editing: compare the scaffold's braces, import path, quotes, and helper spelling. Do not change the checks.

Optional discussion​

What additional policy would prevent applying an older genuine update? How would an application replace a compromised publisher key safely? Why can signed data still be misleading or harmful? Freshness, rollback protection, key rotation, and publisher compromise are discussion topics, not required implementations.

Screenshot preview