Access tokens transported as cleartext

Average severity: High

Description

Access tokens are transported 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.

For more details, see the OpenAPI Specification v2 or v3.

Example

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

OAS v2:

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

The security section defines that the API is protected with OAuth2 accessCode flow. The schemes section sets HTTP as the supported transportation protocol. This means that the API accepts an API call over an unencrypted HTTP connection, and expects it to have the OAuth tokens in the clear.

OAS v3:

...
{
	"security": [
		{
		"OAuth2": ["readOnly"]
		}
	]
}
...
{
	"servers": [
		{
			"url": "http://my.api.server.com/",
			"description": "API server"
		}
	]
}
...  
{
	"components": {
		"securitySchemes": {
			"OAuth2": {
				"type": "oauth2",
				"flows": {
					"authorizationCode": {
						"scopes": {
							"readOnly": "read objects in your account"
						},
						"authorizationUrl": "https://example.com/oauth/authorize",
						"tokenUrl": "https://example.com/oauth/token", 
					}
				}
			}
		}
	}
}

The security section defines that the API is protected with OAuth2 authorizationCode flow (accessCode flow in OAS v2), and the URL of the server for the API is set to HTTP.

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

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

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

OAS v3:

...
{
	"security": [
		{
		"OAuth2": ["readOnly"]
		}
	]
}
...
{
	"servers": [
		{
			"url": "https://my.api.server.com/",
			"description": "API server"
		}
	]
}
...  
{
	"components": {
		"securitySchemes": {
			"OAuth2": {
				"type": "oauth2",
				"flows": {
					"authorizationCode": {
						"scopes": {
							"readOnly": "read objects in your account"
						},
						"authorizationUrl": "https://example.com/oauth/authorize",
						"tokenUrl": "https://example.com/oauth/token", 
					}
				}
			}
		}
	}
}

Get API Security news directly in your Inbox.

By clicking Subscribe you agree to our Data Policy