Skip to content

Unauthenticated JWT issuance via /dev-login remains active in production #298

@Ridanshi

Description

@Ridanshi

Summary

The backend currently exposes a development-only login route in all environments, including production.

POST /auth/dev-login issues a valid 30-day JWT for a hardcoded demo user without requiring any authentication, password verification, feature flag, or environment guard.

This creates a complete authentication bypass vulnerability.


Affected File

apps/backend/src/routes/auth.ts

Root Cause

The route is registered unconditionally:

app.post('/dev-login', async (request, reply) => {
  const token = app.jwt.sign(
    {
      id: 'devcard-demo',
      username: 'demo',
    },
    { expiresIn: '30d' }
  );

  return reply.send({ token });
});

The endpoint:

  • has no authentication checks,
  • has no environment validation,
  • has no feature flag,
  • and is accessible to any caller.

Because it issues a fully valid JWT, the token bypasses every route protected by:

app.authenticate

Security Impact

Any unauthenticated attacker can:

  • issue themselves a valid JWT,
  • impersonate the demo account,
  • access authenticated API routes,
  • and bypass all normal login flows.

Potential impact:

  • authenticated route access,
  • analytics manipulation,
  • unauthorized actions,
  • privilege escalation depending on downstream authorization assumptions.

The issue is especially severe because exploitation requires only:

curl -X POST https://api.devcard.app/auth/dev-login

Reproduction

curl -X POST https://api.devcard.app/auth/dev-login

Response:

{
  "token": "eyJ..."
}

The returned token can immediately be used against protected endpoints.


Proposed Fix

Guard route registration behind a strict environment check.

Suggested approach:

if (process.env.NODE_ENV !== 'production') {
  app.post('/dev-login', async (request, reply) => {
    ...
  });
}

Additional recommendations:

  • emit a startup warning when dev-login is enabled,
  • require an explicit feature flag,
  • and ensure the route is excluded from production builds entirely.

Acceptance Criteria

  • /dev-login is unavailable in production
  • production startup refuses unsafe configuration
  • development behavior remains unchanged
  • authenticated routes cannot be accessed using demo tokens in production
  • regression coverage added for environment gating

Why This Matters

This is a direct authentication bypass vulnerability requiring no credentials and no special conditions to exploit.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions