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

Applications

API specs

NightVision tests an API from a description of it: an OpenAPI (Swagger) specification or a Postman collection. The spec tells the scanner which endpoints exist, which methods they take and what their parameters look like, so every endpoint is tested, not only the ones a crawl happens to reach.

In the dashboard: Applications

Open Applications (opens in a new tab)

There are two places a spec can live:

  • The application’s own spec. Every API application has one. It defines the endpoints its scans test.
  • API schemas. Extra specs you attach to any web or API application, each with its own base URL. Use them for a web application that calls an API, or for an API split across several services.
Format File types Notes
OpenAPI or Swagger specification .yml, .yaml, .json By file or by URL
Postman collection .json Collection format v2.0 or v2.1. Upload it as it is. There is nothing to convert

A file’s extension has to match its contents: JSON in a .json file, YAML in a .yml or .yaml file.

If you have neither, generate a spec from your source code.

Add a spec when you create an API application

Section titled “Add a spec when you create an API application”
  1. On Applications, select New application, then API application.
  2. Enter the Application name and the Base URL.
  3. Under API spec or Postman collection, choose a source:
    • URL: enter the address of the spec. NightVision fetches it and tells you at once if it cannot be read as a spec.
    • File: select Choose a file and pick the spec or collection.
  4. Select Create application.

The base URL has to match the spec. The base URL plus each path in the spec must reach a real endpoint. For example, with paths such as /charges in the spec, a base URL of https://api.example.com/v1 sends requests to https://api.example.com/v1/charges. Do not end the base URL with a slash.

Applications covers the rest of the form.

When your API changes, give the application the new spec.

  1. Open the API application.
  2. On the Application card, select Edit.
  3. Under API spec or Postman collection, enter a new URL or choose a new File. Leave both alone to keep the stored spec.
  4. Select Update.

Changing the URL fetches the spec again. The next scan uses the new spec.

Open the API application, then More settings and General.

The General panel for payments-api. It lists the project, application type, accessibility, application ID, dates, base URL and the spec file with a Download link. API spec status reads Spec/collection has validation warnings, Application is ready to scan reads No, and two warnings are listed underneath.
The General panel shows the spec, its status and any warnings.

The panel shows the spec file, when it was last updated, and two answers:

  • API spec status says where the spec is in its checks.
  • Application is ready to scan is Yes once the spec can be used.
Status Meaning What to do
Spec/collection is valid The spec passed every check Scan
Spec/collection has validation warnings The spec was read and its endpoints are listed, but it has validation errors, shown under Warnings. Application is ready to scan reads No Fix the errors in the file and replace the spec. New scans cannot start until the status is valid. A rescan or scheduled run of an earlier scan still runs
Spec/collection is not valid The file could not be read as a spec or a collection Fix the file and replace the spec
Spec/collection download failed NightVision could not fetch the URL Check that the URL is reachable from the internet, or upload a file instead
Spec/collection is not specified The application has no spec yet Add one
Downloading, Validating, Waiting for upload The spec is still being processed Wait. The panel updates by itself

To get the stored spec back, select Download for an uploaded file or Open for a spec fetched from a URL.

Open More settings and Endpoints to see every endpoint the spec declares, with its method and path.

The Endpoints panel for payments-api: a search box, an Export as CSV button, and a table of methods and paths such as GET /payments/v2/charges and POST /payments/v2/charges/{id}/refund.
The endpoints scans of this application test.
  • Search matches the method or the path.
  • Export as CSV saves the endpoints you are looking at.
  • Open in API inventory opens the same API in API inventory.

After a scan, Coverage shows which of these endpoints the scan requested.

An API schema is an extra spec attached to an application. Each one has a base URL that its endpoints are served under.

Schemas do two things. They tell the scanner about endpoints it might not find by itself, and they let it attack the endpoints most likely to be vulnerable first. A spec that Source intelligence generated from your code marks where each endpoint’s input ends up, such as a database query or a shell command, and the scanner uses those marks to order its work.

To add one:

  1. Open the application, then More settings and API schemas.
  2. Select Add schemas.
  3. Choose a File, or enter an address under Add schema by URL.
  4. Give it a Name and check the Base URL. It starts as the application’s own URL.
  5. On a web application with network analysis turned off, leave Turn on network analysis ticked. Scans of a web application use its schemas only while network analysis is on, and network analysis applies to scans with a max scan duration of 2 hours or more. See Crawler settings.
  6. Select Add.

A web application with no schema also shows an Add an API schema button on its Setup tab, and a scan’s Coverage tab offers the same.

The API schemas panel for customer-portal with an Add schemas button and three schemas. Each row shows a name, where it came from, its base URL and a status: Valid, Valid with warnings, and Download failed.
Three schemas attached to a web application.

Each schema is checked before scans use it:

Status Meaning
Valid Ready. Scans use it
Valid, with warnings Ready, with issues in the file
Invalid The file is not a spec or a collection
Download failed The URL could not be fetched
Downloading, Checking, Waiting for upload Still being processed

The row menu has Download, Edit and Delete. Edit changes the name, base URL and description, and for a schema fetched from a URL, the URL. Changing the URL fetches it again.

On an API application, these schemas are in addition to the application’s own spec.

Source intelligence reads your code and writes the OpenAPI spec for you. Run it in the repository:

Terminal window
nightvision openapi extract . --target payments-api -p "Payments"

--target attaches the spec to the application, replacing the one it had. The CLI detects the languages in the repository; add --lang to restrict a run to one.

To look at the result before you attach it to anything:

Terminal window
nightvision openapi extract . --no-target

See openapi extract for every option and Supported frameworks for what it reads.

The CLI calls an application a target.

Terminal window
# From a local file (OpenAPI or a Postman collection)
nightvision target create payments-api https://api.example.com/v1 \
--type API -p "Payments" --spec-file openapi-spec.yml
# From a URL
nightvision target create payments-api https://api.example.com/v1 \
--type API -p "Payments" --spec-url https://api.example.com/v1/openapi.json

Give --spec-file or --spec-url, not both. You can also create the application with --type API and no spec, then attach one later.

Terminal window
nightvision target update payments-api --spec-file openapi-spec.yml
nightvision target update payments-api --spec-url https://api.example.com/v1/openapi.json

--openapi-file and --openapi-url do the same as --spec-file and --spec-url. The older --swagger-file and --swagger-url spellings still work and are deprecated.

Terminal window
# Attach a schema from a file. The base URL is required.
nightvision api-schema upload orders-v2 orders-v2.yaml \
--target customer-portal --base-url https://orders.example.com
# Have NightVision fetch it from a URL instead
nightvision api-schema upload portal-api \
--target customer-portal --base-url https://portal.example.com/api \
--url https://portal.example.com/api/openapi.json
nightvision api-schema list customer-portal
nightvision api-schema download orders-v2 --target customer-portal
nightvision api-schema delete orders-v2 --target customer-portal

On upload, --overwrite replaces the file of a schema that already has that name, and --wait holds the command until NightVision has finished checking the schema. Every command takes -p to name the project.

Base URL: https://api.nightviz.ai/api/v1/. See the API overview for authentication.

Method and path What it does
POST /targets/openapi/ Create an API application. Send swaggerfile_url to have the spec fetched from a URL
PUT /targets/openapi/{id}/ Update it, including a new swaggerfile_url
POST /targets/openapi/{id}/upload-spec/ Upload a spec file and attach it
GET /targets/openapi/{id}/spec-status/ Read the spec’s status. Poll this after an upload until the spec is ready
GET /targets/openapi/{id}/get-spec-url/ Get a link to download the stored spec
GET, POST /targets/{id}/api-schemas/ List and add API schemas
GET, PUT, DELETE /targets/{id}/api-schemas/{api_schema_id}/ Read, change or remove one schema
GET /targets/{id}/api-schemas/{api_schema_id}/download-url/ Get a link to download a schema

The API reference lists every field.