Safeguard
Developer Tools•

Why does an API scanner hit the wrong host? The OpenAPI servers field

If servers is missing, OpenAPI defaults to a url of a slash. Generated files often list localhost or production. How to set it so scans hit the right host.

Safeguard Security Team
3 min read

The OpenAPI servers field lists the hosts a client should call. If it is missing or empty, the specification says the default is a single server with a url of a slash, meaning relative to wherever the file was loaded. Generated files often carry localhost or a production URL, so check it before every scan.

What the specification says

The OpenAPI Specification describes the servers field as the target hosts for the API, and states that when it is not provided, or is an empty array, the default is one server whose url is a slash. A tool that reads the file and has no other instruction may therefore send requests relative to the location of the file, or to the wrong place entirely.

How generated files get this wrong

Source of the fileTypical servers valueRisk
Generated on a developer machineA localhost addressScanner cannot reach it, or hits a local service
Generated from the running production appThe production URLA scan aimed at production by default
Hand written templatePlaceholder hostRequests go nowhere or to a stale host
Behind a proxy with a path prefixMissing prefixEvery route returns 404

The last row happens with frameworks behind a gateway. FastAPI's own documentation notes that tokenUrl is a relative URL so apps keep working behind a proxy, which is a hint that path prefixes matter when generating absolute URLs elsewhere.

Why this matters for safety

A scan with write requests pointed at production is the expensive mistake. Production data can change, accounts can lock and rate limits can trip. Scanning only the host you meant is a basic prerequisite, alongside permission, test accounts and a rate plan. See what an API scanner needs before its first run and scan a staging site safely.

Steps to set it right

  1. Open the exported description and read the servers entries.
  2. Replace them with the staging base URL for scanning, including any path prefix.
  3. Keep one entry per environment with a description, for example staging and production, so a person can tell them apart.
  4. Make your scanner configuration override the host explicitly, so the file cannot silently redirect it.
  5. Run a single harmless GET against each environment from the scanner to confirm the target.
  6. Record environment, audience and version for each host in your inventory, which is what OWASP recommends.

What to do when docs are disabled

If production docs are off, the export from CI is your input. Generate it with a staging base URL, or post process the file in the pipeline so servers matches the target. The spec-first or code-first comparison shows where that step fits.

Try it yourself

Click through it at your own pace, or open it full screen. Check where the target host is chosen before the scan starts.

Safeguard's SBOM and dependency scanning needs no live target, and a free scan is available.

Quick check

What happens if servers is empty?

The specification says the default is a single server with a url of a slash.

Should I scan whatever host is in the file?

No. Override the target in your scanner configuration so you control which environment is tested.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.