Invalid OAuth2 Authorization URL (v3)

  • Query id: 52c0d841-60d6-4a81-88dd-c35fef36d315
  • Query name: Invalid OAuth2 Authorization URL (v3)
  • Platform: OpenAPI
  • Severity: Medium
  • Category: Access Control
  • CWE: 284
  • 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 - 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": {
                "examples": {
                  "foo": {
                    "value": {
                      "versions": [
                        {
                          "status": "CURRENT",
                          "updated": "2011-01-21T11:33:21Z",
                          "id": "v2.0",
                          "links": [
                            {
                              "href": "http://127.0.0.1:8774/v2/",
                              "rel": "self"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "oAuth2AuthCodeNeg2": {
        "type": "oauth2",
        "description": "For more information, see https://api.my.company.com/docs/oauth",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://api.invalid.company.com#@evil.com/oauth/authorize",
            "tokenUrl": "https://api.my.company.com/oauth/token",
            "scopes": {
              "write:api": "modify apis in your account",
              "read:api": "read your apis"
            }
          }
        }
      }
    }
  }
}
Positive 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": {
                "examples": {
                  "foo": {
                    "value": {
                      "versions": [
                        {
                          "status": "CURRENT",
                          "updated": "2011-01-21T11:33:21Z",
                          "id": "v2.0",
                          "links": [
                            {
                              "href": "http://127.0.0.1:8774/v2/",
                              "rel": "self"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "oAuth2AuthCodeNeg2": {
        "type": "oauth2",
        "description": "For more information, see https://api.my.company.com/docs/oauth",
        "flows": {
          "implicit": {
            "authorizationUrl": "https://api.invalid.company.com#@evil.com/oauth/authorize",
            "scopes": {
              "write:api": "modify apis in your account",
              "read:api": "read your apis"
            }
          }
        }
      }
    }
  }
}
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:
              examples:
                foo:
                  value:
                    versions:
                    - status: CURRENT
                      updated: '2011-01-21T11:33:21Z'
                      id: v2.0
                      links:
                      - href: http://127.0.0.1:8774/v2/
                        rel: self
components:
  securitySchemes:
    oAuth2AuthCodeNeg2:
      type: oauth2
      description: For more information, see https://api.my.company.com/docs/oauth
      flows:
        authorizationCode:
          authorizationUrl: https://api.invalid.comp@#any.com/oauth/authorize
          tokenUrl: https://api.my.company.com/oauth/token
          scopes:
            write:api: modify apis in your account
            read:api: read your apis

Positive 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
      responses:
        '200':
          description: 200 response
          content:
            application/json:
              examples:
                foo:
                  value:
                    versions:
                    - status: CURRENT
                      updated: '2011-01-21T11:33:21Z'
                      id: v2.0
                      links:
                      - href: http://127.0.0.1:8774/v2/
                        rel: self
components:
  securitySchemes:
    oAuth2AuthCodeNeg2:
      type: oauth2
      description: For more information, see https://api.my.company.com/docs/oauth
      flows:
        implicit:
          authorizationUrl: https://api.invalid.comp@#any.com/oauth/authorize
          scopes:
            write:api: modify apis in your account
            read:api: read 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",
        "responses": {
          "200": {
            "description": "200 response",
            "content": {
              "application/json": {
                "examples": {
                  "foo": {
                    "value": {
                      "versions": [
                        {
                          "status": "CURRENT",
                          "updated": "2011-01-21T11:33:21Z",
                          "id": "v2.0",
                          "links": [
                            {
                              "href": "http://127.0.0.1:8774/v2/",
                              "rel": "self"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "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": {
              "write:api": "modify apis in your account",
              "read:api": "read your apis"
            }
          }
        }
      }
    }
  }
}
Negative test num. 2 - 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:
              examples:
                foo:
                  value:
                    versions:
                    - status: CURRENT
                      updated: '2011-01-21T11:33:21Z'
                      id: v2.0
                      links:
                      - href: http://127.0.0.1:8774/v2/
                        rel: self
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:
            write:api: modify apis in your account
            read:api: read your apis