Invalid OAuth2 Authorization URL (v2)
- Query id: 33d96c65-977d-4c33-943f-440baca49185
- Query name: Invalid OAuth2 Authorization URL (v2)
- Platform: OpenAPI
- Severity: Medium
- Category: Access Control
- URL: Github
Description¶
The field authorizationUrl on implicit or authorizationCode fields from OAuth must be a valid URL
Documentation
Code samples¶
Code samples with security vulnerabilities¶
Positive test num. 1 - yaml file
swagger: "2.0"
info:
title: Simple API Overview
version: 1.0.0
license:
name: "Apache 2.0"
url: "https://www.apache.org/licenses/LICENSE-2.0.html"
paths:
"/":
get:
operationId: listVersionsv2
summary: List API versions
responses:
"200":
description: 200 response
securityDefinitions:
api_key:
type: oauth2
authorizationUrl: https://api.invalid.comp@#any.com/oauth/authorize
flow: accessCode
petstore_auth:
type: oauth2
authorizationUrl: https://api.invalid.comp@#any.com/oauth/authorize
flow: implicit
scopes:
write:pets: modify pets in your account
read:pets: read your pets
Positive test num. 2 - json file
{
"swagger": "2.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0",
"license": {
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
}
},
"paths": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "200 response"
}
}
}
}
},
"securityDefinitions": {
"api_key": {
"type": "oauth2",
"authorizationUrl": "https://api.invalid.comp@#any.com/oauth/authorize",
"flow": "accessCode"
},
"petstore_auth": {
"type": "oauth2",
"authorizationUrl": "https://api.invalid.comp@#any.com/oauth/authorize",
"flow": "implicit",
"scopes": {
"write:pets": "modify pets in your account",
"read:pets": "read your pets"
}
}
}
}
Code samples without security vulnerabilities¶
Negative test num. 1 - yaml file
swagger: "2.0"
info:
title: Simple API Overview
version: 1.0.0
license:
name: "Apache 2.0"
url: "https://www.apache.org/licenses/LICENSE-2.0.html"
paths:
"/":
get:
operationId: listVersionsv2
summary: List API versions
responses:
"200":
description: 200 response
securityDefinitions:
api_key:
type: oauth2
authorizationUrl: http://swagger.io/api/oauth/apikey
flow: accessCode
petstore_auth:
type: oauth2
authorizationUrl: http://swagger.io/api/oauth/dialog
flow: implicit
scopes:
write:pets: modify pets in your account
read:pets: read your pets
Negative test num. 2 - json file
{
"swagger": "2.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0",
"license": {
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
}
},
"paths": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "200 response"
}
}
}
}
},
"securityDefinitions": {
"api_key": {
"type": "oauth2",
"authorizationUrl": "http://swagger.io/api/oauth/apikey",
"flow": "accessCode"
},
"petstore_auth": {
"type": "oauth2",
"authorizationUrl": "http://swagger.io/api/oauth/dialog",
"flow": "implicit",
"scopes": {
"write:pets": "modify pets in your account",
"read:pets": "read your pets"
}
}
}
}