> ## Documentation Index
> Fetch the complete documentation index at: https://docs.semgrep.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Review pull requests with Preflight (private beta)

> Run Preflight on pull requests and merge requests to find security and correctness issues before they merge.

> [!NOTE]
>
> Preflight is in **private beta**, and its behavior may change. To join the beta, contact your Semgrep account team.

Preflight finds security vulnerabilities in pull requests (PRs) and merge requests (MRs) before they merge, and comments on the PR or MR with what it finds. It can also check for logic bugs and other correctness issues.

## Prerequisites

* Semgrep has enabled Preflight for your organization.
* You and your organization meet the [prerequisites for Semgrep Agentic Workflows](https://docs.semgrep.dev/workflows/get-started.md#prerequisites).
* Your organization uses [Unified Policies](https://docs.semgrep.dev/semgrep-appsec-platform/unified-policies/overview).
* Your repositories are on GitHub, GitHub Enterprise, GitLab, or GitLab Self-Managed. Preflight doesn't support other source code managers yet.

## Enable Preflight on pull requests

**1. Add Preflight**

Go to **Rules & Policies > Policies > Detection**, and on the **Scheduled workflows** card, click **Edit**. Then click **Add workflow**.

In the **Add workflow** dialog, under **Runs on**, click **PRs**, or search for `Preflight`. Then click the **Preflight** card.

**2. Choose a review scope**

Select a **Review scope** to set how deep or broad each review goes. The scope applies to every Preflight run in your organization, and you can change it later. Choose one of these options:

* **Focused security review** (default): Finds security issues only, with the deepest security analysis. It traces likely attack paths, such as injection and broken access control, through your codebase.
* **Full code review**: Finds security issues and correctness issues, such as logic bugs and performance problems, in one review. Its security analysis is lighter than a focused security review.

**3. Select projects and a trigger**

In **Projects**, select the projects for Preflight to review. In **When**, select what starts a review:

* **A PR/MR is opened or updated** (default): Preflight reviews the PR or MR when it's opened and again on every push.
* **A PR/MR is ready for review**: Preflight reviews the PR or MR when it's opened, reopened, or marked ready for review, but not on later pushes.

With either trigger, Preflight skips draft PRs and MRs, and PRs and MRs that change only documentation.

**4. Turn on comments and save**

Select **Also comment on PR/MR** so that Preflight comments on your PRs and MRs. To see an example comment first, click **Preview comment**. Then click **Save changes**.

Semgrep creates a remediation policy named **Preflight PR/MR comments**. It comments on every Preflight issue in every project, and it doesn't block merges. If you don't select **Also comment on PR/MR**, Preflight issues appear only in Semgrep AppSec Platform. To change which issues get comments or to block merges, see [Configure comments and merge blocking](#configure-comments-and-merge-blocking).

Preflight now reviews PRs and MRs in the projects you selected. To confirm it's running, open a PR or MR in one of those projects and look for the `Semgrep Workflow: preflight` status check.

## Configure comments and merge blocking

Preflight comments on PRs and MRs through remediation policies. The default **Preflight PR/MR comments** policy comments on every issue in every project. To change which issues get comments or to block merges, replace the default policy with your own:

1. Go to **Rules & Policies > Policies > Remediation** and click **Create policy**. Enter a **Policy name**.
2. Under **Event**, select **A workflow job finishes**.
3. Under **Scope**, select the projects the policy applies to. The default is **All projects**.
4. Under **Conditions**, set **When** to **Workflow name** **is any of** **Preflight**. Optional: To narrow the policy, click **Add condition** and add a **Severity** or **Domain** condition.
5. Under **Actions**, click **Add action**. Under **PR/MR**, select one of these actions:
   * **Comment on PR/MR**: Preflight comments on matching issues and doesn't block the merge.
   * **Block merge and comment on PR/MR**: Preflight comments on matching issues and fails the status check.
6. Click **Create & Enable**.
7. Turn off the default policy so that it doesn't keep commenting on every issue. In **Rules & Policies > Policies > Remediation**, find the **Preflight PR/MR comments** policy. Click the three-dot menu button on the policy, and select **Disable policy**. The policy shows a **Disabled** badge.

When a PR or MR has issues that match a blocking policy, the `Semgrep Workflow: preflight` status check fails. The PR or MR shows the check as failed in its list of checks.

To prevent developers from merging until they fix or ignore those issues, make the status check required in your source code manager's branch protection settings. The check fails open: if a Preflight run fails, the check passes, so a failed run doesn't block your developers.

## Review Preflight issues

When comments are on, Preflight comments on the changed lines for each issue it finds. Each comment includes the issue's title, severity, a description of what's wrong and how to fix it, the evidence in your code, and a full analysis. It also links to the issue in Semgrep AppSec Platform.

Preflight puts issues on lines outside the change into one **Findings outside the diff** comment. It updates that comment on every run and strikes through issues it no longer detects.

Every issue also appears on the **Workflows** page in Semgrep AppSec Platform, even when Preflight doesn't comment on it.

Developers can triage an issue by replying to its comment with a command, such as `/ar` and a reason to ignore it as an acceptable risk. For the full list of commands, see [Ignore findings](https://docs.semgrep.dev/for-developers/resolve-findings-through-comments.md#ignore-findings).

## Manage credit usage

Each Preflight run uses [AI credits](https://docs.semgrep.dev/workflows/overview.md#credit-usage-and-billing). With the default trigger, Preflight runs on every push, so credit usage grows with how often your team opens and updates PRs and MRs. Both review scopes use about the same number of credits per run.

To use fewer credits, change either of these settings:

* Run Preflight on fewer projects. Start with the repositories where teams want security feedback on every PR, and add more projects after you see how many credits Preflight uses.
* Run Preflight only when a PR or MR is ready for review, so that later pushes don't start a review.

To change these settings, go to **Rules & Policies > Policies > Detection**, and on the **Scheduled workflows** card, click **Edit**. To see how many credits Preflight has used, check the **Total credits used** column on the **Scheduled workflows** page.
