Safeguard
Developer Tools•

What is OpenAPI spec drift and how do you detect it?

Spec drift is when your OpenAPI file no longer matches the running API. Learn why it weakens security testing and how to catch it in CI before release.

Safeguard Security Team
3 min read

Spec drift is the gap between your OpenAPI description and the API that actually runs. Routes get added, parameters change and old versions linger while the file stays the same. Detect it by diffing the spec against code routes and observed traffic in CI, then fail the build when they disagree.

Why drift matters for security

Spec driven testing only tests what the spec lists. The OpenAPI Specification is described as a language agnostic interface description that lets people and computers discover a service's capabilities without source code or extra documentation. If the description is wrong, the tooling that reads it is wrong too: scanners skip routes that are missing and test parameters that no longer exist.

OWASP API9 names the result a documentation blindspot and recommends generating documentation automatically from open standards as part of CI/CD.

Three kinds of drift

KindExampleSecurity effect
Missing in specNew admin route never describedNever tested by spec driven tools
Missing in codeSpec lists removed endpointWasted test time, confusing docs
MismatchField type, auth rule or status code differsTests assert the wrong behaviour

The authentication row deserves attention. In OpenAPI, security can be declared at the top level and overridden per operation, and per the spec an empty security requirement object makes security optional for that operation. A copy and paste slip there silently documents an open endpoint, or hides a protected one.

How to detect it

  1. Route diff. Have the framework print its registered routes in CI and compare method and path pairs with the spec.
  2. Contract tests. Send example requests from the spec to a test deployment and check status codes and response shapes.
  3. Traffic comparison. Compare normalised paths in staging or production logs with the spec, as described in finding undocumented API endpoints.
  4. Review security blocks. List every operation whose security setting differs from the default and read each one.

How to fix it

  • Pick a source of truth. Either generate the spec from code on every build, or generate server stubs and validation from the spec. Mixing the two invites drift.
  • Fail the pull request on any diff, with a message naming the route.
  • Version the spec file in the same repository as the code.
  • Review spec changes like code changes, because they carry security meaning.

Try it yourself

Click through it at your own pace, or open it full screen. Think about what a scan would miss if the endpoint list it starts from were incomplete.

Quick check

Should the spec be generated from code or written first?

Either works if one side is authoritative and CI enforces it. Spec first suits new APIs with several consumers. Code first suits fast moving internal services.

Does fixing drift remove the need for a scanner?

No. A correct spec helps the scanner cover more, but the scanner still has to find the flaws.

Safeguard policies and gates can enforce checks in the pull request, and the free scan at gold.safeguard.sh/scan is a quick start for dependency risk.

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.