Undefined Scope 'securityScheme' On 'security' Field On Operations
- Query id: 462d6a1d-fed9-4d75-bb9e-3de902f35e6e
- Query name: Undefined Scope 'securityScheme' On 'security' Field On Operations
- Platform: OpenAPI
- Severity: Low
- Category: Access Control
- URL: Github
Description¶
Using an scope on security of operations that is undefined on 'securityScheme' can be defined by an attacker
Documentation
Code samples¶
Code samples with security vulnerabilities¶
Postitive test num. 1 - json file
{
"openapi": "3.0.0",
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"paths": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"security": {
"oAuth2AuthCodeNeg2": [
"read:api",
"error:api"
]
},
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": null
}
}
}
}
}
},
"components": {
"securitySchemes": {
"oAuth2AuthCodeNeg2": {
"type": "oauth2",
"description": "For more information, see https://api.my.company.com/docs/oauth",
"flows": {
"authorizationCode": {
"authorizationUrl": "https://api.my.company.com/oauth/authorize",
"tokenUrl": "https://api.my.company.com/oauth/token",
"scopes": {
"read:api": "read your apis",
"admin:api": "admin scope"
}
},
"password": {
"tokenUrl": "https://api.my.company.com/oauth/token",
"scopes": {
"write:api": "write your apis"
}
}
}
}
}
}
}
Postitive test num. 2 - json file
{
"openapi": "3.0.0",
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"paths": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"security": [
{
"oAuth2AuthCodeNeg2": [
"error:api",
"write:api"
]
}
],
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": null
}
}
}
}
}
},
"components": {
"securitySchemes": {
"oAuth2AuthCodeNeg2": {
"type": "oauth2",
"description": "For more information, see https://api.my.company.com/docs/oauth",
"flows": {
"authorizationCode": {
"authorizationUrl": "https://api.my.company.com/oauth/authorize",
"tokenUrl": "https://api.my.company.com/oauth/token",
"scopes": {
"read:api": "read your apis",
"admin:api": "admin scope"
}
},
"password": {
"tokenUrl": "https://api.my.company.com/oauth/token",
"scopes": {
"write:api": "write your apis"
}
}
}
}
}
}
}
Postitive test num. 3 - yaml file
openapi: 3.0.0
info:
title: Simple API overview
version: 1.0.0
paths:
"/":
get:
operationId: listVersionsv2
summary: List API versions
security:
oAuth2AuthCodeNeg2:
- read:api
- error:api
responses:
'200':
description: 200 response
content:
application/json:
components:
securitySchemes:
oAuth2AuthCodeNeg2:
type: oauth2
description: For more information, see https://api.my.company.com/docs/oauth
flows:
authorizationCode:
authorizationUrl: https://api.my.company.com/oauth/authorize
tokenUrl: https://api.my.company.com/oauth/token
scopes:
read:api: read your apis
admin:api: admin scope
password:
tokenUrl: https://api.my.company.com/oauth/token
scopes:
write:api: write your apis
Postitive test num. 4 - yaml file
openapi: 3.0.0
info:
title: Simple API overview
version: 1.0.0
paths:
"/":
get:
operationId: listVersionsv2
summary: List API versions
security:
- oAuth2AuthCodeNeg2:
- error:api
- write:api
responses:
'200':
description: 200 response
content:
application/json:
components:
securitySchemes:
oAuth2AuthCodeNeg2:
type: oauth2
description: For more information, see https://api.my.company.com/docs/oauth
flows:
authorizationCode:
authorizationUrl: https://api.my.company.com/oauth/authorize
tokenUrl: https://api.my.company.com/oauth/token
scopes:
read:api: read your apis
admin:api: admin scope
password:
tokenUrl: https://api.my.company.com/oauth/token
scopes:
write:api: write your apis
Code samples without security vulnerabilities¶
Negative test num. 1 - json file
{
"openapi": "3.0.0",
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"paths": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"security": [
{
"oAuth2AuthCodeNeg2": [
"read:api",
"write:api"
]
}
],
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": null
}
}
}
}
}
},
"components": {
"securitySchemes": {
"oAuth2AuthCodeNeg2": {
"type": "oauth2",
"description": "For more information, see https://api.my.company.com/docs/oauth",
"flows": {
"authorizationCode": {
"authorizationUrl": "https://api.my.company.com/oauth/authorize",
"tokenUrl": "https://api.my.company.com/oauth/token",
"scopes": {
"read:api": "read your apis",
"admin:api": "admin scope"
}
},
"password": {
"tokenUrl": "https://api.my.company.com/oauth/token",
"scopes": {
"write:api": "write your apis"
}
}
}
}
}
}
}
Negative test num. 2 - json file
{
"openapi": "3.0.0",
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"paths": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"security": {
"oAuth2AuthCodeNeg2": [
"read:api",
"write:api"
]
},
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": null
}
}
}
}
}
},
"components": {
"securitySchemes": {
"oAuth2AuthCodeNeg2": {
"type": "oauth2",
"description": "For more information, see https://api.my.company.com/docs/oauth",
"flows": {
"authorizationCode": {
"authorizationUrl": "https://api.my.company.com/oauth/authorize",
"tokenUrl": "https://api.my.company.com/oauth/token",
"scopes": {
"read:api": "read your apis",
"admin:api": "admin scope"
}
},
"password": {
"tokenUrl": "https://api.my.company.com/oauth/token",
"scopes": {
"write:api": "write your apis"
}
}
}
}
}
}
}
Negative test num. 3 - yaml file
openapi: 3.0.0
info:
title: Simple API overview
version: 1.0.0
paths:
"/":
get:
operationId: listVersionsv2
summary: List API versions
security:
- oAuth2AuthCodeNeg2:
- read:api
responses:
'200':
description: 200 response
content:
application/json:
components:
securitySchemes:
oAuth2AuthCodeNeg2:
type: oauth2
description: For more information, see https://api.my.company.com/docs/oauth
flows:
authorizationCode:
authorizationUrl: https://api.my.company.com/oauth/authorize
tokenUrl: https://api.my.company.com/oauth/token
scopes:
read:api: read your apis
Negative test num. 4 - yaml file
openapi: 3.0.0
info:
title: Simple API overview
version: 1.0.0
paths:
"/":
get:
operationId: listVersionsv2
summary: List API versions
security:
- oAuth2AuthCodeNeg2:
- read:api
responses:
'200':
description: 200 response
content:
application/json:
components:
securitySchemes:
oAuth2AuthCodeNeg2:
type: oauth2
description: For more information, see https://api.my.company.com/docs/oauth
flows:
authorizationCode:
authorizationUrl: https://api.my.company.com/oauth/authorize
tokenUrl: https://api.my.company.com/oauth/token
scopes:
read:api: read your apis