Cluster 9 · OWASP API2:2023 · securitySchemes · OAuth2

Fixing Missing OpenAPI securitySchemes, Bearer JWT & OAuth2 Scopes

Eliminate unauthenticated endpoints and ambiguous API key headers (OWASP API2:2023) with properly typed HTTP Bearer JWT, OAuth2 PKCE scopes, and RFC 9728 protected-resource metadata.

Zero Telemetry · Strict CSP (connect-src 'none')

1. Paste OpenAPI Spec (Quick-Lint) & Controls

OAS 2.0 / 3.0 / 3.1 · OWASP API Top 10
Parsed JSON OpenAPI 3.0.1 · 2 ops · 1 {id} routes · 1 nullable: true · ~522 tok
OWASP API Top 10 & MCP Readiness Checklist (100 Points)
Low API Exploit & Token Risk
85 / 100 (B)
HARDENED — OWASP & MCP READY

Passing: 7 · Fixes Needed: 1 · Target: OpenAPI 3.1.0

Est. MCP Schema Tokens
1,490 tok
$6.71/mo at 50 turns/day ($3/1M)
Reclaimable Diet Savings
-340 tok
Saves $1.53/mo via MCPDiet
API2-AUTH (OWASP API2:2023): Explicit components.securitySchemes (Bearer JWT / OAuth2 scopes) + global/op security CRITICAL FIX
Missing components.securitySchemes or global security[] lets unauthenticated callers probe private routes (OWASP API2).
API1-BOLA (OWASP API1:2023): Object-ID routes ({id}) enforce explicit 401/403 responses & tenant ownership scopes PASS
Parameterized {id} endpoints verify tenant ownership and document 401/403 status codes.
API3-BOPLA (OWASP API3:2023): additionalProperties: false + readOnly: true on server-owned fields (role, id, plan) PASS
Request schemas lock additionalProperties: false and protect server fields with readOnly: true.
API4-BOUNDS (OWASP API4:2023): maxLength, maxItems, maximum & bounded pagination (limit <= 100 / cursor) on inputs PASS
Strings, arrays, and pagination limits define strict maxLength, maxItems, and maximum bounds.
API8-TLS (OWASP API8:2023): HTTPS-only servers[] URLs (zero http:// prod) + strict CORS allowlist & headers PASS
Production servers[] enforce HTTPS-only URLs and strict origin allowlist CORS.
API4-429 (OWASP API4 / API8): Explicit 401, 403 & 429 Too Many Requests responses with Retry-After / X-RateLimit-* PASS
401, 403, and 429 Too Many Requests responses include Retry-After / X-RateLimit-* headers.
API9-INV (OWASP API9:2023): Versioned base paths + deprecated: true ops declare Sunset header & replacement path PASS
Deprecated endpoints publish Sunset headers and migration paths; zero shadow APIs.
MCP-TOKEN (AI / MCP Readiness): Concise tool descriptions (<= 120 tok/op) & OpenAPI 3.1 type arrays (no nullable: true) PASS
Operation descriptions stay lean (~54 tok/op) and OpenAPI 3.1.0 avoids nullable drift.
openapi-owasp-remediation.yaml
openapi: "3.1.0"
info:
  title: "JWT & OAuth2 API Service"
  version: "1.0.0"
components:
  securitySchemes:
    bearerJwt:
      type: http
      scheme: bearer
      bearerFormat: JWT
    oauth2Auth:
      type: oauth2
      flows:
        authorizationCode:
          authorizationUrl: https://auth.example.com/authorize
          tokenUrl: https://auth.example.com/oauth/token
          scopes:
            items:read: Read tenant-scoped resources
            items:write: Mutate tenant-scoped resources
security:
  - bearerJwt: []
Zero-Upload SpecDiff $49 Remediation PR

Audit Full OpenAPI Specs or Ship a Hardened PR Today

Run a 100% browser-side breaking-change diff, OWASP API Top 10 scan & SARIF 2.1.0 export on SpecDiff (https://spec.runglab.dev), order a $49 Done-For-You OpenAPI & MCP Remediation PR on Creem, or automate via POST /v1/openapi/audit (API Hub), remote MCP tool audit_openapi_spec, and Apify Cloud PPE.

OpenAPI Controls, Bounds & Verification Reference

Rule / Control Hardened Pattern Security & Token Rationale
Bearer JWT Scheme type: http / scheme: bearer / JWT Replaces ad-hoc `Authorization` header parameters inside every route
OAuth2 Granular Scopes flows.authorizationCode.scopes Enforces least privilege per operation (read vs write vs admin)
Global Default Security Root security: [{ bearerJwt: [] }] Fail-closed default; public routes must explicitly opt out with security: []
401 + WWW-Authenticate RFC 9728 resource_metadata link Enables zero-config OAuth discovery for AI agents and MCP clients

Hardened OpenAPI 3.1 Bearer JWT + OAuth2 Security Schemes

security-schemes.yaml
components:
  securitySchemes:
    bearerJwt:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Short-lived RS256/EdDSA JWT access token (<=15m TTL).
    oauth2Auth:
      type: oauth2
      flows:
        authorizationCode:
          authorizationUrl: https://auth.example.com/oauth/authorize
          tokenUrl: https://auth.example.com/oauth/token
          scopes:
            billing:read: Read invoices and subscription status
            billing:write: Modify billing seats and payment methods
security:
  - bearerJwt: []
paths:
  /v1/health:
    get:
      security: []
      description: Public unauthenticated readiness probe.
      responses:
        "200":
          description: Healthy

OAuth 401 Header Pairing for MCP & Agent Clients (RFC 9728)

rfc9728-401-response.yaml
responses:
  "401":
    description: Missing or invalid Bearer token
    headers:
      WWW-Authenticate:
        schema:
          type: string
        example: Bearer resource_metadata="https://api.example.com/.well-known/oauth-protected-resource"

Key Engineering Takeaways

  • Manually adding `name: Authorization, in: header` inside `parameters[]` violates OpenAPI conventions and causes SDK generators, API gateways, and MCP converters to skip credential injection.
  • Setting root-level `security:` makes authentication fail-closed by default so newly added endpoints automatically inherit protection unless explicitly marked `security: []`.
  • Pairing OpenAPI `oauth2` scopes with `/.well-known/oauth-protected-resource` (RFC 9728) ensures autonomous MCP clients authenticate seamlessly without custom scripts.

Common Contract Pitfalls to Avoid

  • Passing API keys inside URL query strings (`in: query`) where credentials leak into reverse-proxy logs, browser history, and Referer headers.
  • Defining `securitySchemes` in `components` without referencing them in root `security:` or per-operation `security:`.
  • Using a single wildcard scope instead of separating read, write, and billing/admin operations.

More OpenAPI OWASP & MCP Optimization Guides

← Back to OpenAPI OWASP & MCP Scorer Hub · 2026 N=26 OpenAPI & MCP Benchmark → · MCP Context Token Cost Calculator → · CORS Preflight & Webhook HMAC Debugger → · SpecDiff Live Diff & SARIF → · $49 Remediation PR →

Frequently Asked Questions

Why shouldn't I model Authorization as a normal header parameter in OpenAPI?

OpenAPI 3.0/3.1 explicitly ignores Authorization, Accept, and Content-Type header parameters in favor of `components.securitySchemes` — using `parameters` breaks Swagger UI auth buttons, SDKs, and gateway enforcement.

How do I mark a single public route like /health when global security is enabled?

Add `security: []` directly on that specific operation (`get:`) to override the root `security:` requirement explicitly.

Can RungLab check my domain's RFC 9728 OAuth metadata alongside OpenAPI?

Yes — use our Cluster 6 Agent Discovery Linter (/agent-discovery/) for RFC 9728 manifests and SpecDiff (https://spec.runglab.dev) for OpenAPI securitySchemes.