Skip to main content

Exercise 09 instructor walkthrough

Preflight​

Read the teaching plan and rubric. From the repository root, export a fresh kit:

node tooling/package-student-kit.mjs 09-authentication-failures node ./dist/session-logout-class
cd dist/session-logout-class/app
node --version
node checks.mjs
node server.mjs

The destination must not exist. Expect 8/10 checks with two revocation failures and exit code 1; then the local server runs at http://127.0.0.1:3000. Do not install dependencies. A second terminal can run checks while the server is active.

Demonstrate the problem​

Sign in as alice@campus.example with Campus-demo-42!, request the profile, capture the token, and log out. Normal profile access is now rejected because the browser cleared its current token. Replay still returns Alice's profile because the server retained the session. Capture HTTP evidence, not token values.

Worked repair​

In session-policy.mjs, use the supplied helper:

import { revokeSession } from './session-helpers.mjs';

export function endSession(state, token) {
return revokeSession(state, token);
}

The helper targets the presented token only. Repeating logout is safe. Invalid tokens cannot revoke other sessions.

Verify the repair​

Save, stop and restart the server, and refresh. Log in and capture a new token, log out, and replay without another restart: expect HTTP 401. Log in again and request the profile: expect HTTP 200. Open two tabs, sign in independently in both, log out the first, and verify the second still accesses its profile. Run node checks.mjs: expect 10 passed; 0 failed and exit code 0.

Restarting clears sessions in both versions, so a token captured before restart cannot demonstrate the repair. Expiry can also cause a false conclusion; replay promptly. Automated expiry checks use a controlled clock, not a long classroom wait.

Reference explanations​

  • Why server revocation? A client can clear its own copy but cannot erase copies held elsewhere. The server controls whether presented credentials remain valid.
  • Why another login should work? Logout ends a session, not the account's ability to authenticate again.
  • Why preserve the second tab? It has a distinct token and this lesson's policy is per-session logout.
  • Why not only wait for expiry? Expiry is independent; logout requires immediate revocation of the current token.
  • What is not proven? This exercise does not establish production-grade authentication or address all A07 weaknesses.

If students change tests, UI labels, or all-session state instead of the policy, return them to the evidence requirements. Preserve the intentionally vulnerable starter as an instructor comparison; never host it publicly.

Screenshot preview