How AI Remediation Works

The modern AI auto-remediation pipeline connects three components: a vulnerability scanner, a large language model, and a version control system. When the scanner produces a finding, the LLM receives the finding alongside the relevant code context and produces a diff that resolves the issue. That diff is opened as a pull request for human or automated review.

The quality of the fix depends entirely on how much context the LLM receives. Early naive implementations sent only the CVE identifier and the vulnerable line. Modern implementations send the full function, surrounding imports, the test suite for that module, and the scanner's explanation of why the code is vulnerable β€” dramatically improving correctness.

remediation-prompt-context.txt Prompt
# Context sent to the LLM for a SAST finding
vulnerability: CWE-89 SQL Injection
file: src/api/users.py
line: 47
scanner: Semgrep rule python.sqlalchemy.sql-injection

vulnerable_code: |
  query = f"SELECT * FROM users WHERE id = {user_id}"
  result = db.execute(query)

function_context: [full 80-line function]
test_file: tests/test_users.py
imports: [relevant imports]

instruction: Fix the vulnerability. Do not change behaviour.
              Return a unified diff only. No explanation.

The LLM returns a diff. The remediation pipeline applies it, runs the test suite, and β€” if tests pass β€” opens a pull request tagged with the vulnerability details and the scanner finding.

What AI Remediation Can and Cannot Fix

Vulnerability classes vary enormously in how amenable they are to automated patching. The pattern breaks down into three tiers:

High-confidence auto-fix candidates

  • Dependency vulnerabilities β€” bump a version number with compatible API
  • Missing security headers β€” add X-Frame-Options, Content-Security-Policy, etc.
  • Hardcoded secrets β€” replace literal with environment variable reference
  • SQL injection via string formatting β€” switch to parameterised queries
  • Disabled TLS verification β€” remove verify=False, InsecureSkipVerify
  • IaC misconfigurations β€” restrict cidr_blocks, add encryption flags

Moderate confidence β€” requires review

  • XSS fixes requiring output encoding β€” context-dependent
  • Path traversal β€” normalisation logic can introduce bugs
  • Command injection β€” subprocess refactoring is risky if args are complex

Do not auto-fix

  • Business logic vulnerabilities
  • Authentication and authorisation flaws β€” model rarely understands the full auth context
  • Race conditions and TOCTOU bugs
  • Cryptographic algorithm selection β€” wrong choice can be subtly catastrophic

Warning: AI remediation engines optimise for "passing tests" as a proxy for correctness. A fix that passes all existing tests but introduces a new vulnerability is the worst outcome β€” it closes the scanner finding while adding a new attack vector.

Pipeline Design

A production-grade AI remediation pipeline has five stages:

  1. Finding enrichment β€” augment the raw scanner finding with code context, function boundaries, test coverage, and past fix history for similar vulnerabilities.
  2. LLM patch generation β€” send enriched context to the LLM with a strict output format (unified diff only, no prose).
  3. Patch validation β€” apply the diff to a clean branch, run linters, type checkers, and the test suite.
  4. Re-scan β€” run the original scanner against the patched code to verify the finding is actually resolved.
  5. PR creation β€” open a pull request with full provenance: original finding, LLM prompt, generated diff, test results, re-scan result.

Steps 3 and 4 are non-negotiable. Without validation, you are merging unreviewed AI code into production.

Approval Gates

The degree of automation versus human review depends on the vulnerability class and the confidence score of the generated fix. A sensible tiered model:

  • Auto-merge β€” dependency bumps where the API is identical and the test suite is comprehensive. Low risk, high volume.
  • Auto-PR, security-team approval β€” code changes that fix injection or TLS issues. Human eye on the diff before merge.
  • Auto-PR, lead-engineer approval β€” any fix touching authentication, session management, or cryptography.
  • No auto-fix β€” business logic, access control, IDOR. These require architectural understanding the LLM does not have.

Tip: Add the AI-generated diff as a code review comment alongside the original scanner finding. Reviewers who see both together make better decisions than reviewers who see only the diff.

Risks of AI-Generated Fixes

The primary risks are not the obvious ones:

  • False confidence β€” a green test suite is not proof of correctness. SAST re-scan passes because the old pattern is gone, not because the new code is safe.
  • Context truncation β€” LLMs have context windows. For large files, the patch may not see the full function it is modifying, leading to subtly broken logic.
  • Hallucinated APIs β€” the model may use a library function that does not exist in the version you are running.
  • Scope creep β€” "fix the vulnerability" prompts sometimes cause the model to refactor surrounding code, changing behaviour beyond the intended scope.
  • Test gaming β€” if the model can see the test suite, it may produce a fix that makes tests pass without addressing the root cause.

Tooling Landscape

Several tools now offer AI-powered remediation as a first-class feature:

  • AquilaX β€” integrated scanner with AI remediation suggestions and PR generation, with configurable auto-merge policies per vulnerability class.
  • Snyk DeepCode AI β€” AI fix suggestions integrated into Snyk's SCA and SAST findings.
  • GitHub Copilot Autofix β€” generates fix suggestions directly in the GitHub code scanning UI.
  • Pixee β€” specialised Java and Python auto-remediation using a library of hardened code transformations.

Getting Started

The lowest-risk way to introduce AI auto-remediation:

  1. Start with dependency vulnerability auto-fix only β€” the blast radius of a wrong version bump is small and reversible.
  2. Require passing tests and a re-scan before any PR is auto-opened.
  3. Run in observation mode for 30 days β€” generate PRs but do not auto-merge. Review the quality.
  4. Gradually expand to code-level fixes for high-confidence classes with security team sign-off.
  5. Track the false-fix rate (fixes that pass tests but reintroduce the vulnerability in a different form) as your primary quality metric.

"Auto-remediation that ships a new vulnerability to fix an old one is strictly worse than no auto-remediation. Measure false-fix rate before you measure velocity."