Authentication is the gatekeeper of your entire application. If it fails, every other security measure becomes irrelevant. Yet authentication is one of the areas where AI-generated code most consistently cuts corners — not because the AI doesn't know how to write secure auth, but because secure auth requires paranoia, and paranoia requires experience.
What Is Broken Authentication?
Broken authentication (OWASP A07) is an umbrella term for flaws in how an application verifies user identity and manages sessions. It includes vulnerabilities that let attackers log in as other users, impersonate admins, maintain unauthorized access after logout, and guess or bypass login credentials.
The consequences are severe: an attacker who exploits broken authentication doesn't just read other users' data — they operate as those users. They can make purchases, change passwords, delete accounts, send messages, and access administrative functions.
The Most Common Broken Authentication Patterns in Vibe Apps
1. Admin Routes Protected Only by Authentication, Not Authorization
This is the most common and most dangerous pattern. An admin dashboard route checks that a user is logged in but doesn't verify the user is an admin. Any authenticated user can access admin functionality by navigating directly to /admin or calling admin API endpoints.
AI-generated admin routes frequently look like this: check if there's a valid session, if yes proceed, if no redirect to login. The admin role check is either missing entirely or implemented in the wrong place (checked on the frontend, not on the API).
2. Role Claims Trusted from Client-Controlled Sources
A vibe-coded app might store user roles in a cookie, localStorage, or the JWT payload — and then trust that value without verifying it against the database. If the role is in a cookie, an attacker edits the cookie to set their role to 'admin'. If the role is in a JWT payload, the vulnerability is more subtle but exploitable when JWT validation is weak.
3. No Rate Limiting on Login Endpoints
An authentication endpoint with no rate limiting can be attacked with credential stuffing: automated tools try billions of username/password combinations from leaked credential databases. With no rate limiting, an attacker can make thousands of attempts per second. Most users reuse passwords from other breaches, making this attack highly effective.
Statistics
The Have I Been Pwned database contains over 12 billion leaked credentials from historical breaches. Attackers use these lists for credential stuffing. An endpoint that processes 1,000 attempts per second against even 0.1% reuse will find real credentials within minutes.
4. Password Reset Flaws
Password reset flows are a frequent source of authentication vulnerabilities. Common issues include: reset tokens that don't expire, reset tokens that are predictable (short, sequential, or generated with Math.random()), and reset flows that don't invalidate existing sessions (allowing an attacker to initiate a reset but the victim's existing session remains valid).
5. JWT Misconfigurations
JWTs are widely used for stateless authentication, but they're misused in AI-generated code in predictable ways. The most dangerous: accepting the 'none' algorithm (where the JWT is unsigned and anyone can forge tokens), using a weak or guessable secret (common AI-generated secrets like 'secret', 'mysecret', or the app name), and not validating the algorithm specified in the token header.
6. Sensitive Endpoints Not Checking Authentication at All
This sounds too obvious to be real, but it happens. Particularly in API routes that are only meant to be called by other server-side code (internal endpoints, webhook handlers, admin operations), AI often omits authentication entirely. These endpoints are frequently discoverable through API documentation, JavaScript bundles, or directory brute-forcing.
How to Audit Your Authentication Implementation
A systematic authentication audit covers these areas:
- Enumerate every route and API endpoint. For each one: is authentication required? Is it enforced server-side?
- Identify every admin or privileged operation. Is the role check enforced server-side, not just in the UI?
- Find every place user roles or permissions are stored or read. Are they sourced from the server-authoritative session, not from client-controlled values?
- Test login rate limiting: make 100 rapid login attempts with wrong credentials. Does the system slow down, block, or require CAPTCHA?
- Review the password reset flow: are tokens cryptographically random? Do they expire? Are they single-use?
- If using JWTs: verify the signing algorithm is explicitly enforced and the secret is cryptographically strong (256+ bits).
Fixes for the Most Common Issues
Enforcing Admin Authorization
Always verify role on the server side in the API handler, not in a layout or middleware that might be bypassed. Fetch the user's role from your database using their authenticated user ID — never from the request payload. In Next.js App Router: check the role inside the API route handler, not just in the layout.
Adding Rate Limiting
Use a token bucket or fixed window rate limiter on login, registration, and password reset endpoints. Upstash Redis with the @upstash/ratelimit library is a popular choice in Next.js deployments. Rate limit by IP, not by user ID (since the attacker is targeting accounts they don't own yet). Return 429 Too Many Requests with a Retry-After header.
Secure Password Reset Tokens
Generate password reset tokens using a cryptographically secure random number generator (crypto.randomBytes(32) in Node.js, not Math.random()). Store a hash of the token in your database (bcrypt or SHA-256), not the raw token. Set a short expiration (15–60 minutes). Invalidate the token after first use. Invalidate all existing sessions for the user when the password is changed.
Ready to check your app?
Find your vulnerabilities before attackers do.
Pentrust runs AI agents that chain real exploits against your application and provides copy-paste fixes for every finding. Full pentest in under 30 minutes.
Run a free pentest