Access tokens from client credentials grant flow transported as cleartext

Issue ID: v3-global-securityrequirement-oauth2-clientcredentials-clear

Average severity: High

Description

Access tokens from client credentials grant flow are transported in the clear over an unencrypted channel. Attackers can easily intercept API calls and retrieve the unencrypted tokens. They can then use the tokens to make other API calls.

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. The security requirement defines that the API is protected with OAuth2 client credentials flow. The server object 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 token in the clear:

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

Possible exploit scenario

Attackers can intercept the 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 all server objects to support HTTPS only so that all traffic is encrypted.

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