AI-Assisted Engineering

The Hidden Problems With AI-Generated Code: Security, Bugs and Technical Debt

AI assistants make developers faster, and they also introduce problems that do not show up immediately: insecure patterns delivered with confidence, plausible but wrong answers, hallucinated packages and a slow build-up of inconsistent, duplicated code. We look at the evidence and the practices that keep these problems in check.

By EthicalHat Research · · 3 min read
Infographic: The hidden costs of AI-generated code

AI coding assistants are now used by a large share of developers, and the productivity benefits are real. But some costs of AI-generated code do not show up in a demo or even in the first sprint. They show up months later, in security reviews, incident reports and codebases that have become harder to change.

Here are the hidden problems, with the evidence behind them.

1. Security: less secure code, more confidence

Earlier research found that a large share of AI suggestions in security-relevant scenarios contained vulnerabilities. A Stanford study, Do Users Write More Insecure Code with AI Assistants?, to be presented at the ACM CCS conference later this month, went further by studying people. Participants who had access to an AI assistant wrote significantly less secure code on several tasks than those without one, and were more likely to believe their code was secure.

That combination is the real risk: vulnerable patterns delivered fluently, to developers who feel reassured by the tool.

Common patterns include:

  • string-built SQL and shell commands,
  • missing authorisation checks in generated endpoints,
  • weak or outdated cryptography,
  • disabled certificate verification "to make it work", and
  • secrets inlined in configuration examples.
python
# A fix that "works" and is often suggested for SSL errors: never do this
requests.get(url, verify=False)

# What should happen instead: fix the trust store or pin the correct CA bundle
requests.get(url, verify="/etc/ssl/certs/internal-ca.pem", timeout=10)

2. Correctness: plausible but wrong

A Purdue University study this summer analysed ChatGPT's answers to Stack Overflow programming questions and found that 52% contained incorrect information. Yet in a user study, participants still preferred the ChatGPT answers a substantial share of the time, citing their comprehensiveness and well-articulated style, and often overlooked the errors.

Fluency is persuasive. Wrong code that is well formatted, well commented and confidently explained gets less scrutiny than it deserves.

3. Supply chain: hallucinated packages

Assistants sometimes recommend installing packages that do not exist. Security researchers showed this year that attackers can register those hallucinated names on public registries (npm, PyPI) and publish malicious code, waiting for developers who follow the AI's advice to install it.

bash
# Before installing a package an assistant suggested, check it is real and reputable
pip index versions some-suggested-package      # does it exist? how many versions?
npm view some-suggested-package time.created maintainers repository

Check that suggested packages exist, are actively maintained, are widely used and come from the expected publisher.

4. Technical debt at speed

When producing code becomes much cheaper, some things increase quietly:

  • Duplication. Assistants happily generate a new helper rather than finding the existing one, so codebases accumulate several versions of the same logic.
  • Inconsistency. Suggestions follow patterns from public code rather than your team's conventions.
  • Churn. Code that is written quickly and rewritten soon after.
  • Bloat. More code than needed, because generating it cost nothing.

None of this breaks a build. All of it makes the codebase harder to understand and change later.

5. Skills that never get built

Developers, particularly early in their careers, learn by struggling through problems. An assistant that always provides an answer can short-circuit that learning, leaving developers able to produce code but less able to debug, review or design it, which are exactly the skills needed to catch the problems above.

Practices that keep these problems in check

flowchart TB
  G[AI-assisted change] --> A[Automated gates<br/>tests, types, lint,<br/>SAST, SCA, secrets]
  A --> D[Duplication & dependency checks<br/>new packages reviewed]
  D --> R[Human review<br/>intent, security, fit with codebase]
  R --> M[Merge]
  M --> Me[Metrics<br/>defects, churn, vulnerabilities]
  Me -->|feedback| P[Team norms & training]
  • Keep human accountability. Whoever merges the code owns it.
  • Automate security checks on every pull request: SAST, dependency scanning, secret scanning and IaC scanning.
  • Review new dependencies explicitly, especially ones suggested by an assistant.
  • Give assistants good context: shared helpers, clear conventions and secure examples in the codebase lead to better suggestions.
  • Watch duplication and churn metrics as early warning signs.
  • Protect learning: encourage juniors to ask for explanations, pair on reviews and sometimes solve problems without assistance.
  • Train reviewers on the specific failure modes of AI-generated code.

The bottom line

AI-generated code is not inherently worse than human code, but it fails in characteristic ways: confidently insecure, plausibly wrong, supply-chain unaware and quietly repetitive. Organisations that recognise those patterns and build them into their reviews, tooling and training get the productivity gains without paying for them later.

Our secure code review and application security testing services are tuned to the patterns AI assistants introduce, and our security training teaches developers to review AI-generated code critically.

EthicalHat Research

The EthicalHat research team: penetration testers, SOC analysts and engineers writing about security, software engineering and AI.

Want an expert opinion on your own systems?

Email info@ethicalhat.com or call +1-844-838-4422. Our security engineers are happy to talk it through.