Login
ChallengesLearn
Scoreboard
Teams
Profile

Preferences

Truesapiens

LearnAPI SecurityBroken Authentication
API Security·Lesson 4 of 11

Broken Authentication

OWASP API #2. API keys in URLs, missing credential rotation, no rate limit on login, predictable tokens, JWT flaws specific to API contexts (no HttpOnly, no CSRF as defence, token in query string).

Intermediate14 min
APIAuthJWT
Loading lesson…
PreviousBroken Object Level AuthorizationNextExcessive Data Exposure

© 2026 Truesapiens.

Terms of ServicePrivacy PolicyCookie Policy

Broken Authentication is the second most critical API security risk according to OWASP. APIs face unique authentication challenges that web applications do not: tokens are sent in every request (often in URLs or headers that get logged), there is no built-in CSRF protection, and authentication endpoints must be aggressively rate-limited to prevent credential stuffing and brute-force attacks.

What you'll be able to do
  • Identify API-specific authentication flaws: tokens in URLs, missing rate limits, and weak JWT signing.
  • Explain why API auth is fundamentally different from browser-based auth.
  • Describe the 2021 Peloton API auth bypass and its root cause.
  • Apply rate limiting, secure token delivery, and short-lived JWTs with proper signing.
Key terms
Credential stuffing
An automated attack where stolen username/password pairs from one service are replayed against another service's login endpoint. APIs are prime targets because they lack the visual CAPTCHA or JavaScript challenges of browser-based forms.
JWT (JSON Web Token)
A compact, URL-safe token format used for API authentication. A JWT contains a header, payload, and signature. If the signing key is weak or the token does not expire, an attacker who obtains the token can impersonate the user indefinitely.
Rate limiting
The practice of restricting the number of requests a client can make to an endpoint within a time window. Without rate limiting on login, logout, and token-refresh endpoints, attackers can brute-force credentials or exfiltrate tokens at high speed.
What is it?

API auth is not browser auth

Browser-based web applications have built-in security mechanisms that APIs lack. CSRF tokens protect against cross-origin requests. HttpOnly cookies keep session tokens out of JavaScript reach. The browser enforces same-origin policy. APIs receive none of these protections automatically. Tokens are transmitted in Authorization headers or even URL query strings, which are logged by proxies, load balancers, and CDNs. A single log entry can expose a valid session token to anyone with access to the infrastructure logs.

Beyond token storage, APIs expose authentication endpoints — login, logout, token refresh, password reset — that are trivially automated. Without rate limiting, an attacker can send millions of login attempts per hour. Without short token expiry, a stolen token remains valid for days or weeks. Without proper JWT signing, an attacker can forge tokens by changing the algorithm from RS256 to HS256 using a known public key.

Broken authentication flow
Mini Map
Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.
Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.
Try it

Explore the auth scenarios

The simulator below lets you test three authentication scenarios: token leaked in a URL query string, rate-limited login endpoint, and proper authentication with the token in an Authorization header. Watch the request and response logs to see how each scenario behaves.

staging/api/auth/login
Auth Tester
auth-tester · login simulation

Broken Authentication Simulator

Test three authentication scenarios and observe the differences in request behaviour.

Token will appear in URL
Response
Click Login to send an authentication request.
Request log

No requests yet.

Real-world relevance

Peloton API auth bypass (2021)

In 2021, security researchers disclosed that the Peloton API had multiple broken authentication flaws. The most critical was that the GET /api/user/me endpoint returned the authenticated user's data without requiring a valid session token for all request methods. Additionally, the API had no rate limiting on authentication endpoints, enabling credential stuffing attacks against user accounts. Peloton fixed the issue by enforcing session validation on all endpoints and introducing rate limiting on login and token-refresh routes.

The Peloton case illustrates a common pattern: developers assume that certain endpoints are "safe" because they return data about the current user, but they forget to verify the session for every HTTP method or edge case. Combined with missing rate limiting, a single auth gap exposes every user account to compromise.

Mitigation

Rate limits, secure delivery, and short-lived JWTs

Fixing broken authentication requires a layered approach. Rate limit every authentication endpoint — login, logout, token refresh, password reset — to prevent brute-force and credential stuffing attacks. Never transmit tokens in URL query strings or request bodies that get logged. Use short-lived JWTs (15-30 minutes for access tokens) with refresh tokens stored in HttpOnly cookies. Sign JWTs with a strong, secret key and reject the "none" algorithm.

javascriptvulnerable
// VULNERABLE — token in URL query string
const loginUrl = `https://api.example.com/auth/login?token=${jwt}`;
// Logged by: CDN, load balancer, reverse proxy, browser history

// VULNERABLE — no rate limiting on login
app.post('/api/auth/login', async (req, res) => {
  const user = await db.user.findUnique({ where: { email: req.body.email } });
  if (!user || !bcrypt.compare(req.body.password, user.passwordHash)) {
    return res.status(401).json({ error: 'Invalid credentials' });
  }
  const token = jwt.sign({ userId: user.id }, SECRET, { expiresIn: '7d' });
  res.json({ token });
  // No rate limit — attacker can try 10,000 passwords/second
});

// SAFE — rate limited, token in header, short expiry
const rateLimiter = rateLimit({ windowMs: 60_000, max: 5 });

app.post('/api/auth/login', rateLimiter, async (req, res) => {
  const user = await db.user.findUnique({ where: { email: req.body.email } });
  if (!user || !bcrypt.compare(req.body.password, user.passwordHash)) {
    return res.status(401).json({ error: 'Invalid credentials' });
  }
  const token = jwt.sign({ userId: user.id }, SECRET, { expiresIn: '15m' });
  res.json({ token }); // Client sends in Authorization: Bearer <token>
});

Additional measures: implement MFA for sensitive operations, rotate refresh tokens on each use, store password hashes with a strong algorithm (argon2 or bcrypt), and monitor authentication endpoints for anomalous traffic patterns.

Further reading
  • OWASP API Security Top 10 — Broken Authentication (API2)(OWASP)
  • Peloton API Auth Bypass Disclosure (2021)(Hacker News)
  • JWT Handbook — Algorithm Confusion Attacks(Auth0)
Key takeaways

What to remember

  • APIs lack the built-in security of browser-based auth — no CSRF tokens, no HttpOnly cookies by default, no same-origin policy.
  • Never put tokens in URL query strings. Every proxy, CDN, and load balancer logs the full URL.
  • Rate limit all authentication endpoints. Without it, credential stuffing and brute-force attacks are trivial.
  • Use short-lived JWTs (15-30 min) with strong signing keys. Reject the "none" algorithm and verify the signature on every request.
  • The 2021 Peloton breach is a textbook case: an endpoint returned user data without session validation, and auth endpoints had no rate limiting.

Knowledge check

0/3 answered · 0 correct
  1. 1.Why is API authentication fundamentally different from browser-based web app authentication?

  2. 2.An API returns the JWT token in the URL query string after login. What is the primary risk?

  3. 3.What is the purpose of rate limiting on authentication endpoints?