---
title: "Findings on pull requests with SARIF"
description: "Export a scan's findings as SARIF 2.1.0 and upload them to GitHub code scanning, so they annotate the changed lines of a pull request."
---

TRUSTIVAN exports the findings of a scan as a
[SARIF 2.1.0](https://docs.oasis-open.org/sarif/sarif/v2.1.0/sarif-v2.1.0.html)
log. A code host that ingests SARIF then shows them where a reviewer already
is: GitHub annotates the changed lines of the pull request and lists them
under **Security → Code scanning**. No TRUSTIVAN integration is installed on
the code host for this; the upload step is the code host's own.

## GitHub Actions

```yaml
name: security
on:
  pull_request:
  push:
    branches: [main]

permissions:
  contents: read
  security-events: write   # required by upload-sarif

jobs:
  scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: trustivan/trustivan@v1
        id: trustivan
        with:
          repo: ${{ github.server_url }}/${{ github.repository }}
          ref: ${{ github.sha }}
          sarif-file: trustivan.sarif
        env:
          TRUSTIVAN_API_KEY: ${{ secrets.TRUSTIVAN_API_KEY }}

      - uses: github/codeql-action/upload-sarif@v3
        # always(): a build the policy blocked is the one whose findings a
        # reviewer most needs to see. The output is empty when the scan
        # itself failed and no log was written.
        if: always() && steps.trustivan.outputs.sarif-file != ''
        with:
          sarif_file: ${{ steps.trustivan.outputs.sarif-file }}
          category: trustivan
```

The API key needs `findings:read` in addition to the three scopes the
[policy gate](/integrations/github-actions) uses.

GitHub code scanning is included for public repositories and needs GitHub
Code Security (formerly Advanced Security) for private ones. That is GitHub's
requirement, not TRUSTIVAN's.

<Note>
The scan runs on the TRUSTIVAN deployment, which clones the repository
itself. For a private repository, store a git credential first:
[Scan a private repository](/how-to/scan-a-private-repository).
</Note>

## From the command line

`--sarif` is accepted by both `scan` and `gate`, and implies waiting for the
scan to finish:

```bash
trustivan scan --repo https://github.com/acme/api --ref "$GIT_COMMIT" --sarif trustivan.sarif
trustivan gate --image ghcr.io/acme/api:1.4.2 --policy "$POLICY_ID" --sarif trustivan.sarif
```

`--sarif -` writes the log to standard output. `gate` writes the log before it
acts on the verdict, so a blocked build still produces one. Neither command
writes a log for a scan that failed: an empty log would tell the code host the
commit is clean.

Other code hosts take the same file. GitLab reads SARIF through its own
converters, and Azure DevOps through the SARIF SAST Scans Tab extension; those
two paths have not been exercised by TRUSTIVAN's tests.

## From the API

```bash
curl -fsS -H "Authorization: Bearer $TRUSTIVAN_API_KEY" \
  "https://app.trustivan.com/api/v1/scans/$SCAN_ID/sarif" -o trustivan.sarif
```

`GET /api/v1/scans/{id}/sarif` needs `findings:read` and answers
`application/sarif+json`. A scan that is still queued or running answers `409`.

## What is in the log

| SARIF property | Value |
|---|---|
| `runs[0].tool.driver` | `TRUSTIVAN`, with the deployment's version |
| `results[]` | The findings **this scan** observed that are not suppressed or resolved, worst first |
| `results[].ruleId` | The rule or advisory identifier: a SAST rule ID, a CVE, a secret detector ID, a misconfiguration check ID |
| `results[].level` | `error` for critical and high, `warning` for medium, `note` otherwise |
| `results[].locations` | The file and lines. A finding with no file, such as a package in an image, is placed on the scan target at line 1, because a code host displays nothing for a result without a location |
| `results[].partialFingerprints` | TRUSTIVAN's finding fingerprint, so the same finding stays one alert across uploads |
| `rules[].properties.security-severity` | The CVSS score when the finding has one, otherwise the middle of its severity band. GitHub turns this into critical, high, medium or low |
| `rules[].properties.tags` | `security`, the finding kind, and `external/cwe/cwe-<n>` for a SAST rule's CWEs |
| `rules[].help` | The rule's fix guidance |
| `runs[0].properties` | `scanId`, `target`, `truncated`, `omittedSuppressedOrResolved` |

A secret finding's result carries the detector and the location, never the
secret: TRUSTIVAN does not store the value.

## Limits

- **5,000 results per log.** Past that the least severe are dropped and
  `runs[0].properties.truncated` is `true`. GitHub's own limit is 25,000
  results per run.
- **Suppressed findings are left out**, and counted in
  `omittedSuppressedOrResolved`. Suppress a finding in TRUSTIVAN and the next
  upload closes its alert on GitHub.
- **Export only.** TRUSTIVAN does not import SARIF from another tool.
- **Paths are what the scanner recorded.** For a repository scan they are
  relative to the repository root, which is what GitHub needs to place an
  annotation. For an image scan they are paths inside the image and annotate
  nothing in a pull request; those results appear in the code scanning list
  only.
- The log's structure is validated against the OASIS SARIF 2.1.0 schema in
  TRUSTIVAN's test suite. An upload to GitHub is not part of that suite.
