Skip to main content
AI SAST PR scans run incremental security analysis on pull requests against an established baseline scan of the target branch. They analyze only the code changed by the pull request, deduplicate findings against the baseline, and show only the net new findings that the pull request introduces. When the pull request is merged, the new findings are added to the baseline so that future PR scans compare against the latest mainline state. An average AI SAST PR scan completes within about five minutes. AI SAST PR scans run the detection agent on the pull request. They run only on pull requests that target the repository’s default branch. AI SAST PR scans help you to:
  • Scan only the code changed by the pull request, with results in a few minutes.
  • Show only net new, auto-triaged findings, and filter out false positives.
  • Review findings inline on the pull request through PR comments and in PR Runs.
  • Block risky merges or fail CI through action policies on the resulting findings.
You can run AI SAST PR scans in the following ways:

How AI SAST PR scans work

An AI SAST PR scan runs in three stages.
1

Build the baseline

AI SAST processes the full repository on the target branch and stores all detection-agent findings as the baseline. See Establish a baseline scan.
2

Scan the PR diff

A pull request triggers a PR scan that analyzes only the code changed by the pull request, using the full-repository context that the baseline established. The scan selects context files by code topology, following the changed files to the code they depend on. It does not expand the analysis to files that import the changed files.
3

Show net new findings

Findings are fingerprinted and matched against the baseline. Issues that already exist in the baseline are filtered out, and only net new findings appear in the PR result, so reviewers see exactly what the pull request introduces.

Establish a baseline scan

The baseline is the reference point every AI SAST PR scan compares against. It defines the known security state of the target branch. Therefore, the PR scan can isolate net new findings from issues that already exist. The baseline gives the AI SAST agents the full-repository context they need to reason about the changed code. Without a baseline, every AI SAST finding on the pull request would appear as new, including pre-existing issues, and the PR result would not be reviewable. We recommend that you run the first baseline scan from the command line so the baseline is in place before the first PR scan is requested. Replace /path/to/code with the path to your repository and <namespace> with your Endor Labs namespace.
When a pull request is merged, the net new findings from the PR scan are automatically added to the baseline. This keeps PR scans and baseline scans consistent for the next round of pull requests. A PR scan reuses the findings from an earlier scan of the same pull request in the last seven days, instead of running detection again, in the following cases:
  • The commit was already scanned.
  • The new commit changes only comments or documentation.
  • The diff is empty or only deletes code.
  • A file was renamed without edits. Its findings move to the new path.
To run detection again on a commit that was already scanned, add --ai-sast-rescan. Findings keep the same identity when a pull request is rebuilt. Suppressions on those findings keep applying.

Run AI SAST PR scans from the CLI

You can run AI SAST PR scans using endorctl for GitHub and GitLab. The --ai-sast --pr --pr-incremental --pr-baseline=<target-branch> --scm-pr-id=<pr-or-mr-id> combination runs the AI SAST detection agent on the changed code, deduplicates findings against the baseline, and records the results as a PR Run that does not affect main-branch monitoring scans and reports. The --pr-incremental flag makes the scan incremental, --pr-baseline tells the scan which branch to compare against, and --scm-pr-id identifies the pull request. Endor Labs stores PR and MR scan findings in PR Runs for three weeks, after which they are removed to accommodate new PR scans. Run the following command after you commit to a pull request or merge request. Ensure that you install and configure endorctl before running scans from the command line.
Replace <target-branch> with the pull request’s target branch, such as main, and <pr-or-mr-id> with the pull request or merge request ID. AI SAST PR scans require both --pr-incremental and --scm-pr-id. To post findings as PR comments, add --enable-pr-comments and an SCM token, and keep --pr-baseline. For the full list of pull request flags, see Pull request (CI) flags to learn more. AI SAST PR scans analyze only the code changed by the pull request. Do not set --diff-scope in PR scan commands. That flag is for local diff scans.

Set up AI SAST PR scans step by step

The steps below build the full command up from a baseline scan to posting comments and blocking merges. Verify each scan in your pipeline before adding the next flag.
1

Run a baseline scan

Scan the default branch so later PR scans have a baseline to compare against. In a large repository, the baseline can take more than one scan to complete. See Establish a baseline scan to learn what the baseline is and why PR scans need it.
2

Run a PR scan against the baseline

Run an AI SAST scan on the pull request. Point --pr-baseline at the branch the pull request merges into, and set --scm-pr-id to the pull request or merge request ID. The scan shows only the net new findings introduced by the pull request, and Endor Labs stores the results as a PR Run.
3

Post findings as PR comments

Provide an SCM token and enable PR comments with --enable-pr-comments. Retain --pr-baseline to identify the target branch for AI SAST. For GitHub Enterprise Server, also specify --github-api-url with your server’s API URL.
4

Block merges on findings

The scan reports findings and posts comments, but it does not block merges on its own. Pair the command with an action policy that breaks the build and a required status check on your target branch. See Block pull requests on findings.
To run AI SAST PR scans against a baseline without posting comments, stop after the second step. Keep --pr-baseline and do not set --enable-pr-comments.

Run AI SAST PR scans from CI

You can run AI SAST PR scans from a CI pipeline by invoking endorctl scan with the --ai-sast, --pr, --pr-incremental, --pr-baseline, and --scm-pr-id flags in jobs triggered by pull request or merge request events. This approach provides control over when scans run, supports posting findings as PR or MR comments, and allows policies to be enforced, such as failing builds or blocking merges. The scan profile assigned to the project determines the toolchains and environment used for the scan. For platform-specific YAML and command syntax, see: A baseline AI SAST scan must exist on the target branch before any PR scan can produce findings. See Establish a baseline scan.

Run AI SAST PR scans through SCM apps

The Endor Labs GitHub and GitLab apps can run AI SAST PR scans automatically on every pull request, without CI pipeline configuration. PR comments post the net new findings introduced by a pull request as a PR comment in GitHub and as an MR comment in GitLab, so developers see results in the SCM UI without leaving their review flow. Configure Action policies to post PR comments. See Pull request comments to learn more. To configure AI SAST PR scans:
  1. Install the Endor Labs GitHub app, Endor Labs GitLab app, Bitbucket Cloud app, or Bitbucket Data Center app.
  2. Enable PR scans and PR comments during installation: GitHub App Pro, GitLab App, Bitbucket Cloud app, or Bitbucket Data Center app.
  3. Create a scan profile and add ENDOR_SCAN_AI_SAST=true to the Environment Variables.
  4. Associate the scan profile with the project.
  5. Open or update a pull request on the configured repository to trigger an AI SAST PR scan.
If the project does not yet have a baseline AI SAST scan, the platform automatically triggers one when the first PR scan is requested. The PR scan does not produce results or post PR comments until the baseline completes. The first baseline scan takes longer than subsequent scans because it must process the full repository. In a large repository, the baseline can take more than one scan to complete. Each later scan indexes only the files changed since the previous scan instead of the whole repository.