Skip to content
Open dashboard (opens in a new tab)

Integrations

Scan from a pipeline

A pipeline scans with the NightVision CLI. The CLI signs in with an API token, starts a scan of an application you have already set up, waits for it to finish, and exports the results in the format your tools read.

In the dashboard: SettingsIntegrationsPipelines

Open Pipelines (opens in a new tab)

In the dashboard, the same summary is under Settings, Integrations, Pipelines.

The Pipelines tab under Settings, Integrations, with three setup steps and a button that opens pipeline and CLI runs on Scans.
Settings, Integrations, Pipelines lists the three steps and links to your pipeline runs.

Every pipeline integration is the same three steps.

  1. Install the CLI on the runner. One download command for Linux runners. See Install the CLI.
  2. Give the pipeline an API token. Store it as a secret named NIGHTVISION_TOKEN. The CLI reads that environment variable, so no login step is needed.
  3. Run nightvision scan with the name of the application.
Terminal window
nightvision scan my-app --project my-project --auth my-app-login

The CLI scans without signing in unless you pass --auth (or set NIGHTVISION_CREDS_ID), so name the authentication in every pipeline scan that needs a login. If the API issues short-lived tokens, see Authenticate an API in a pipeline.

Set these up once, from the dashboard or from your own terminal. The pipeline reuses them on every run.

  • An application. Create it under Applications, or run nightvision target create my-app https://localhost:9000 --type API. Use --type WEB for a web application. See Applications.
  • An authentication, if the application has a login. Record it once and pass its name with --auth. See Recorded logins and Authentication.
  • An API token. In the dashboard, open Settings, Integrations, API tokens and select Generate API token. From a terminal, run nightvision token create --expiry-date YYYY-MM-DD with a date about 90 days out. A token acts as the account that made it, so create it from a dedicated CI account and always set an expiry date. A token without one never stops working. Give that account a role on the application’s project: Scan Operator works when the application was created from the same repository the pipeline checks out, and Project Manager is needed otherwise or if the job uploads a specification. See API tokens.
  • It looks for the application in the token account’s default project, which is often not the application’s project. Pass --project my-project with the project’s name (or set NIGHTVISION_PROJECT_ID to its ID), as the examples here do, or the scan stops with an error that the application is not in the current project.
  • It runs for up to 30 minutes by default. Raise the limit with --max-duration-minutes, from 30 up to 480.
  • If the application’s URL is not reachable from the internet (for example https://localhost:9000 on the runner), the CLI relays the scan traffic through the runner. You do not open any inbound ports. See Scan private networks.
  • When its output is redirected, the first line it prints is the scan ID. Progress and log lines go to standard error, so they still show in the job log.
Terminal window
nightvision scan my-app --project my-project --auth my-app-login > scan-results.txt
SCAN_ID=$(head -n 1 scan-results.txt)

For an API, generate the OpenAPI specification from the code in the same job, before the scan. The CLI uploads the specification to the application, and the scan tests every route it found.

Terminal window
nightvision openapi extract . --target my-app --project my-project --lang java

This step changes the application, because it uploads the specification, so the token needs the Project Manager role on the project. A Scan Operator token can start the scan and cannot run this step. See API tokens.

The specification is saved as openapi-spec.yml. Pass that file to an export command with --openapi-file and each finding carries the file and line that declares the vulnerable route. See Extract an OpenAPI specification and Code traceback.

CI system What you get Guide
GitHub Actions Findings as code scanning alerts on the Security tab GitHub Actions
GitLab CI/CD Findings in the GitLab vulnerability report GitLab
Azure DevOps Findings on the build’s Scans tab, and optional work items Azure DevOps
Bitbucket Pipelines A scan on every push, with the SARIF file as an artifact Bitbucket
Jenkins Findings beside the source line, through the Warnings plugin Jenkins
JFrog Scan results and the API specification attached to an image as signed evidence JFrog

Any other CI system works the same way: install the CLI, set NIGHTVISION_TOKEN, run nightvision scan.

nightvision scan exits 0 when the scan completes. It exits non-zero when the scan fails, times out or is stopped, so the job fails and nobody reads a green build as a clean result.

A completed scan exits 0 whether or not it found anything. To fail the build on findings, count them in the export, as shown below.

Export the scan to SARIF, leave out what should not block a build, and fail the job if anything is left.

Terminal window
nightvision export sarif -s "$SCAN_ID" \
--exclude-severity info,low \
--exclude-resolution false_positive,wont_fix
COUNT=$(jq '[.runs[].results[]] | length' results.sarif)
if [ "$COUNT" -gt 0 ]; then
echo "$COUNT findings at medium severity or higher"
exit 1
fi
  • --exclude-severity takes a comma-separated list of info, low, medium, high, critical, unknown and unspecified.
  • --exclude-resolution takes open, resolved, false_positive and wont_fix. Excluding false_positive and wont_fix means a finding your team has already triaged in the dashboard stops blocking builds.

Both flags work on every export command.

A scan whose login fails runs signed out and tests far less. Check the login first, in about two minutes, before you spend a full scan.

Terminal window
nightvision scan my-app --project my-project --auth my-app-login --login-check \
--validation-url https://localhost:9000/account

--login-check runs only the login. It does not crawl and it runs no checks.

Exit code Meaning
0 The login works. With --validation-url, the session reached that page signed in. Without it, a session was captured.
1 The check could not finish: an infrastructure problem or a timeout.
2 The login failed.
3 Inconclusive. The session could not be confirmed either way.

See Login check for the content and status-code options.

Each export command takes the scan ID with -s.

Command Output Use it for
nightvision export sarif results.sarif GitHub code scanning, Azure DevOps, Jenkins, any SARIF reader
nightvision export gitlab gl-dast-report.json The GitLab vulnerability report
nightvision export csv results.csv Spreadsheets and your own scripts
nightvision export jira Jira issues One Jira issue per finding. See Jira

Change the output path with -o. For PDF reports and exports from the dashboard, see Reports and exports.

To post a scan result to Slack or Microsoft Teams from the same job, see Notifications.

A pipeline run is an ordinary scan. Open Scans and set the Trigger filter to CLI and pipelines, or select See pipeline and CLI runs on Scans on the Pipelines tab.

The CLI also prints a link to the scan in the job log, on the Link: line.