Security Review for AI-Generated Code
Short answer
AI-generated code tends to fail in predictable places: missing authorization checks, injection through string-built queries, hardcoded secrets, insecure defaults and dependencies that are outdated or do not exist. A security review combines automated scanning for secrets, dependencies and known patterns with a manual review of authentication, authorization and data flows, and fixes those findings before an external penetration test.
Why generated code needs its own review focus
Coding agents produce code that compiles, passes the happy path and looks idiomatic. That is exactly what makes their security flaws easy to miss. The model optimises for a working feature as described in the prompt. Unless the prompt or instruction file says otherwise, nobody told it who must not be able to use that feature. Reviewers also tend to skim large generated diffs. The result is a recognisable pattern of weaknesses, which is good news: you know where to look.
The typical flaws
- Broken authorization: endpoints check that a user is logged in, but not that the record belongs to them. Changing an ID in the URL reveals someone else’s data.
- Client-side security: role checks and price calculations in the frontend only, with the API accepting whatever it receives.
- Injection: SQL built with string interpolation, shell commands assembled from user input, unescaped HTML rendered as markup.
- Secrets in code: API keys in source files, example config committed with real values, keys exposed through frontend environment variables.
- Dependency problems: outdated packages with known vulnerabilities, and hallucinated package names that do not exist or, worse, have been registered by attackers to catch exactly these mistakes.
- Insecure defaults: CORS open to every origin, debug mode on, verbose error messages with stack traces, no rate limiting on login and password reset.
- Weak session and token handling: tokens without expiry, JWTs not verified properly, password reset links that can be reused.
A review process that scales
Reviewing every line by hand does not scale when agents produce thousands of lines a week. Combine automation with focused human review:
- Threat model in one page: what data the app holds, who its users and roles are, which actions are sensitive.
- Secret scanning over the full Git history with a tool such as gitleaks or TruffleHog. Rotate anything found, deleting it from the code is not enough.
- Dependency scanning with npm audit, OSV-Scanner or Dependabot, plus a check that every dependency is a real, maintained package you intended to install.
- Static analysis with Semgrep or CodeQL in CI, so new findings block the pull request.
- Manual review of the critical paths: authentication, authorization on every endpoint, payment and file upload handling, admin functions.
- Dynamic checks against a staging environment, for example with OWASP ZAP, and with two test users trying to access each other’s data.
An AI reviewer can help triage findings and spot patterns, but it should not be the only reviewer of code that another AI wrote. Feed the lessons back into the instruction file of the repository so the agent stops repeating the same mistakes.
Preparing for a penetration test
A pentest is most valuable when it finds what your own review could not, not what a scanner would have caught. Before booking one:
- Fix all findings from the steps above.
- Provide a stable staging environment with production-like configuration and test accounts for each role.
- Write down the scope: domains, APIs, mobile apps, what is out of scope.
- Prepare architecture notes and the threat model, so testers spend time on attacks rather than discovery.
The OWASP Application Security Verification Standard is a good checklist for agreeing on the depth of testing with the pentest provider.
How jocapps can help
OnlineAppCreator is our ISO-certified B2B and B2G delivery team in Germany. It reviews and hardens AI-built code for production, fixes findings and prepares applications for external penetration tests, with long-term maintenance under an SLA if needed. To make your own team better at reviewing agent output, neooutput runs hands-on workshops on agentic coding, including secure review workflows, in English or German, on-site or remote. Our guide on security risks of agentic coding covers the process side. For a first conversation, book a free 30-minute intro call via the meeting planner.
Frequently asked questions
Is AI-generated code less secure than human-written code?
Not inherently, but it fails in predictable ways and is often reviewed less carefully because there is so much of it. A review focused on authorization, injection, secrets and dependencies catches most issues.
What is a hallucinated dependency?
A package name the model invents that does not exist in the registry. Attackers may register such names with malicious code, so every new dependency should be verified before installation.
Can an AI tool review AI-generated code?
It helps with triage and catching patterns, but it should complement, not replace, human review of the critical paths and automated scanners in CI.
Do I need a pentest if I did a security review?
For apps handling sensitive data or serving larger customers, an independent pentest after the internal review is strongly advisable. Many customers and tenders ask for one.
Guides on this topic
Related solutions
- Production readiness and auditsAccessibility Audit for Web and Mobile Apps Under the EAA
- Production readiness and auditsApp Performance Audit for Web and Mobile Apps
- Production readiness and auditsMaking a Bolt.new App Production-Ready
- Production readiness and auditsSecurity Review for Lovable and Supabase Apps
Talk to us about your project
Honest advice on your idea, prototype or app.
- 30 minutes
- Free
- No obligation
