Transporting access tokens as cleartext allowed

Average severity: High

Description

The security scheme allows transporting access tokens in the clear over an unencrypted channel. Attackers can easily intercept API calls and retrieve the tokens. They can then use the tokens to make other API calls.

This is a potential risk, because the definition is in the security scheme, not in the security requirements. However, it easily turns into an actual risk when the unsafe method is used in a security requirement.

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": {
    "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" ]
    }
  ]
}

Possible exploit scenario

Attackers can intercept access tokens 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 tokens.

Remediation

Set  schemes to support HTTPS only so that all traffic is encrypted.

  "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" ]
    }
  ]
}

Get API Security news directly in your Inbox.

By clicking Subscribe you agree to our Data Policy