Invalid OAuth2 Token URL (v3)
- Query id: 3ba0cca1-b815-47bf-ac62-1e584eb64a05
- Query name: Invalid OAuth2 Token URL (v3)
- Platform: OpenAPI
- Severity: Medium
- Category: Access Control
- URL: Github
Description¶
OAuth2 security scheme flow requires a valid URL in the tokenUrl field
Documentation
Code samples¶
Code samples with security vulnerabilities¶
Positive test num. 1 - yaml file
openapi: 3.0.0
info:
title: Simple API overview
version: 1.0.0
paths:
"/":
get:
operationId: listVersionsv2
summary: List API versions
responses:
'200':
description: 200 response
content:
application/json:
components:
securitySchemes:
oAuth2AuthCodePos1:
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: http://example.com#@evil.com/
scopes:
read:api: read your apis
Positive test num. 2 - yaml file
openapi: 3.0.0
info:
title: Simple API overview
version: 1.0.0
components:
securitySchemes:
oAuth2AuthCodePos2:
type: oauth2
description: For more information, see https://api.my.company.com/docs/oauth
flows:
password:
tokenUrl: inval`id
scopes:
read:api: read your apis
paths:
"/":
get:
operationId: listVersionsv2
summary: List API versions
responses:
'200':
description: 200 response
content:
application/json:
Positive 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
responses:
'200':
description: 200 response
content:
application/json:
components:
securitySchemes:
oAuth2AuthCodePos3:
type: oauth2
description: For more information, see https://api.my.company.com/docs/oauth
flows:
clientCredentials:
tokenUrl: httxps//|api
scopes:
read:api: read your apis
Positive test num. 4 - json file
{
"openapi": "3.0.0",
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"paths": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": null
}
}
}
}
}
},
"components": {
"securitySchemes": {
"oAuth2AuthCodePos1": {
"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": "http://example.com#@evil.com/",
"scopes": {
"read:api": "read your apis"
}
}
}
}
}
}
}
Positive test num. 5 - json file
{
"openapi": "3.0.0",
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"components": {
"securitySchemes": {
"oAuth2AuthCodePos2": {
"type": "oauth2",
"description": "For more information, see https://api.my.company.com/docs/oauth",
"flows": {
"password": {
"tokenUrl": "inval`id",
"scopes": {
"read:api": "read your apis"
}
}
}
}
}
},
"paths": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": null
}
}
}
}
}
}
}
Positive test num. 6 - json file
{
"openapi": "3.0.0",
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"paths": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": null
}
}
}
}
}
},
"components": {
"securitySchemes": {
"oAuth2AuthCodePos3": {
"type": "oauth2",
"description": "For more information, see https://api.my.company.com/docs/oauth",
"flows": {
"clientCredentials": {
"tokenUrl": "httxps//|api",
"scopes": {
"read:api": "read your apis"
}
}
}
}
}
}
}
Code samples without security vulnerabilities¶
Negative test num. 1 - yaml file
openapi: 3.0.0
info:
title: Simple API overview
version: 1.0.0
paths:
"/":
get:
operationId: listVersionsv2
summary: List API versions
responses:
'200':
description: 200 response
content:
application/json:
components:
securitySchemes:
oAuth2AuthCodeNeg1:
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: http://localhost.com:8080
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",
"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"
}
}
}
}
}
}
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
responses:
'200':
description: 200 response
content:
application/json:
components:
securitySchemes:
oAuth2AuthCodeNeg3:
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