---
title: "Scan an API with an OpenAPI document"
description: "Give a verified target its OpenAPI description so an active scan tests the operations it lists, including ones no page links to."
---

A crawl finds what pages link to. An API usually has no pages: its endpoints
are known to its clients, not discoverable by following links. Give the target
its OpenAPI description and an active scan tests the operations the document
lists, as well as whatever the crawl finds.

## Requirements

- The target is **verified**. An API description is a list of things to
  attack, so it is accepted only for an application you have proven is yours;
  on an unverified target the request is refused with
  `dast_target_not_verified`.
- The document is **OpenAPI 3** or **Swagger 2**, as JSON or YAML, at most
  **1 MB**, with at least one path.

## Store the document

On the target, choose **Settings** and, under **API description**, choose the document file, and
save. With the API (the document travels as a string):

```bash
jq -Rs '{openapi_document: .}' openapi.yaml | \
curl -sS -X PATCH https://app.trustivan.com/api/v1/dast/targets/$TARGET_ID \
  -H "Authorization: Bearer $TRUSTIVAN_KEY" -H "Content-Type: application/json" \
  --data-binary @-
```

The target then reports `has_openapi: true` and the document's size. The
document itself is not returned. Send an empty string to remove it.

Store it again whenever the API changes. TRUSTIVAN does not fetch the document
from a URL, so it does not follow your API as it evolves.

## What the scan does with it

During an active scan, after the crawl, the engine reads the document and
builds one request for each operation, filling parameters and request bodies
from the document's `example` and `default` values and, where there are none,
from values generated to fit the schema. Those requests are then tested like
any other: every parameter is attacked.

- **The server is your target.** Whatever `servers` the document names, every
  request goes to the target's origin. A document cannot send the scan
  anywhere else.
- **Authentication** is the target's
  [authentication header](/how-to/run-authenticated-dynamic-scans). Security
  schemes declared in the document are not acted on.
- **Every operation is called**, including `DELETE` and other operations that
  change or remove data. Use a staging environment.
- If the document cannot be read, the scan still runs on what the crawl found
  and carries a warning saying so.

## Getting useful coverage

The engine can only send what the document lets it build. Coverage is better
when:

- parameters and bodies have realistic `example` values (an identifier that
  exists, a date in the right format), because a request your API rejects as
  malformed never reaches the code you want tested;
- path parameters have examples that point at real records;
- the document describes the API that is actually deployed at the target.

## Read the result

Findings on API operations are ordinary dynamic findings. Their endpoint is
the operation's path with identifiers replaced by a placeholder
(`/orders/{id}`), and their parameter is the one the attack was in.

## Not supported

Postman collections and HAR files are not accepted. A GraphQL endpoint and
schema, a SOAP WSDL and a gRPC address are set separately, in the same
**Settings** dialog (see [API targets](/concepts/dynamic-scanning#api-targets)).
See [Limits](/concepts/dynamic-scanning-limits).
