Vibe Coding in Production: How AI-Generated Code Puts User Data and Payments at Critical Risk
A non-developer client built a full SaaS platform with AI subscriptions and payment operations using only LLM-assisted "vibe coding", then called us in for a security audit before launch. What we found was alarming: a single authenticated request could escalate any user to admin, unlock paid plans without payment, and expose users' financial and personal data. This is what happens when AI builds the door, the lock, and the payment terminal... without a human reviewing any of it.
Uendell Magno ·
By Uendell Magno de Souza Ávila · AVLI Solutions
A client reached out asking for a security review before going further with their platform. They had built a full SaaS product using AI-assisted development — no formal engineering background, no security training, iterating entirely through LLM prompts. The platform handled user subscriptions, AI-powered analysis credits, and payment operations.
They had the instinct to ask someone to look at it before it caused damage. That instinct was correct.
This article documents what the audit found, why it happened, and what every non-developer building with AI tools needs to understand before processing a single real payment.
The platform is not identified. All findings are published with full authorization for educational purposes.
The Platform Profile: Real Stakes, Real Users
This was not a toy project. At the time of the audit, the platform had:
An active user base with subscription tiers (free trial, paid plans)
A payment flow processing real transactions for AI analysis credits
Personal and financial data in storage: name, email, CPF, address, subscription status, billing history
An AI dashboard consuming those credits per analysis — meaning credit balance had direct monetary value
A marketplace component connecting buyers and sellers
The backend was NestJS, the frontend Next.js. Both generated through iterative AI prompting. The developer had no prior backend security experience. The AI produced functional, deployable code. And that was the entire review process.
Finding 1 — Any User Can Become Admin in One Request
Root Cause: Unrestricted Mass Assignment and Over-Permissive API Responses
Before the privilege escalation was even attempted, the audit identified a prior violation: the /me endpoint was returning the full user object to the frontend — including internal fields such as role, plan, and other server-side attributes that the client has no legitimate reason to receive in their raw, writable form.
This reflects a broader design failure. APIs should apply the principle of least exposure: every response must be scoped to exactly what the consuming client needs, nothing more. Returning role: "free" to a logged-in user's dashboard widget is unnecessary. Returning it as a mutable field in a JSON body that mirrors the database schema is a direct invitation to attack. When internal fields are surfaced to the client, they signal to any attacker — or curious user — which parameters the server might accept back.
That inference proved correct.
What happened
Using only a free-tier account and its own valid session token, the auditor sent a single PATCH request to the user update endpoint:
PATCH /api/v1/users/{own-uuid}
Authorization: Bearer <free-tier-token>
Content-Type: application/json
{ "role": "admin" }
→ HTTP 200 OK
→ "role": "admin" confirmed in databaseNo special tooling. No exploit chain. One HTTP request, thirty seconds, permanent admin access.
A second request confirmed that paid subscription plans were equally writable:
{ "plan": "PROFISSIONAL" }
→ HTTP 200 OK — paid plan activated without paymentWhy This Is Catastrophic and Why AI Generated It
In a system where plan tier gates access to AI credits, the ability to freely write your own plan or role field collapses the entire trust boundary of the platform:
Any free user can unlock paid features without paying. Every AI credit consumed this way is a direct financial loss to the operator.
Any user can become admin. In a SaaS, that typically means access to all user records, billing data, platform settings, and potentially payment provider credentials.
The attack survives token rotation. Because the escalation writes to the database — not the JWT — the attacker's next login issues an admin-role token legitimately. Revoking the original token does not undo the damage.
All user PII becomes accessible. The
GET /users/:idendpoint lacked IDOR protection. An admin-role token could enumerate every user profile, including CPF numbers and billing data collected for payment processing.
Why AI Generated This Flaw
This vulnerability was not introduced by a malicious actor or a careless senior developer. It was generated by a language model doing exactly what it was instructed to do and that is the actual problem.
When a developer prompts an LLM with "create a PATCH endpoint to update user profile", the model scaffolds a DTO directly from the user entity schema. It copies every field, name, email, role, plan, subscriptionStatus because all of them exist on the model, and the model has no visibility into which fields are user-editable versus system-controlled. That distinction was never stated in the prompt, so it was never encoded in the output.
The validation pipe was correctly configured with whitelist: true, which strips undeclared properties. But because role was declared in the DTO, as the AI had scaffolded it, it passed through as valid user input. The security control worked. The contract it was enforcing was wrong.
This is the core failure mode of AI-assisted backend development: LLMs generate structurally correct code against an incomplete specification. The model cannot infer business rules that were never written. It does not know that plan is a billing artifact, that role controls administrative access, or that neither should ever be writable by the authenticated user themselves. It produces a coherent, passing, deployable implementation with the attack surface baked in from the first line.
The AI built exactly what it was asked to build. The specification was incomplete, no human caught it before it reached production. OWASP API Security Top 10 (2023)
API3:2023 - Broken Object Property Level Authorization (BOPLA): Users can modify properties they should not control.
API5:2023 - Broken Function Level Authorization: A free-tier user can perform administrative operations.
The fix
The correction operates at the design level, not the code level. Three rules, applied together, close this entire class of vulnerability.
1. DTOs must be authored from business rules, not derived from the entity schema.
The DTO, the object that defines what the server accepts from the client, should be written by asking "what is this user role permitted to change?", not "what fields exist on this model?". Those are different questions with different answers. A user updating their profile should be able to change their display name and notification preferences. They should never be able to touch role, plan, or subscriptionStatus , and the correct way to enforce that is to simply not include those fields in the input contract. A field absent from the DTO cannot be assigned, regardless of what the client sends.
2. Privileged mutations require their own isolated endpoints with explicit authorization.
Changing a user's role is an administrative act. It should live on a separate route, protected by an admin guard, that is only reachable with a token that already carries admin authority. This makes the authorization boundary structural rather than conditional, there is no code path by which a free-tier token reaches that handler.
3. Self-service routes must derive identity from the token, never from the URL.
A route that accepts PATCH /users/{id} and relies on the caller to supply their own ID is an IDOR waiting to happen. Self-service mutation endpoints should extract the user's identity exclusively from the verified JWT payload, the server decides who you are, not the request body. The URL parameter for id should only appear on admin-guarded routes where the caller has verified authority to act on arbitrary users.
Taken together: the user's writable surface is defined explicitly and minimally, privileged operations are structurally inaccessible to unprivileged tokens, and the server never trusts the client to self-identify.
Finding 2 — Authentication Endpoints Fully Open to Brute Force
What Happened
Ten consecutive failed login attempts against the authentication endpoint returned consistent HTTP 401 responses. No throttling, no lockout, no CAPTCHA challenge, no HTTP 429 at any point in the sequence. The password reset endpoint behaved identically, so, unlimited attempts, zero friction.
Why This Compounds Everything
In isolation, missing rate limiting enables credential stuffing: automated tools cycling through leaked email/password combinations at thousands of attempts per minute until one succeeds. That is serious on its own.
Combined with Finding 1, it becomes a fully automated, end-to-end attack chain:
Run credential stuffing against
/auth/login- no rate limit means volume is constrained only by the attacker's bandwidth.On the first valid session, issue one
PATCHrequest to self-assignrole: admin.The escalation writes to the database and persists permanently. Token rotation does not undo it.
With admin access, enumerate all user records - CPF numbers, addresses, subscription history, and billing data collected by the platform for payment processing.
No step in this chain requires any technical sophistication. Step 2 is a single HTTP request.
A platform processing payments and collecting financial PII under Brazilian law is a data controller under LGPD (Lei 13.709/2018). A breach of this data through an access control failure that was preventable at the infrastructure level creates direct regulatory exposure — not a theoretical future risk, but a concrete compliance liability that exists today.
OWASP API Security Top 10 (2023)
API4:2023— Unrestricted Resource ConsumptionAPI2:2023— Broken Authentication
The Fix
Rate limiting must be enforced at two layers simultaneously, because either layer alone is insufficient.
At the application layer, authentication routes require their own throttle policy, stricter than the general API limit. Login should permit no more than five attempts per fifteen-minute window per IP. Password reset should be tighter still, three attempts in the same window, because it is a lower-friction account recovery path that attackers target specifically. These limits must be configured separately from the global API throttle, not inherited from it.
At the infrastructure layer, Cloudflare or an equivalent reverse proxy should enforce rate limiting on the /auth/* path before requests reach the application at all. This protects against distributed credential stuffing from rotating IPs, which application-layer throttling alone cannot address.
Complementing both: account lockout after N consecutive failures with an email notification to the legitimate owner, and exponential backoff enforcement so that even attempts that don't trigger a hard lockout face increasing delays. Lockout without notification is incomplete, the user needs to know their account was targeted.
All three controls, application throttle, infrastructure limit, and lockout with notification, are required together. Any single one of them is bypassable in isolation.
What the AI Got Right and Why That Creates a False Sense of Security
This is the most important part of this article, and the most counterintuitive.
The platform was not universally broken. The AI-generated code correctly implemented:
SQL injection resistance - classic payloads and logical tautologies (
OR '1'='1) returned standard 401 responses. The ORM was correctly parameterizing queries.NoSQL operator injection resistance - object-based operators (
{"$gt": ""}) were rejected without triggering database logic.Password hash protection - no authentication primitives (hash, salt) appeared in any API response. Serialization exclusions were working.
Type validation - array and object injections on string fields were rejected with typed validation errors (
"name must be a string").User enumeration prevention on password reset - the endpoint returned a generic confirmation message regardless of whether the email existed.
Partial property protection - fields like
subscriptionStatus,hasUnlimitedAccess, andtrialEndsAtwere correctly excluded from the update DTO.
A superficial review, or a non-security-trained developer testing their own code, would find all of these controls working and conclude the platform is secure. The vulnerability was invisible to functional testing. It only appeared when someone specifically asked: "can I write a field I shouldn't be able to write?"
This is the core danger of unreviewed AI-generated code in production: it is selectively correct. Enough controls work to create confidence. The missing controls are the ones that require understanding intent, and LLMs cannot infer intent that was never stated.
The Specific Risk Profile of AI-Built Payment Platforms
When a non-developer builds a payment platform with AI assistance, three structural problems compound.
The prompt never includes the security specification. A developer prompting "add a subscription checkout flow" is thinking about UX and conversion. They are not thinking about whether the plan field should be writable by the user. The AI produces what was asked. What was not asked is not produced, and no warning is issued about what is missing.
Functional testing confirms the wrong things. "Does the payment flow work?" and "Can a user manipulate their own subscription record?" are different questions. The first is tested naturally during development. The second requires adversarial thinking that is not part of a non-developer's mental model, and AI-assisted testing will not supply it unprompted.
Payment data increases the attack surface value. A free-tier blog with a mass assignment flaw is a nuisance. A subscription SaaS with CPF numbers, billing data, and AI credit balances with the same flaw is a target. The financial and regulatory stakes of a breach scale with what the platform collects, and payment platforms collect the most sensitive data of all.
Pre-Launch Security Checklist for AI-Built Platforms Handling Payments
Before any AI-generated platform that handles payments goes live, every mutation endpoint must be verified against the following, by a human, not another AI.
DTO separation. Is the update DTO derived from the entity schema, or defined strictly by what users are permitted to change? These must never be the same object.
Privileged field isolation. Are
role,plan,subscriptionStatus,credits, and any field with monetary or permission value absent from user-facing DTOs?Object ownership. Can user A modify user B's record by substituting a UUID in the URL? Every endpoint must verify that the authenticated user's identity matches the resource being modified, or use
/meroutes that derive identity from the token exclusively.Rate limiting on auth. Is there a throttling policy on login, forgot-password, and reset-password endpoints? Absence means credential stuffing is unconstrained.
Admin endpoint isolation. Are privileged operations, such as role changes, plan upgrades, and credit grants, on separate routes protected by role guards, or are they writable through the same endpoint that regular users access?
LGPD exposure assessment. What personal and financial data is stored? Who can access it via the API? Is access logged? A platform processing CPF and payment data is a data controller under LGPD regardless of its technical origin.
Conclusion: AI Can Build the Platform. It Cannot Audit It.
The client in this case did the right thing: they built fast with AI assistance, then requested a human review before the platform scaled. The vulnerabilities found were severe but contained, as no breach occurred because the audit happened before significant user growth.
That sequence, build with AI and audit with humans before launch, is the correct workflow. What is dangerous is the inverse: launching with AI-generated code, growing a user base, collecting payment data, and only discovering access control failures after a breach or a regulatory inquiry.
AI coding assistants will continue to improve. They will not, in the near term, replace the adversarial thinking required to audit authorization logic, because adversarial thinking requires understanding what a system should prevent, not only what it should do. That understanding lives with humans who know the business context, the regulatory environment, and the threat model.
If you are building a platform with AI assistance and it touches subscriptions, payments, or user data: get a human to review it before it goes live. The cost of an audit is a fraction of the cost of a breach, financial, reputational, or regulatory.
References
[1] OWASP Foundation. (2023). OWASP API Security Top 10 2023. https://owasp.org/API-Security/
[2] NestJS Documentation. (2024). Security — Authorization. https://docs.nestjs.com/security/authorization
[3] NestJS Documentation. (2024). Security — Rate Limiting. https://docs.nestjs.com/security/rate-limiting
[4] Pearce, H., Ahmad, B., Tan, B., Dolan-Gavitt, B., & Karri, R. (2022). Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributions. Proceedings of the 43rd IEEE Symposium on Security and Privacy (S&P 2022), pp. 754–768. https://doi.org/10.1109/SP46214.2022.9833571
[5] Brasil. Lei nº 13.709, de 14 de agosto de 2018 (LGPD) — Lei Geral de Proteção de Dados Pessoais.
[6] Saltzer, J. H., & Schroeder, M. D. (1975). The protection of information in computer systems. Proceedings of the IEEE, 63(9), 1278–1308.
The platform audited in this study is not identified by name or domain. The audit was conducted with full written authorization from the platform operator. No third-party user data was accessed or extracted. Published for educational purposes within the DevSecOps, NestJS, and AI-assisted development communities.