Vibe coding without human review is a security failure waiting to happen
Not too long ago I ran into an MFA enrollment flow that somebody had vibe-coded. And it worked, which is sort of the problem. You turned on two-factor, a QR code popped up, you scanned it with your authenticator app, typed in a code, and that was that. Looked like every other MFA setup you've ever used.
Turns out the QR code came from a free QR generator website. The page built a URL to that site's API, stuck the data to encode in the query string, and used whatever came back as an image:
const res = await fetch("/api/mfa/setup", { method: "POST" });
const { otpauthUri } = await res.json();
qrImage.src = "https://qr-generator.example/api/create?size=200x200&data="
+ encodeURIComponent(otpauthUri);
Here's what's in otpauthUri:
otpauth://totp/Acme:jordan@example.com?secret=JBSWY3DPEHPK3PXP&issuer=Acme
That's the whole second factor, right there. The secret is the shared key your authenticator app uses to make its six-digit codes, and the server checks those codes against the same key. If you've got it, you can make valid codes for as long as that user stays enrolled:
import pyotp
pyotp.TOTP("JBSWY3DPEHPK3PXP").now() # a valid code, and a new one every 30 seconds
The label even tells you whose secret it is and what it's for. So every user who turned on MFA sent all of that to a third party the company had no agreement with, no control over, and most likely didn't know it was using.
What actually leaked
It's worth being a little careful here, because "it went over the internet" isn't really the problem.
If that request went out over plain HTTP, sure, the secret crossed every network between the user and the QR site in the clear. HTTPS fixes that part, and it doesn't help much, because the real trouble's at the other end. The secret's in a URL, and URLs get written down all over the place:
- the QR site's web server and access logs, CDN logs, analytics and error tracking;
- the user's browser cache, since the image is cacheable;
- any proxy or security appliance that logs URLs, which a lot of corporate networks do.
The QR site also gets the user's IP address and browser, plus a Referer header with your site's name in it. So now a stranger's logs have a list of accounts at your company, each one with its MFA secret, and when and from what network it got set up.
They don't have to be up to anything for that to matter. Free services get sold, get breached, change hands and change what they keep. You've hung your users' second factor on a log file you'll never see.
The whole point of MFA is the day a password leaks. Phishing, reused passwords and old breaches all hand an attacker the password. With the TOTP secret too, they've got both factors, and nothing ever tells the user.
How it got built
You don't need bad intent for this, or even what you'd usually call carelessness. Ask for "show the user a QR code for their authenticator app" and an external QR API is a pretty common answer. Tutorials did it that way for years, and it's one line with nothing to install. The model reaches for what it's seen the most, and it works. The demo's fine, the tests pass, the scan goes through.
Nobody asked what was in that URL, because nobody read the code closely enough to notice there was a URL. That's the failure. Not that a model wrote it, but that the engineer shipped an authentication system without understanding what it did, and nothing in their process made them.
A person could write the same bug, and I'm sure some have. The difference is that writing it by hand means typing somebody else's hostname into your MFA code yourself, and you'd probably stop and think about that. Generated code skips that moment. It shows up finished and plausible, and it's real easy to read it like you'd read a library: it runs, so it must be fine.
The fix
Make the QR code where the secret already lives. On the server:
import pyotp
import segno
def start_mfa_enrollment(user):
secret = pyotp.random_base32()
user.pending_totp_secret = encrypt(secret) # not active until confirmed
user.save()
uri = pyotp.TOTP(secret).provisioning_uri(
name=user.email, issuer_name="Acme",
)
return segno.make(uri).png_data_uri(scale=5)
The image goes to the browser as a data: URI right in the page, so it never leaves your server as its own request. You could just as well draw it in the browser with a QR library you bundle, as long as you serve it yourself and don't pull it from a CDN.
Then finish the flow the right way:
def confirm_mfa_enrollment(user, code):
secret = decrypt(user.pending_totp_secret)
if not pyotp.TOTP(secret).verify(code, valid_window=1):
raise BadRequest("that code didn't match")
user.totp_secret = user.pending_totp_secret
user.pending_totp_secret = None
user.save()
Serve the enrollment page with Cache-Control: no-store, and keep the secret encrypted, not sitting there in plain text.
A content security policy would've caught the original bug right in the browser:
Content-Security-Policy: default-src 'self'; img-src 'self' data:
With that header the third-party image just doesn't load, and the developer finds out in the first five minutes instead of never. That alone makes it worth having. It turns "the page is quietly talking to somebody else" into an error you can see.
Review generated code like a stranger's pull request
Give generated code the review you'd give a pull request from a contractor you've never met. It looks competent, and you've got no idea what they were thinking. A handful of questions catch most of the bad stuff, and the MFA bug fails the very first one.
Where does data go? List every outbound request: every URL, every SDK that phones home, every script tag and image from somewhere else. For each one, ask what it's sending.
grep -rnoE "https?://[^\"' )>]+" src/ templates/ \
| grep -vE 'localhost|127\.0\.0\.1|example\.(com|org)' \
| sort -u
That won't find everything, but it would've found this one. Better yet, give production an egress allowlist, so a new outbound host is a failed request and not a quiet one.
What's secret here, and where does it end up? Follow every key, token and password from where it's made to everywhere it gets written: logs, URLs, error messages, client-side code, analytics events.
Who's enforcing this rule? Authorization belongs on the server, on every request. A check that lives in the UI, in a hidden field or in a system prompt isn't a check.1
Is this the insecure version of something common? Generated code is full of lines that work fine in a tutorial and shouldn't ever ship. These all run without a peep:
jwt.decode(token, options={"verify_signature": False}) # trusts any token
requests.get(url, verify=False) # no TLS checking
token = "".join(random.choices(string.ascii_letters, k=32)) # guessable
subprocess.run(f"convert {filename} out.png", shell=True) # shell injection
The fixes are all small: verify signatures with a fixed list of algorithms, leave TLS checking on, use secrets.token_urlsafe(), and pass a list of arguments without shell=True. The hard part's noticing them in the first place.
Do these packages exist, and are they the ones you meant? Check every new package name against the registry and its real project page. A name that sounds right doesn't mean it's the library you think it is.
Could you explain it to somebody else? If you can't walk through how it works, line by line, for anything touching logins, payments or personal data, it's not ready, no matter how well it runs. That was the real gap here. I don't think that engineer would've shipped the QR URL if they'd had to walk a coworker through it.
Use the tools, own the result
I use AI tools for a lot of my own code, and I'm not saying don't. They're fast, and for plenty of work they're really good. The speed is exactly why review matters more now. One engineer can generate a whole lot more code than they can carefully read, and an attacker only needs the piece nobody read.
The rule's the same one it's always been: you're responsible for what you ship. "The model wrote it" is going to go over about as well in an incident report as "I copied it from Stack Overflow". Read it, understand it, and for anything security-related, have somebody else read it too.
-
Added November 2026: for more on why a system prompt can't hold a security rule, see The prompt is not a security boundary. ↩