Implicit grant flow in OAuth2 authentication allowed

Issue ID: global-securityscheme-oauth2-implicit

Average severity: Minimal

Description

One or more global security schemes in the API allows to set security requirements that use implicit grant flow in OAuth2 authentication. This flow has been deprecated by OAuth Best Current Practice.

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 is a potential risk, because the definition is in security schemes. 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": [
        "https"
    ],
    // ...
    "securityDefinitions": {
        "OAuth2": {
            "type": "oauth2",
            "flow": "implicit",
            "scopes": {
                "readOnly": "read objects in your account"
            },
            "authorizationUrl": "https://example.com/oauth/authorize"
        }
    }
}

Possible exploit scenario

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

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