Secure AI Engineering

AI-Generated Code: Security Risks for Modern Development Teams

AI code assistants are spreading through development teams during Copilot's extended preview, often before security or legal teams have been consulted. This article looks at the team-level risks (vulnerable suggestions, leaked secrets, licensing and review fatigue) and a lightweight governance model to adopt the tools safely.

By EthicalHat Research · · 3 min read
Infographic: AI-generated code risks at a glance

GitHub Copilot's technical preview has been running for nearly a year, and similar tools are appearing. In many organisations, developers started using AI code assistants on their own initiative, installing an extension and signing up with a personal account. Security, legal and engineering leadership often found out later.

The productivity benefits are real, and so are the risks. This article looks at them from the perspective of a development team and its security partners.

Risk 1: vulnerable suggestions

The most cited research, Asleep at the Keyboard? from New York University (published in 2021 and appearing at IEEE Security & Privacy this month), asked Copilot to complete code in scenarios related to the most dangerous software weaknesses. About 40% of the programs it produced were vulnerable.

Common patterns include SQL built from strings, missing input validation, weak hashing, hard-coded credentials and unsafe file handling. The model reproduces what it has seen, including insecure code.

Risk 2: secrets and sensitive data

Two directions of risk:

  • Out: code context, which may include credentials or proprietary logic, is sent to the assistant's cloud service. Organisations need to understand what is sent, how it is retained and whether it may be used for training.
  • In: suggestions sometimes include placeholder or example credentials that developers leave in, and patterns that encourage hard-coding secrets.

Risk 3: licensing and provenance

Models trained on public code occasionally reproduce recognisable snippets. Where that code is under a restrictive licence, including it without attribution may create obligations. The legal questions are unresolved, and some organisations are waiting for clearer answers before allowing AI assistants on commercial products.

Risk 4: weaker review habits

Perhaps the most subtle risk is behavioural. Well-formatted, confidently generated code can receive less scrutiny than it deserves, from the developer who accepted it and from reviewers who assume it is boilerplate. Junior developers may accept code they do not fully understand.

A lightweight governance model

Banning AI assistants rarely works. Developers find them useful and will use them anyway. A lighter approach:

flowchart TB
  P[1. Policy<br/>approved tools & settings,<br/>no-go areas, ownership] --> C[2. Controls<br/>SAST, secrets & dependency<br/>scanning on every PR]
  C --> R[3. Review<br/>same standard for AI code,<br/>extra care in sensitive paths]
  R --> T[4. Training<br/>common AI failure modes]
  T --> M[5. Measure<br/>findings, incidents,<br/>developer feedback]
  M --> P

1. A one-page policy. Which tools are approved, and with which settings? Which code may not be sent to third-party services? Which areas (authentication, cryptography, payments) require extra caution? Who owns AI-assisted code? (The developer who accepts it.)

2. Automated controls on every pull request. SAST, secret scanning and dependency scanning catch many of the patterns assistants produce. They should run regardless of how code was written.

3. Consistent review standards. Reviewers should apply the same scrutiny to AI-assisted code as any other, and more in sensitive paths. Some teams ask authors to note when significant portions were AI-generated.

4. Targeted training. Short sessions on the typical failure modes of AI suggestions, using real examples from your codebase if possible.

5. Measurement. Track security findings, review comments and developer feedback to adjust the policy.

Practical tips for developers

  • Treat suggestions like code from an unknown contributor: read every line before accepting.
  • Ask yourself what inputs could break the suggested code.
  • Never accept credentials, keys or tokens in suggestions, even as placeholders.
  • Prefer your project's existing helpers over generic suggested implementations.
  • Write or keep tests that exercise edge cases and security requirements.
python
# Suggested code often looks like this: works for the demo, fails the security review
def load_user_file(filename):
    return open(f"/srv/uploads/{filename}").read()          # path traversal

# What the project's helper should enforce
def load_user_file(user, filename):
    path = safe_join(user_upload_dir(user), filename)        # rejects ../ and absolute paths
    with open(path, "rb") as f:
        return f.read()

The bottom line

AI code assistants will be part of most development teams soon, whether or not they are formally adopted. The risks (vulnerable suggestions, data exposure, licensing and complacent review) are manageable with a short policy, automated checks that apply to all code, consistent reviews and targeted training. The worst option is to ignore the tools and discover later what they have been writing.

Our secure code review and security training services help teams adopt AI assistants with the right guardrails.

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.