The Token That Never Dies

Medium

· Backend

Incident

SEV-1

BUG-5521

Priority: Critical (security) · reported by pentest

Time to fix: 20 min

Failing checks on the shipped build

  • a fresh token is accepted

    expected 200 but got 401

  • clock skew works in the client's favour

    30s inside the skew window must pass: expected 200 but got 401

How to work this incident

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
  4. Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
  5. Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.

Inspired by

JWT deployments

Security review flagged that Meridian API access tokens keep working long after they expire — and freshly issued tokens are sometimes rejected at 9 AM sharp.

Token decoding and the route guard are locked. verifyToken.js owns the expiry math.

Remember: JWT exp is in seconds since epoch (RFC 7519), and the service allows 60 seconds of clock skew in the client's favour.

Code map

var store = require("./tokenStore");

var CLOCK_SKEW_SECONDS = 60;

// exp is SECONDS since epoch (JWT spec). nowMs is milliseconds.
exports.verifyToken = function (token, nowMs) {
  var payload = store.decode(token);

  var deadline = payload.exp - CLOCK_SKEW_SECONDS;
  if (deadline < nowMs) {
    return { valid: false, reason: "expired" };
  }

  return { valid: true, userId: payload.userId };
};

Sign in to edit the file, run the tests and submit a fix

A free account — no card, no trial clock. You come straight back here.

The Token That Never Dies — JavaScript Bug Hunt

Security review flagged that Meridian API access tokens keep working long after they expire — and freshly issued tokens are sometimes rejected at 9 AM sharp.

  • Language: JavaScript
  • Layer: Backend
  • Difficulty: Medium
  • Modelled on: JWT deployments
  • Visible tests: a fresh token is accepted; a token expired an hour ago is rejected; clock skew works in the client's favour
  • Reward: 50 XP for a complete fix

Incident

  • Severity: SEV-1 (priority: Critical (security))
  • Ticket: BUG-5521
  • Reported by: pentest
  • Time to fix: 20 minutes, the target for a medium incident

Failing checks on the shipped build

  • a fresh token is accepted — expected 200 but got 401
  • clock skew works in the client's favour — 30s inside the skew window must pass: expected 200 but got 401

How to work this incident

  1. Read the report: write down the expected behaviour and the actual one in a sentence each.
  2. Reproduce it: run the visible tests and find the failing check that matches the report.
  3. Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
  4. Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
  5. Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.

Briefing

Security review flagged that Meridian API access tokens keep working long after they expire — and freshly issued tokens are sometimes rejected at 9 AM sharp.

Token decoding and the route guard are locked. verifyToken.js owns the expiry math.

Remember: JWT exp is in seconds since epoch (RFC 7519), and the service allows 60 seconds of clock skew in the client's favour.

Bug report

BUG-5521 · Priority: Critical (security) · Reported by: pentest

  • A token with exp = one hour AGO is still accepted.
  • Tokens minted by a server whose clock is 30s ahead get rejected, even though the spec grants 60s of skew tolerance.

Contract for verifyToken(token, nowMs): returns { valid: true, userId } or { valid: false, reason }.

Logs

[guard] ALLOW userId=u_812 exp=1767261600 now=1767265200000  <- expired 1h ago!
[guard] DENY  reason=expired exp=1767268830 now=1767268800000    <- only 30s ahead

The code as shipped

src/auth/verifyToken.js (editable)

var store = require("./tokenStore");

var CLOCK_SKEW_SECONDS = 60;

// exp is SECONDS since epoch (JWT spec). nowMs is milliseconds.
exports.verifyToken = function (token, nowMs) {
  var payload = store.decode(token);

  var deadline = payload.exp - CLOCK_SKEW_SECONDS;
  if (deadline < nowMs) {
    return { valid: false, reason: "expired" };
  }

  return { valid: true, userId: payload.userId };
};

Read-only context: src/auth/guard.js, src/auth/tokenStore.js.

Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More JavaScript bug hunts.