Skip to content

Commit 55d0c62

Browse files
authored
Merge pull request #4388 from handrews/sec-req-uri
Allow URIs for Security Schemes
2 parents bcf3c58 + 33aef07 commit 55d0c62

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

Diff for: src/oas.md

+20-6
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ This allows Security Scheme Objects and Tag Objects to be defined next to the AP
214214

215215
The interface approach can also work for Discriminator Objects and Schema Objects, but it is also possible to keep the Discriminator Object's behavior within a single document using the relative URI-reference syntax of `mapping`.
216216

217-
There are no URI-based alternatives for the Security Requirement Object or for the Operation Object's `tags` field.
218-
These limitations are expected to be addressed in a future release.
217+
There are no URI-based alternatives for the Operation Object's `tags` field.
218+
This limitation is expected to be addressed in a future release.
219219

220220
See [Appendix F: Resolving Security Requirements in a Referenced Document](#appendix-f-resolving-security-requirements-in-a-referenced-document) for an example of the possible resolutions, including which one is recommended by this section.
221221
The behavior for Discrimator Object non-URI mappings and for the Operation Object's `tags` field operate on the same principles.
@@ -4165,7 +4165,12 @@ flows:
41654165
#### Security Requirement Object
41664166

41674167
Lists the required security schemes to execute this operation.
4168-
The name used for each property MUST correspond to a security scheme declared in the [Security Schemes](#security-scheme-object) under the [Components Object](#components-object).
4168+
4169+
The name used for each property MUST either correspond to a security scheme declared in the [Security Schemes](#security-scheme-object) under the [Components Object](#components-object), or be the URI of a Security Scheme Object.
4170+
Property names that are identical to a component name under the Components Object MUST be treated as a component name.
4171+
To reference a Security Scheme with a single-segment relative URI reference (e.g. `foo`) that collides with a component name (e.g. `#/components/securitySchemes/foo`), use the `.` path segment (e.g. `./foo`).
4172+
4173+
Using a Security Scheme component name that appears to be a URI is NOT RECOMMENDED, as the precedence of component-name-matching over URI resolution, which is necessary to maintain compatibility with prior OAS versions, is counter-intuitive. See also [Security Considerations](#security-considerations).
41694174

41704175
A Security Requirement Object MAY refer to multiple security schemes in which case all schemes MUST be satisfied for a request to be authorized.
41714176
This enables support for scenarios where multiple query parameters or HTTP headers are required to convey security information.
@@ -4178,8 +4183,8 @@ An empty Security Requirement Object (`{}`) indicates anonymous access is suppor
41784183
##### Patterned Fields
41794184

41804185
| Field Pattern | Type | Description |
4181-
| ---- | :----: | ---- |
4182-
| <a name="security-requirements-name"></a>{name} | [`string`] | Each name MUST correspond to a security scheme which is declared in the [Security Schemes](#security-scheme-object) under the [Components Object](#components-object). If the security scheme is of type `"oauth2"` or `"openIdConnect"`, then the value is a list of scope names required for the execution, and the list MAY be empty if authorization does not require a specified scope. For other security scheme types, the array MAY contain a list of role names which are required for the execution, but are not otherwise defined or exchanged in-band. |
4186+
| --- | :---: | --- |
4187+
| <a name="security-requirements-name"></a>{name} | [`string`] | Each name or URI MUST correspond to a security scheme as described above. If the security scheme is of type `"oauth2"` or `"openIdConnect"`, then the value is a list of scope names required for the execution, and the list MAY be empty if authorization does not require a specified scope. For other security scheme types, the array MAY contain a list of role names which are required for the execution, but are not otherwise defined or exchanged in-band. |
41834188

41844189
##### Security Requirement Object Examples
41854190

@@ -4199,6 +4204,8 @@ api_key: []
41994204

42004205
###### OAuth2 Security Requirement
42014206

4207+
This example uses a component name for the Security Scheme.
4208+
42024209
```json
42034210
{
42044211
"petstore_auth": ["write:pets", "read:pets"]
@@ -4213,14 +4220,16 @@ petstore_auth:
42134220

42144221
###### Optional OAuth2 Security
42154222

4223+
This example uses a relative URI reference for the Security Scheme.
4224+
42164225
Optional OAuth2 security as would be defined in an <a href="#openapi-object">OpenAPI Object</a> or an <a href="#operation-object">Operation Object</a>:
42174226

42184227
```json
42194228
{
42204229
"security": [
42214230
{},
42224231
{
4223-
"petstore_auth": ["write:pets", "read:pets"]
4232+
"#/components/securitySchemes/petstore_auth": ["write:pets", "read:pets"]
42244233
}
42254234
]
42264235
}
@@ -4282,6 +4291,11 @@ In addition, OpenAPI Descriptions are processed by a wide variety of tooling for
42824291

42834292
An OpenAPI Description describes the security schemes used to protect the resources it defines. The security schemes available offer varying degrees of protection. Factors such as the sensitivity of the data and the potential impact of a security breach should guide the selection of security schemes for the API resources. Some security schemes, such as basic auth and OAuth Implicit flow, are supported for compatibility with existing APIs. However, their inclusion in OpenAPI does not constitute an endorsement of their use, particularly for highly sensitive data or operations.
42844293

4294+
The rules for connecting a [Security Requirement Object](#security-requirement-object) to a [Security Scheme Object](#security-scheme-object) under a [Components Object](#components-object) are ambiguous in a way that could be exploited. Specifically:
4295+
4296+
* It is implementation-defined whether a component name used by a Security Requirement Object in a referenced document is resolved from the entry document (RECOMMENDED) or the referenced document.
4297+
* A Security Requirement Object that uses a URI to identify a Security Scheme Object can have the URI resolution hijacked by providing a Security Scheme component name identical to the URI, as the name lookup behavior takes precedence over URI resolution for compatibility with previous versions of the OAS.
4298+
42854299
### Handling External Resources
42864300

42874301
OpenAPI Descriptions may contain references to external resources that may be dereferenced automatically by consuming tools. External resources may be hosted on different domains that may be untrusted.

0 commit comments

Comments
 (0)