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
- Read the report: write down the expected behaviour and the actual one in a sentence each.
- Reproduce it: run the visible tests and find the failing check that matches the report.
- 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.
- Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
- 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 aheadThe 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.