Invalid OAuth2 Token URL (v2)

  • Query id: 274f910a-0665-4f08-b66d-7058fe927dba
  • Query name: Invalid OAuth2 Token URL (v2)
  • Platform: OpenAPI
  • Severity: Medium
  • Category: Access Control
  • URL: Github

Description

OAuth2 security definition flow requires a valid URL in the tokenUrl field
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:
  oAuth2AuthCodeNeg3:
    type: oauth2
    description: For more information, see https://api.my.company.com/docs/oauth
    flow: accessCode
    authorizationUrl: https://api.my.company.com/oauth/authorize
    tokenUrl: http://example.com#@evil.com/
    scopes:
      read:api: read your apis
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": {
    "oAuth2AuthCodeNeg3": {
      "type": "oauth2",
      "description": "For more information, see https://api.my.company.com/docs/oauth",
      "flow": "accessCode",
      "authorizationUrl": "https://api.my.company.com/oauth/authorize",
      "tokenUrl": "http://example.com#@evil.com/",
      "scopes": {
        "read:api": "read your apis"
      }
    }
  }
}

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:
  oAuth2AuthCodeNeg3:
    type: oauth2
    description: For more information, see https://api.my.company.com/docs/oauth
    flow: accessCode
    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. 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": {
    "oAuth2AuthCodeNeg3": {
      "type": "oauth2",
      "description": "For more information, see https://api.my.company.com/docs/oauth",
      "flow": "accessCode",
      "authorizationUrl": "https://api.my.company.com/oauth/authorize",
      "tokenUrl": "https://api.my.company.com/oauth/token",
      "scopes": {
        "read:api": "read your apis"
      }
    }
  }
}