All posts

    Agent security

    Security Review for AI-Generated Code: What to Check Before You Merge

    A review-to-merge worksheet for AI-written changes: verify code, dependencies, access, secrets, delivery and the evidence behind a test result.

    Harden banner: Review Before You Merge. A diff-to-test-to-Git-merge diagram is paired with Claude Code, OpenAI Codex and Cursor logos. Merge is a Git operation, not the Merge company.

    Executive summary

    Review AI-generated code against the intended change, the actual diff and independently observed test results before merging it. Inspect dependencies, authorization, secrets and workflow configuration as well as application logic. Keep code quality and agent behavior as separate review questions: a safe-looking patch does not explain every operation used to produce it. Give consequential changes an accountable reviewer and retain the evidence that supports the merge decision.

    Review the change, not the confidence of the explanation

    A coding agent fixes a checkout bug and presents a concise summary. It says the tests passed and the change is ready. The diff also updates a build workflow and adds a dependency nobody requested.

    Those extra changes may have a reasonable explanation. They still need review. The summary is a claim about the work, while the diff and test artifacts are evidence a reviewer can inspect.

    Whether a team uses Claude Code, Codex or Cursor, begin with the requested behavior. Ask what should change for the user and what should remain unaffected. Then read the patch without relying on the agent's account of its scope.

    GitHub's responsible-use guidance for agents calls for reviewing and testing generated work before merging. The useful practice is to make that review concrete enough that a person can explain why the change is acceptable.

    Establish the intended boundary

    Keep the task and acceptance conditions near the pull request. A calculation fix might require updated arithmetic, a regression test and a short explanation. It should not silently become a migration, a credential change or a redesign of deployment permissions.

    Separate requested changes from incidental cleanup. If the agent reformats unrelated files, the larger diff can make important behavior harder to see. Consider splitting unrelated work into another change rather than asking a reviewer to approve everything together.

    Review the final revision, not a previously tested commit. If the patch changes after checks finish, identify which evidence remains applicable. A green result attached to an earlier state does not describe the current files simply because it appears in the same pull request.

    Follow the inputs that affect behavior

    Inspect application code, dependency files, scripts and configuration as one change set. A small code edit can rely on a new package, installation hook or environment variable that changes the deployment's behavior.

    Use the following worksheet as an illustrative review aid:

    Area Question Evidence to inspect
    Application logic Does the patch satisfy the intended behavior? Diff, acceptance case and affected call paths
    Dependencies What new executable behavior enters the project? Manifest, lockfile and package provenance
    Authorization Can a different identity now reach this operation? Access checks and relevant negative tests
    Secrets Does private material reach code or artifacts? Sanitized scan findings and configuration review
    Delivery Can this revision change how code reaches production? Workflow diff, permissions and release controls

    The worksheet does not certify a change. It helps assign the right question to the artifact that can answer it. A dependency scanner and a human reviewer may identify different problems in the same patch.

    For dependency provenance and installation risk, our package-security guide covers the agent's installation path. Keep that question separate from whether the resulting application code meets its requirements.

    Verify tests from the system that ran them

    Open the check result and confirm the tested revision, environment and outcome. Review skipped cases and changed test configuration. Ask whether a new test would fail against the old behavior and pass against the intended fix.

    An agent can accidentally write a test that repeats the implementation's mistaken assumption. It can also remove a failing assertion while making the rest of the suite pass. Read the test diff as carefully as the code it is supposed to check.

    Use negative cases where the change affects access or sensitive operations. An authorized user succeeding does not establish that another user is rejected. A test against a disposable fixture can validate the intended distinction without exposing production resources.

    When the evidence is incomplete, state the missing check and give it an owner. Do not convert “not tested” into “probably safe” because the patch is small or the explanation sounds certain. Our agent security-testing article offers a separate approach for testing the agent's permitted actions.

    Treat security findings as claims to verify

    Run the project's established code, dependency and secret checks. Read the relevant findings and resolve exceptions through the normal process. A tool's absence of findings has a scope: the rules, languages, configuration and files it examined.

    Review automated fixes too. GitHub's security-and-quality AI feature guidance describes developer review and validation of proposed fixes. A generated repair may address one alert while changing behavior elsewhere.

    Keep the review focused on the actual failure path. If an authorization check moves, inspect which caller reaches the new location. If a query changes, verify how untrusted input is handled. If a workflow gains write permission, determine what task requires it and which events can trigger that workflow.

    Keep the agent's actions in view

    A pull-request review primarily examines the proposed change. The agent may also have run commands, accessed resources or contacted services while producing it. Those actions can matter even when they leave no trace in the final diff.

    Harden evaluates supported agent calls before execution, adding a task-aware boundary around those operations. That complements review of the resulting code; it does not establish that the application is free of vulnerabilities. Keep both questions in the handoff record.

    For example, the code reviewer can inspect the checkout fix while a separate action record helps explain why the agent attempted a deployment during a repository-only task. Verify the supported integration and available evidence instead of assuming every background process was observed.

    Make the merge decision explainable

    Name the reviewer responsible for consequential behavior and record the unresolved risks, if any. Keep the accepted revision tied to its checks. A later change to code, dependencies or workflow permissions should receive the review it needs.

    The decision can be short: the requested behavior works, relevant access cases were checked, dependencies were reviewed, no unexplained delivery changes remain and the required owner accepted the evidence. Every statement should have an artifact behind it.

    If the team wants to evaluate the action boundary alongside its existing review process, start with one representative workflow in Control. Configure the supported integration and keep the legitimate development task in the evaluation. The objective is a reviewable change produced through an appropriately controlled workflow.

    FAQs

    Should AI-written code receive a different quality standard?

    Use the project's required quality and security standard. Adjust the review effort to the change's consequences and the reliability of its evidence. Generated code still needs accountable ownership, meaningful tests and examination of the behavior it introduces.

    Can an AI reviewer approve another agent's patch?

    It can assist with finding problems and organizing review. Assign the merge decision according to the team's ownership rules. Inspect consequential findings and test artifacts directly; agreement between two models is not independent evidence that the change behaves correctly.

    What if the test suite passes but coverage is weak?

    Identify the behavior the current checks do not exercise and add appropriate verification. A passing suite establishes only what those checks cover. Access-sensitive changes often need both permitted and rejected cases, with the tested revision and environment recorded.

    Does a clean diff show that the agent acted safely?

    It shows the proposed file changes. Commands, network requests and operations in external systems may not appear there. Review relevant action and resource evidence separately when the workflow can affect sensitive information or systems.

    Does Harden replace code scanning or pull-request review?

    No. Its supported pre-execution checks concern the agent's proposed actions. Code scanning and review examine properties of the resulting software and change set. Define each responsibility explicitly and verify how the controls work together in the team's actual workflow.