Access tokens from implicit grant flow transported as cleartext

Issue ID: global-securityrequirement-oauth2-implicit-clear

Average severity: High

Description

The API accepts access tokens from implicit grant flow in OAuth2 authentication that 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.

OAuth2 implicit grant flow uses long-lived access tokens, does not support refresh tokens, and the technical limitations that used to justify using the flow are gone. This flow has been deprecated by OAuth Best Current Practice.

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": "implicit",
            "scopes": {
                "readOnly": "read objects in your account"
            },
            "authorizationUrl": "https://example.com/oauth/authorize"
        }
    },
    // ...
    "security" : {
        "OAuth2": [ "readOnly" ]
    }
}

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.

In addition, implicit grant flow can leak access tokens and is vulnerable to access token replay. The long-lived access tokens and lack of refresh tokens provide extended opportunity for exploits.

Remediation

Set schemes to HTTPS, and do not use implicit grant flow in OAuth2 authentication.

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