Test safely / Module 08

Use AI to accelerate secure code review without inventing findings

Combine model-assisted review with static analysis, tests, dependency evidence, and developer context.

55 minutes Intermediate Practical lab
01

Give the model a narrow review contract

Ask for concrete trust boundaries, data flows, dangerous APIs, and missing authorization checks rather than a generic find all vulnerabilities prompt. Supply only the files and dependencies needed, and remove secrets, customer data, and proprietary context that the chosen service is not approved to process.

Require the response to state file, line, precondition, data flow, CWE where applicable, confidence, and evidence still needed. This makes weak guesses visible.

02

Triangulate every claim

Confirm model hypotheses with source tracing, tests, compiler or type feedback, static analysis, dependency advisories, and runtime behavior in an isolated fixture. Reject findings that depend on unreachable code, sanitized inputs, impossible permissions, or invented library behavior.

Also look for what the model misses: authorization at object level, race conditions, business logic, deployment configuration, and interactions spread across multiple services.

  • Hypothesis: a plausible weakness that needs evidence.
  • Finding: a reproducible condition with affected asset and impact.
  • Fix: a specific change at the root control boundary.
  • Regression: a test that fails before the fix and passes after it.
  • Residual risk: what the fix does not cover.
03

Protect the review pipeline

Source files, issue text, dependency metadata, generated code, and repository instructions are all untrusted inputs to an AI coding workflow. Limit repository write permissions, review tool calls, isolate build execution, and block secret access by default.

Do not allow a model to merge, deploy, or rotate production configuration merely because it identified a problem. Separate diagnosis, patch proposal, verification, and release authority.

Fast review is useful only when the evidence and release controls remain slower than a bad assumption.

Practice

Review a toy authorization bug

Safety boundary: Use a small local application created for training.

  1. 01

    Create a read endpoint that looks up a record by ID but forgets to check the requesting owner.

  2. 02

    Ask the model for a structured review without requesting exploit payloads.

  3. 03

    Confirm the data flow manually and write a failing authorization test.

  4. 04

    Add the ownership check and rerun the test.

  5. 05

    Record whether the model explanation matched the verified root cause.

Checkpoint

Ready to move on?

Go deeper

Primary sources for this module

All resources
Previous module07 · Test prompt injection as a control failure Next module09 · Understand evasion, poisoning, privacy, and model extraction
Share this module LinkedIn Email Permanent link