TL;DR
- The pull request is the one step every change passes through before it reaches a shared branch, so it’s the right place to run AI SAST on code from developers and coding agents alike.
- A diff-aware PR scan reports only what the change introduces, but it traces data across the whole repository, which is how it catches flaws that live in unchanged code.
- Key merge blocking to the triage verdict, not severity alone: block confirmed true positives, comment on unknowns, and never block on false positives.
- Lock down the CI step with the pull_request trigger for forks, least-privilege permissions, keyless authentication, and actions pinned to a full commit SHA.
Why is the pull request the right place for AI SAST?
The pull request is the right place for AI SAST because it's the one step every change passes through before it reaches a shared branch, whether a developer or a coding agent wrote it. Editors, agents, and laptops vary across a team. The PR doesn't.
Almost half of companies now have codebases that are at least 50% AI-generated, up from 20% at the start of 2025. Volume isn't the only issue. In Carnegie Mellon researchers' SusVibes benchmark, 61% of an AI coding agent's solutions were functionally correct, while only 10.5% were secure. Code that passes tests and still ships a vulnerability is the kind of change a human reviewer skims and approves on a busy afternoon.
The flaws that matter in those diffs often have no pattern to match. Broken access control, missing authorization checks, and business logic errors depend on how the new code interacts with the rest of the application. In the June 2026 GA benchmark, Endor Labs AI SAST surfaced 3x more real vulnerabilities than frontier models, including business logic and access control flaws that rule-based SAST can't express. For a deeper look at those flaw classes, see our breakdown of what static analysis catches and misses in AI-generated code.
Teams in regulated sectors have a framework reason too. Practice PW.7 in the NIST Secure Software Development Framework calls for reviewing or analyzing source code to find vulnerabilities. Running automated review on every PR gives you a consistent, recorded way to meet that practice for human-written and AI-written code alike.
Where AI SAST runs, from the agent loop to scheduled scans
AI SAST works as a layered setup. Each location catches a different class of problem at a different speed, and the PR sits in the middle as the backstop.
AI coding agents can get security feedback while they generate code, so fewer issues reach the PR in the first place. AURI by Endor Labs is a security harness for agentic software development. It connects to coding agents through Hooks, Skills, MCP, CLI, and API, which lets an agent check its own output and fix problems before a human sees the diff. AURI handles the agent side. The PR scan still sees every change, no matter which agent or editor produced it.
At the front of the line, Endor Labs Secrets Detection stops leaks at pre-commit and validates findings as live or revoked. A validated live key needs rotating right away. A revoked one is a cleanup task.
Each merge to main refreshes the baseline that the next PR scan compares against. Scheduled full scans pick up issues that only appear when many changes combine, and they apply detection improvements to code that hasn't changed in months.
Diff-aware PR scans vs full baseline scans
A diff-aware PR scan reports only what the change introduces, but the analysis behind it needs the whole repository. The diff rarely contains the full story of whether something is exploitable.
Here's a worked example. A PR adds an export endpoint in routes/export.js:
- The handler reads orderId from the URL and sortBy from the query string.
- It calls getOrderRows(orderId, sortBy), an existing helper in db/orders.js.
- The helper builds a SQL query by concatenating sortBy into an ORDER BY clause.
- The helper never checks that the order belongs to the requesting user.
The diff shows a tidy 20-line handler that passes two values to a function. A diff-only scan sees no sink, no query, and no authorization logic, so it reports nothing. The vulnerable sink and the missing access check both live in unchanged code.
A scan that reports on the diff while tracing across the repository follows sortBy from the request into the helper and reaches the concatenated query. It also notices that orderId reaches a data read with no ownership check. That's a SQL injection and an insecure direct object reference. Both are new, even though the helper is old: before this PR, every caller passed hardcoded sort values and checked ownership upstream. The PR created the reachable path, so the finding belongs to the PR.
This is what Endor Labs detection agents do. They trace user-controlled data from source to sink across multi-file architectures, which is how a PR scan can report on the diff while reasoning over the whole repository. The detection agent documentation covers how the agent generates and tags those findings.
In Endor Labs, a baseline AI SAST scan must exist on the target branch before any PR scan can produce findings. The baseline gives the agents the full-repository context they need to reason about the changed code. You create it with:
endorctl scan --ai-sast --path=/path/to/code -n <namespace>The PR scan then runs the detection agent on only the code the pull request changes, with results in a few minutes:
endorctl scan --ai-sast --pr --pr-baseline=<target-branch> --path=/path/to/code -n <namespace>Endor Labs deduplicates PR scan findings against the baseline and records them as a PR run that doesn't affect main-branch monitoring scans. Developers see the issues their change introduced, not the backlog they inherited. The AI SAST scan documentation covers baseline setup, and the AI SAST PR scans guide explains how Endor Labs scopes PR scans.
What a useful PR comment contains
A useful PR comment gives the developer enough to fix the issue without opening another tool. It needs a location, a plain-language description, evidence, a verdict, and a fix. Here's the shape of one for the export endpoint above:
SQL injection via sortBy in order export (routes/export.js, line 14)
User input from the sortBy query parameter reaches a SQL query without validation.
Path: req.query.sortBy (routes/export.js:9) → getOrderRows(orderId, sortBy) (routes/export.js:14) → string concatenation into ORDER BY (db/orders.js:42) → db.query() (db/orders.js:44)
Verdict: True positive. The route is public, and no middleware sanitizes sortBy.
Suggested fix: Map sortBy to an allowlist of column names in the handler, and pass the mapped value to getOrderRows.
The path lets a skeptical developer verify the claim in 30 seconds. The verdict tells them whether this is worth their afternoon. The fix turns a ticket into a commit.
In Endor Labs AI SAST, triage agents classify each finding as true positive, false positive, or unknown, and remediation agents propose a context-aware fix. Those two outputs supply the verdict and the fix in the comment, and the verdict also gives your merge policy something reliable to key on. The PR comments documentation covers how to configure PR comments.
Comment hygiene matters as much as content:
- Post one comment per root cause. Five comments for one tainted parameter teach people to scroll past.
- Update the comment when new commits change the picture, instead of stacking new ones.
- Resolve the comment when the fix lands, so the PR conversation reflects current state.
Comment, fail, or block: setting PR policies
PR policies come in three enforcement levels, and each one asks something different of the developer:
- Comment only: findings appear on the PR as feedback. The check passes, and nobody waits.
- Fail the check: the security job reports a failing status. The PR shows red, but merging is still possible.
- Block merge: the failing check prevents merging. On GitHub, that's a required status check. On GitLab, it's a merge request approval rule or a pipeline-must-succeed setting. On Azure Repos, it's a branch policy.
Most teams phase enforcement by severity alone. That breaks down when severity labels are noisy, because developers learn that a red check often means nothing. Key enforcement to the triage verdict as well:
- Block merge only on findings classified as true positives at a severity you've agreed on, such as critical and high.
- Comment on findings classified as unknown, and route them to AppSec for review.
- Never block on findings classified as false positives.
Then roll out in phases:
- Comment only on all repositories. Let developers and AppSec see the findings and calibrate.
- Fail the check on confirmed critical findings in a few pilot repositories.
- Make it a required status check on your high-value repositories.
Blocking becomes a targeted policy for confirmed issues, which is why developers keep trusting it.
You also need an exception path. A developer who disagrees with a verdict should be able to dispute the finding from the PR, with a short reason, and AppSec should review disputes and unknowns on a set turnaround. The PR shouldn't stall while that happens. Merge on the unknown, track it, and fix it in a follow-up if AppSec confirms it.
If you want a one-line version to paste into your rollout doc: comment everywhere, fail on confirmed criticals in pilots, require the check on high-value repositories, and keep a dispute path open the whole time.
Keeping AI SAST scans fast in the pipeline
PR scans stay fast when you scope them to the change and keep them off the critical path. A few tactics do most of the work:
- Run the security job in parallel with tests and builds, not after them.
- Cancel superseded runs when a developer pushes a new commit. A concurrency group in GitHub Actions does this in two lines.
- Skip docs-only or config-only changes with path filters, so a README typo doesn't trigger a code scan.
- Post comments as soon as results arrive, and reserve the required check for confirmed findings.
Endor Labs AI SAST is built on the Endor Labs Code API, a semantic model of your code with callgraphs and dataflow. The agents query that model instead of dumping entire codebases into an LLM. That keeps costs contained at enterprise scale and keeps scan time predictable. Languages with Code API support (C, C#, Go, Java, JavaScript, and Kotlin) get faster, cheaper scans.
Combined with scoping the PR scan to changed code, this is how results arrive in a few minutes, often before a human reviewer opens the PR.
Secrets and permissions for AI review steps in CI
An AI review step posts comments and calls an external service, so it changes your pipeline's attack surface. Wire it with the same care you'd give a deploy job. The OWASP Top 10 CI/CD Security Risks names the two risks to design against: CICD-SEC-4 Poisoned Pipeline Execution and CICD-SEC-6 Insufficient Credential Hygiene.
Start with pull requests from forks. Fork PRs contain code you don't control, and that code runs in your pipeline. They shouldn't receive scanner tokens by default. GitHub's pull_request trigger withholds repository secrets from fork PRs and limits the workflow token, which is the behavior you want. Resist switching to pull_request_target to get secrets back. That trigger runs with the base repository's privileges, and if the job checks out and executes the fork's code, you've built a poisoned pipeline. Require maintainer approval before workflows run for outside contributors.
Next, scope job permissions to the minimum:
- contents: read to check out code.
- pull-requests: write to post review comments.
- id-token: write for keyless authentication.
- Nothing else.
For GitHub Actions, Endor Labs recommends keyless authentication through id-token: write, so there's no long-lived scanner token to leak. Prefer short-lived or OIDC-based credentials wherever your CI platform supports them. Where you do need a stored token, keep it in the CI system's secret store as a masked, protected variable, limit it to protected branches, and rotate it on a schedule.
Endor Labs also recommends pinning GitHub Actions to a full commit SHA rather than a tag. A tag can move. A SHA can't.
Finally, know what code leaves the runner during an AI step. Confirm which files the step sends for analysis and where they're processed, and record that in your threat model so the answer is ready when security reviewers ask for it.
Running AI SAST in GitHub Actions, GitLab CI, Jenkins, Azure Pipelines, and Bitbucket
The same pattern works across CI systems: trigger on PR events, grant minimal permissions, cancel stale runs, and run the PR scan against the target branch baseline. Only the trigger and permission syntax change.
Endor Labs gives you two ways to run it.
The first needs no pipeline changes. The Endor Labs GitHub, GitLab, Bitbucket Cloud, and Bitbucket Data Center apps can run AI SAST PR scans automatically on every pull request. Enable PR scans and PR comments, then add ENDOR_SCAN_AI_SAST=true to a scan profile.
The second runs inside your pipeline. endorctl runs AI SAST PR scans for GitHub and GitLab repositories from any pipeline job triggered by pull request or merge request events. It integrates with GitHub Actions, GitLab, Jenkins, CircleCI, Azure DevOps, Bitbucket, Google Cloud Build, and Buildkite.
Here's a GitHub Actions example. Before it runs, endorctl must be installed and authenticated in the job, as described in the AI SAST PR scans guide. Store your namespace as a repository variable, and pin actions/checkout to a full commit SHA in your own copy.
name: AI SAST PR scan
on:
pull_request:
branches: [main]
permissions:
contents: read
pull-requests: write
id-token: write
concurrency:
group: ai-sast-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
ai-sast:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run AI SAST PR scan
run: endorctl scan --ai-sast --pr --pr-baseline=main --path=. -n ${{ vars.ENDOR_NAMESPACE }}The equivalent trigger on other platforms:
- GitLab CI: a job with rules matching $CI_PIPELINE_SOURCE == "merge_request_event", with the merge request's target branch as the baseline.
- Jenkins: a multibranch pipeline or PR-triggered job that builds GitHub or GitLab pull requests and runs the same endorctl command.
- Azure Pipelines: the pr trigger on your default branch for GitHub or GitLab repositories, with a branch policy if you want the check required.
- Bitbucket: the Endor Labs Bitbucket Cloud or Data Center app, which scans every PR without pipeline configuration.
Platform-specific setup lives in the AI SAST scan documentation.
Metrics that show it's working
Five metrics show whether PR scanning catches real issues without slowing delivery:
- Blocked PR rate: PRs with a failing security check divided by PRs scanned. This tells you how much friction the check adds. A high rate with a high dismissal rate means your policy is blocking on noise.
- Time to fix in PR: time from the first finding comment to the commit that fixes it. This measures whether comments carry enough context to act on. Hours are good. Days mean developers are struggling to act on the comment.
- Fix rate before merge: findings resolved in the PR divided by findings raised. This is the core outcome. Every fix here is one that never reaches main or a backlog.
- Dismissal rate: findings marked not applicable divided by findings raised. This is your trust gauge. If developers dismiss a large share of findings, they'll soon stop reading them.
- Findings reaching main from scheduled scans: new issues that scheduled full scans find in code that already passed a PR scan. This checks coverage. A steady trickle shows where PR scans have blind spots.
Read the trends together. A falling dismissal rate alongside a stable or falling blocked PR rate means developers trust the check and it isn't getting in their way. Rising fix rate before merge with shorter time to fix means the comments are doing their job.
Verdict-backed findings move these numbers. Teams running Endor Labs see 83% fewer blocked PRs and 6x faster remediation. On the noise side, Endor Labs AI SAST delivers up to 95% false positive reduction by combining agents, program analysis, and rules, which is what keeps dismissal rates low enough for a required check to hold up.
Running AI SAST on every PR with Endor Labs
AI Security Review runs the Endor Labs AI SAST engine on every pull request, confirms which vulnerabilities are exploitable, and ships a context-aware fix with each one. Developers close real issues before merge instead of triaging noise after it. AI Security Review is available for GitHub.
For the engine behind it, see Endor Labs AI SAST. If you want the detection depth, read the whitepaper on our multi-agent approach to AI security code review, or start with the launch post introducing AI Security Code Review.
FAQs
Does AI SAST replace human code review on pull requests?
AI SAST is a dedicated security reviewer that works alongside your human reviewers on every PR. It traces data flows across files and checks every change at a consistent depth, which human reviewers can't sustain at the pull request volume AI-assisted teams now produce. Human reviewers still own design intent, readability, and whether the change solves the right problem. The two together cover more than either one alone.
Should AI SAST run on pull requests from forks?
Fork PRs should get AI SAST coverage through a setup that never exposes scanner credentials to the fork's code. Use the pull_request trigger so secrets stay withheld, require maintainer approval before workflows run for outside contributors, and avoid running fork code under pull_request_target. Once a maintainer has reviewed the change, scan it with full credentials as part of your normal flow.
How can AI be used in a CI/CD pipeline beyond security scanning?
AI can summarize pull requests for reviewers, draft test cases for new code paths, explain why a build failed, and generate release notes from merged changes. Each of these steps calls a model from your pipeline, so the same rules from this guide apply: least-privilege tokens, careful handling of fork PRs, and a clear record of what code leaves the runner.
What's next?
When you're ready to take the next step in securing your software supply chain, here are 3 ways Endor Labs can help:







