Skip to main content

Challenge 5: Secure code review of AI-generated code and agents

Tools: Semgrep OSS (open source, LGPL 2.1) + Gitleaks (open source, MIT) · Frameworks: OWASP Top 10:2025 + CWE Top 25 · Time: 3–4 h

What you will build

A secure code review pipeline: you generate code with an AI assistant (Copilot, ChatGPT, Claude), deliberately reproduce the 6 most common vulnerability classes in AI-generated code, then detect and fix each one with free static-analysis tools. This is the artifact that proves you can be the human control gate for AI-written code — the fastest-growing requirement in AI Security job postings.

Where to run this: on your machine, inside the Step 0 environment. No cloud account required.

Why it matters for employment

AI coding assistants generate code faster than teams can review it, and studies from Snyk, Veracode, and Georgetown CSET consistently find that a meaningful share of AI-generated code samples contain at least one of the classic OWASP/CWE vulnerability classes — because the model was trained on code that also contained them. AI Security Engineer, AppSec Engineer, and "Secure AI-assisted development" job postings now explicitly ask for the ability to review, triage, and fix AI-generated code, not just prompt an LLM. This challenge gives you a repeatable, tool-backed process for exactly that.

🎯 The 6 vulnerability classes you will detect

Every AI coding assistant can reproduce these — they are old, well-documented weaknesses, not novel "AI" risks. Knowing them cold, and knowing how to find them automatically, is a core AppSec skill that transfers directly to reviewing AI output.

#VulnerabilityCWEOWASP Top 10:2025 categoryTypical AI-generated mistake
1SQL InjectionCWE-89A05:2025 – InjectionString-concatenated query instead of parameterized query/ORM
2Cross-Site Scripting (XSS)CWE-79A05:2025 – InjectionRendering user input into HTML/JS without escaping
3Path TraversalCWE-22A01:2025 – Broken Access ControlBuilding a file path from user input without validating ../
4Auth BypassCWE-287 / CWE-306A07:2025 – Authentication FailuresMissing auth check on a new endpoint the model scaffolded
5Secrets in CodeCWE-798A02:2025 – Security MisconfigurationHardcoded API key/password the model used as a "working example"
6SSRFCWE-918A01:2025 – Broken Access ControlServer fetches a URL supplied by the user with no allow-list

Category numbers verified against the current OWASP Top 10:2025 release — re-check before citing in an interview, as OWASP periodically renumbers categories.

Steps

# 1. Instala Semgrep (SAST) y Gitleaks (secret scanning) en tu entorno virtual
python -m pip install semgrep
# Gitleaks: descarga el binario para tu OS desde
# https://github.com/gitleaks/gitleaks/releases (o `brew install gitleaks` en macOS)

# 2. Crea un repo de práctica y pide a un asistente de IA (Copilot/ChatGPT/Claude)
# que genere 6 pequeños fragmentos de código, uno por vulnerabilidad:
# "Write a Flask endpoint that looks up a user by ID in SQLite" → probable SQLi
# "Write a Flask route that renders a comment submitted by a user" → probable XSS
# "Write a function that serves a file given a filename from the query string" → Path Traversal
# "Write an admin endpoint that deletes a user by ID" → probable Auth Bypass
# "Write a script that calls the OpenAI API" → probable secreto hardcodeado
# "Write a function that fetches and returns the content of a URL provided by the user" → SSRF

# 3. Corre Semgrep con el ruleset de OWASP Top 10 sobre el repo completo
semgrep --config p/owasp-top-ten .

# 4. Corre un segundo ruleset más amplio de seguridad general
semgrep --config p/security-audit .

# 5. Corre Gitleaks para detectar secretos
gitleaks detect --source . --report-path reports/gitleaks-report.json

# 6. Guarda ambos reportes en reports/ — son tu evidencia
Mapping: Semgrep/Gitleaks finding → vulnerability class → CWE
ToolRule/finding pattern (example)Vulnerability classCWE
Semgrep p/owasp-top-tenpython.lang.security.audit.formatted-sql-querySQL InjectionCWE-89
Semgrep p/owasp-top-tenpython.flask.security.audit.xss.debug / unescaped template renderXSSCWE-79
Semgrep p/security-auditpath-traversal-open / os.path.join with unvalidated inputPath TraversalCWE-22
Semgrep p/security-auditMissing @login_required / @require_auth decorator on sensitive routeAuth BypassCWE-287 / CWE-306
Gitleaksgeneric-api-key, openai-api-key, aws-access-keySecrets in CodeCWE-798
Semgrep p/security-auditrequests.get(user_supplied_url) without allow-listSSRFCWE-918

Rule IDs evolve with Semgrep's rule registry — run semgrep --config p/owasp-top-ten --json . and inspect check_id to see the exact IDs your version reports.

Alternative / complementary free tools
  • CodeQL (free for public repositories and open source) — GitHub's SAST engine; strong on all 6 classes and integrates with GitHub code scanning + Copilot Autofix.
  • Bandit (free, Python-specific) — good complement to Semgrep for Python-only projects, especially for hardcoded secrets and subprocess/eval misuse.
  • TruffleHog (free, open source) — alternative secret scanner with live credential verification.
  • OWASP ASVS — a free checklist to verify authentication/access-control requirements beyond what a scanner alone can catch (e.g., business-logic auth bypass).

📦 Deliverable

An ai-code-security-review/ repository with:

  1. README.md — which AI assistant generated the code, the prompts you used, and a summary table: vulnerability → CWE → OWASP category → severity.
  2. vulnerable/ — the original AI-generated snippets, unmodified (6 files, one per vulnerability class).
  3. fixed/ — your remediated version of each snippet, with a one-line comment explaining the fix.
  4. reports/ — raw Semgrep and Gitleaks output (JSON) as evidence.
  5. A short "lessons for prompting" section: what instruction you'd add to your prompt next time to reduce the chance the assistant reproduces each vulnerability (e.g., "always use parameterized queries," "never hardcode credentials, use environment variables").

✅ Success criteria

  • Reproduced and detected all 6 vulnerability classes (SQLi, XSS, Path Traversal, Auth Bypass, Secrets in Code, SSRF).
  • Each finding is mapped to its CWE ID and OWASP Top 10:2025 category.
  • Each vulnerability has a corresponding fixed version with an explanation.
  • Ran both Semgrep and Gitleaks and kept the raw reports as evidence.
  • The README is understandable by a non-technical hiring manager in 2 minutes.
Use disposable, synthetic examples only

Generate and test only in a local, throwaway repository. Never point these scanners at production code you do not own, and never commit real secrets (even fake-looking ones tied to real accounts) to a public repository.


Previous: ← Challenge 4 · Back to track home

🎓 You finished the track — now what?

  1. Publish the 5 repos on your GitHub and pin them on your profile.
  2. Write 1 LinkedIn post per challenge explaining what you learned (this creates recruiter visibility).
  3. Add the resume line to your CV.
  4. Prepare a 5-minute demo of your favorite for interviews.