Sending credentials as cleartext allowed

Description

One or more global security schemes in the API allows to set security requirements that accept user credentials sent in cleartext over an unencrypted channel. Attackers can easily intercept API calls and retrieve the credentials. They can then use the credentials to make other API calls.

This is a potential risk, because the definition is done on the global level. However, it easily turns into an actual risk when the unsafe method is used in a security requirement or operation.

For more details, see the OpenAPI Specification.

Example

The following is an example of how this type of risk could look in your API definition:

  "schemes": [
    "http"
  ],
  ...
  "securityDefinitions": {
    "regularSecurity": {
      "type": "basic"
    }
  },
  ...
  "security": [
    {
      "regularSecurity": []
    }
  ],
  ...
}

The security field defines that the API is protected with basic authentication (username and password). The schemes field sets HTTP as the supported transportation protocol. This means that the API could accept an API call over an unencrypted HTTP connection, and expects it to have the username and password in the clear.

Possible exploit scenario

Attackers can intercept the credentials simply by listening to the network traffic in a public WiFi network. They could also use a traffic logging tool on a smartphone, computer, or browser, or sniff the traffic in the network to get the credentials.

Remediation

At the very least, set schemes to support HTTPS only so that all traffic is encrypted.

You could also improve the security of the authentication method. The OAuth 2.0 accessCode flow is considered the most secure way to provide API authorization for OpenAPI Specification v2.

            ...
  "schemes": [
    "https"
  ],
  ...
  "securityDefinitions": {
    "OAuth2": {
      "type": "oauth2",
      "flow": "accessCode",
      "scopes": {
        "readOnly": "read objects in your account"
      },
      "authorizationUrl": "https://example.com/oauth/authorize",
      "tokenUrl": "https://example.com/oauth/token", 
    }
  },
  ...
  "security" : [
    "OAuth2": [ "readOnly" ]
  ]
}