Article · api-security / openapi / python
When does an authorization rule become weaker in an OpenAPI file?
Global security inheritance, empty scope lists and AND–OR changes: reading access conditions across two OpenAPI files.
An API change can leave the path, parameters and response fields untouched while changing the conditions declared for accessing an operation. A small edit to security may have a larger meaning than its line count suggests.
The example prepared for OpenAPI Auth Drift asks a specific question: Which condition required by the old document is no longer required by the new one? The aim is to make effective authentication and authorization requirements easier to compare across two local OpenAPI documents. This invoice API is entirely synthetic, with no real server, tokens or invoice records.
Read inheritance before the operation
The document declares bearerAuth globally. The old GET /invoices operation has no separate security field, so it inherits that requirement. The new version adds security: [] to the operation. In the document model, this removes the inherited authentication condition. It does not demonstrate that a live API accepts anonymous requests. Operation overrides are described in the OpenAPI 3.0.4 Operation Object.
Spotting an empty array in the new file is only part of the comparison. We also need the requirement inherited by the old operation. Here, an absent operation field and an explicitly empty one have different effects. The effective condition matters more than the individual changed line.
An empty list does not always mean anonymous
For /export, security: [{oauth: [read]}] becomes security: [{oauth: []}]. The required read scope disappears, while the OAuth scheme requirement remains. This is a scope reduction, not anonymous access. A scope names an authorization permission requested for the token.
The unchanged /private operation uses security: [{bearerAuth: []}] and still declares authentication. An empty list attached to a scheme is different from an empty security array. The distinction follows the OpenAPI 3.1.1 Security Requirement Object.
The same schemes, connected differently
For /dual, the old requirement is [{A: [], B: []}]; the new one is [{A: []}, {B: []}]. Previously, both A and B were required. Now, either is sufficient. AND becomes OR, creating more accepted paths without removing authentication altogether. The difference between conditions inside one object and alternatives in the surrounding array is defined by the Security Requirement Object.
Calling all three edits “authentication removed” would discard useful information. /invoices introduces anonymous access in the model, /export reduces a scope requirement, and /dual relaxes the need to satisfy both schemes. Each needs its own review question: Was the change intentional, and which use case requires it?
From a document difference to a review decision
The comparison command for the synthetic example files is:
python openapi_auth_drift.py examples/before.json examples/after.json --format jsonFrom the tool directory, the command takes the old document first and the new document second. JSON is intended for processing the comparison as a report. Other OpenAPI comparison tools exist. This work focuses on effective auth conditions after applying global inheritance and operation overrides.
The recorded example grows from four operations to five and reports four findings: three changed requirements and the new /health operation. A policy with the exact method, path and reason marks only /health as acknowledged, keeping it visible and leaving the other three findings actionable. This records the intentional public operation without dismissing the other changes.
The result is a signal for reviewing what the documents declare. The tool is not intended to send real HTTP requests, validate tokens or test access to data. Unresolved references and unreadable inputs should not become “no changes” results either. Whether the implementation follows the declared rule remains a separate question for authorized validation.
Explore the three changes visually. Download the CLI, including its README, supported profile and synthetic examples.