← All Labs
🛡 AI HACKING ADVANCED +150 XP · +60 no-hint bonus 🎯 Practice mode

Sessions by an AI — Find the Subtle Flaws in Generated Auth Code

An AI coding agent wrote the login, session and password reset code for a small API. It is tidy, commented and every test passes. Six lines in it are security flaws, and none of them is the obvious kind. This is the code review a bug bounty hunter does on a leaked repository.

https://bookshop.local/search

What is insecure AI-written authentication code?

AI coding agents produce authentication code that runs, reads well and passes the tests they wrote for it. The flaws are in the choices a test does not exercise: how a token is generated, whether it expires, which algorithms are accepted, and whose ID is trusted.

Clean formatting and helpful comments make this code easy to approve. Over-reliance on it is the risk: the reviewer assumes that code which looks finished has been thought through.

A real case

We have not found a public incident from 2025 or 2026 that matches this technique closely enough to cite, so we are not listing one here.

How to fix it

  • Review generated authentication code line by line against a checklist, as you would a new contributor's.
  • Use a password hash built for the job, such as argon2 or bcrypt.
  • Generate tokens from a cryptographic random source, expire them and make them single use.
  • Pin JWT algorithms, set httpOnly and secure on session cookies, and take the user ID from the verified session only.

Questions people ask

Why do the tests pass if the code is insecure?

Tests written alongside the code check that it works for normal use. They rarely check what an attacker would try.

Is AI-written code more dangerous than human code?

It makes the same mistakes, but at greater volume and with a polish that lowers the reviewer's guard.

Read the full OWASP LLM Top 10 guide · All free labs · AI red team certification