Cleartext Credentials With Basic Authentication For Operation

  • Query id: 86b1fa30-9790-4980-994d-a27e0f6f27c1
  • Query name: Cleartext Credentials With Basic Authentication For Operation
  • Platform: OpenAPI
  • Severity: High
  • Category: Access Control
  • URL: Github

Description

Cleartext credentials over unencrypted channel should not be accepted for the operation
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"
  },
  "components": {
    "securitySchemes": {
      "regularSecurity": {
        "type": "http",
        "scheme": "basic"
      }
    }
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersions",
        "summary": "List versions",
        "servers": [
          {
            "url": "http://myapi.com/",
            "description": "server URL"
          }
        ],
        "security": [
          {
            "regularSecurity": []
          }
        ],
        "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"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
Positive test num. 2 - yaml file
openapi: 3.0.0
info:
  title: Simple API overview
  version: 1.0.0
components:
  securitySchemes:
    regularSecurity:
      type: http
      scheme: basic
paths:
  "/":
    get:
      operationId: listVersions
      summary: List versions
      servers:
        - url: http://myapi.com/
          description: server URL
      security:
        - regularSecurity: []
      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

Code samples without security vulnerabilities

Negative test num. 1 - json file
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API overview",
    "version": "1.0.0"
  },
  "components": {
    "securitySchemes": {
      "OAuth2": {
        "type": "oauth2",
        "flows": {
          "authorizationCode": {
            "scopes": {
              "write": "modify objects",
              "read": "read objects"
            },
            "authorizationUrl": "https://myapi.com/oauth/authorize",
            "tokenUrl": "https://myapi.com/oauth/token"
          }
        }
      }
    }
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersions",
        "summary": "List versions",
        "servers": [
          {
            "url": "http://myapi.com/",
            "description": "server URL"
          }
        ],
        "security": [
          {
            "OAuth2": [
              "write",
              "read"
            ]
          }
        ],
        "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"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
Negative test num. 2 - yaml file
openapi: 3.0.0
info:
  title: Simple API overview
  version: 1.0.0
components:
  securitySchemes:
    OAuth2:
      type: oauth2
      flows:
        authorizationCode:
          scopes:
            write: modify objects
            read: read objects
          authorizationUrl: https://myapi.com/oauth/authorize
          tokenUrl: https://myapi.com/oauth/token
paths:
  "/":
    get:
      operationId: listVersions
      summary: List versions
      servers:
        - url: http://myapi.com/
          description: server URL
      security:
        - OAuth2:
            - write
            - read
      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