Operation Using Basic Auth

  • Query id: ceefb058-8065-418f-9c4c-584a78c7e104
  • Query name: Operation Using Basic Auth
  • Platform: OpenAPI
  • Severity: Medium
  • Category: Access Control
  • CWE: 284
  • URL: Github

Description

Operation Object should not use basic authentication
Documentation

Code samples

Code samples with security vulnerabilities

Positive test num. 1 - json file
{
  "swagger": "2.0",
  "info": {
    "title": "Simple API overview",
    "version": "1.0.0"
  },
  "schemes": [
    "https"
  ],
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "200 response"
          }
        },
        "security": [
          {
            "oAuth2AuthCodeNeg2": []
          }
        ]
      }
    }
  },
  "securityDefinitions": {
    "oAuth2AuthCodeNeg2": {
      "type": "basic",
      "description": "For more information, see https://api.my.company.com/docs/oauth"
    }
  }
}
Positive test num. 2 - yaml file
swagger: "2.0"
info:
  title: Simple API overview
  version: 1.0.0
schemes:
  - https
paths:
  "/":
    get:
      operationId: listVersionsv2
      summary: List API versions
      responses:
        "200":
          description: 200 response
      security:
        - oAuth2AuthCodeNeg2: []
securityDefinitions:
  oAuth2AuthCodeNeg2:
    type: basic
    description: For more information, see https://api.my.company.com/docs/oauth

Code samples without security vulnerabilities

Negative test num. 1 - json file
{
  "swagger": "2.0",
  "info": {
    "title": "Simple API overview",
    "version": "1.0.0"
  },
  "schemes": [
    "https"
  ],
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "200 response"
          }
        },
        "security": [
          {
            "oAuth2AuthCodeNeg2": [
              "write",
              "read"
            ]
          }
        ]
      }
    }
  },
  "securityDefinitions": {
    "oAuth2AuthCodeNeg2": {
      "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": {
        "write:api": "modify apis in your account",
        "read:api": "read your apis"
      }
    }
  }
}
Negative test num. 2 - yaml file
swagger: "2.0"
info:
  title: Simple API overview
  version: 1.0.0
schemes:
  - https
paths:
  "/":
    get:
      operationId: listVersionsv2
      summary: List API versions
      responses:
        "200":
          description: 200 response
      security:
        - oAuth2AuthCodeNeg2:
            - write
            - read
securityDefinitions:
  oAuth2AuthCodeNeg2:
    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:
      write:api: modify apis in your account
      read:api: read your apis