Operation accepts access tokens from password grant flow transported as cleartext

Issue ID: operation-securityrequirement-oauth2-password-clear

Average severity: High

Description

The API operation accepts access tokens from resource owner password credentials 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.

This flow has been deprecated by OAuth Best Current Practice and must not be used.

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:

{
    "securityDefinitions": {
        "OAuth2": {
            "type": "oauth2",
            "flow": "password",
            "scopes": {
                "read": "read objects in your account",
                "write": "modify objects in your account"
            },
            "tokenUrl": "https://example.com/oauth/token"
        }
    },
    // ...
    "paths": {
        "/pets": {
            "post": {
                "description": "Creates a new pet in the store",
                "operationId": "addPet",
                "schemes": [
                    "http"
                ],
                "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.

The resource owner password grant flow in OAuth2 is highly dangerous, because it exposes the credentials of the resource owner to the client. Even in the best case, this expands the attack surface and also normalizes insecure behavior (entering your credentials somewhere else than the authorization server).

Remediation

Set schemes to HTTPS, and do not use resource owner password credentials grant flow in OAuth 2 authentication.

{
    "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"
        }
    },
    // ...
    "paths": {
        "/pets": {
            "post": {
                "description": "Creates a new pet in the store",
                "operationId": "addPet",
                "schemes": [
                    "https"
                ],
                "security": [
                    {
                        "OAuth2": [
                            "write",
                            "read"
                        ]
                    }
                ]
                // ...
            }
        }
    }
}