Skip to content

Security

AI-Generated Code Security: How We Pen-Test It

Day45th Engineering · · 8 min read

An engineer reviewing code and a network graph on two monitors

How We Pen-Test AI-Written Code Before It Ships

AI coding tools have changed how software gets built. They’ve also changed how it breaks.

In 2025, Veracode tested code from leading AI models across dozens of common programming tasks. The result: AI-generated code introduced an OWASP Top 10 vulnerability in about 45% of tasks. Java fared worst, failing more than 70% of the time. Just as important, newer and larger models didn’t produce meaningfully more secure code.

Real incidents followed. In 2025, a vulnerability in a popular AI app builder (CVE-2025-48757) exposed data from more than 170 apps built on it. In Retool’s 2026 survey, 93% of IT and security leaders said they were concerned about “vibe-coded” tools running in production.

None of this means you shouldn’t use AI to build software. We use it every day, and it’s why we can ship in 45 days. It means you need a process that assumes AI code is guilty until proven innocent. Here’s ours.

Why AI code fails in predictable ways

AI models learn from huge amounts of public code, including plenty of insecure code. They’re optimised to produce something that works, not something that’s safe. The failure modes are consistent:

  • Missing authorisation checks. The endpoint works, but any logged-in user can read anyone’s data.
  • Injection. User input concatenated into queries or shell commands.
  • Hard-coded secrets. API keys pasted into code “for now”.
  • Outdated or hallucinated dependencies. Packages with known vulnerabilities, or names that don’t exist and can be squatted by attackers.
  • Over-permissive defaults. Wide-open CORS, public storage buckets, verbose error messages.
  • Logic flaws. A discount applied twice, or a status that can be skipped.

Because these patterns are predictable, they’re catchable, if you look for them deliberately.

Our seven gates

Every Day45th release passes seven gates. Nothing ships if a gate fails.

Gate 1: Threat model

Before code, we ask what could go wrong for this data and these users. Who are the actors? What’s sensitive? What would an attacker want? A one-page threat model shapes what we test later.

Gate 2: AI-assisted build, clearly tracked

AI drafts code inside our normal workflow. Every change arrives as a pull request, so nothing is pasted straight into production.

Gate 3: Senior code review

A senior engineer reviews every merge. Reviewers use a short checklist built from the failure modes above: authorisation on every endpoint, parameterised queries, no secrets, input validation and least-privilege access. This is the single most valuable control, and AI can’t do it for you.

Gate 4: Static analysis and secret scanning

Automated static analysis (SAST) and secret scanning run on every commit in CI. They catch the easy mistakes so humans can focus on the subtle ones.

Gate 5: Dependency audit

Every package is checked against known-vulnerability databases. We pin versions, remove anything unused, and verify that suggested packages actually exist and are the ones we expect.

Gate 6: VAPT

Before release, our security team runs a vulnerability assessment and penetration test, combining automated scanning with manual testing aligned to the OWASP Top 10 and the OWASP ASVS. Manual testing matters most for authorisation and business-logic flaws, which scanners routinely miss. Testers try to:

  • access another user’s or tenant’s data,
  • escalate privileges,
  • inject into every input,
  • abuse APIs (rate limits, mass assignment, insecure direct object references),
  • break the business logic.

Gate 7: Fix, re-test, sign off

Findings are fixed, re-tested and signed off. The client gets a report: an executive summary for buyers and auditors, plus technical detail for engineers.

What you should ask any vendor building with AI

Whether you hire us or someone else, ask these five questions:

  1. Does a senior human review every line of AI-generated code before it merges?
  2. Do you run SAST, secret scanning and dependency checks in CI?
  3. Is there a manual penetration test before launch, and do I get the report?
  4. Where does my data live, and is it ever sent to an AI provider that retains it?
  5. Who owns the code, and can I see the repository from day one?

Vague answers are an answer.

If you’ve already shipped an AI-built app

Plenty of founders and internal teams have built something useful with AI tools that has quietly become business-critical. If that’s you, a sensible order is:

  1. Find your secrets. Rotate any key that has ever been in code.
  2. Check authorisation. Can one user see another’s data? Test it with two accounts.
  3. Lock down storage and CORS. Nothing public that shouldn’t be.
  4. Update dependencies and remove unused ones.
  5. Get a pen test before your next customer, investor or auditor asks for one.

We do this as a fixed-price App Rescue & Hardening engagement, usually in two to three weeks.

The bottom line

AI makes building software faster and cheaper, and on its own it makes software less safe. The answer isn’t to avoid AI. It’s to pair it with experienced people and a pipeline that treats every AI-written line as untrusted until it’s reviewed and tested.

That’s what “AI-built, human-hardened” means.


Want to see what this looks like in practice? See our seven release gates or book a free call to talk through the security of something you’ve already built.

Sources: Veracode GenAI Code Security Report (2025); CVE-2025-48757; Retool survey (2026); OWASP Top 10 and ASVS.

Hands on a laptop showing a business analytics dashboard

Free 30-Minute Call

Want This Applied to Your Business?

Bring your software bill, your messiest spreadsheet or the process you'd hand to an AI agent. You'll get an honest answer.

Live by day 45. Fixed price.

Book a Free Call