Skip to main content
MediumAPIOWASP A07:2021CWE-522

How to fix: OpenAPI document declares the OAuth2 implicit flow

The served API description declares an OAuth2 security scheme using the implicit grant. That flow returns the access token directly in the redirect URL fragment instead of through a back-channel exchange.

Why it matters

An implicit-grant token arrives in the URL fragment, so it lands in browser history, in any Referer sent by a script the page loads, and in the logs of anything that records full URLs. There is no client authentication and no PKCE, so a token intercepted at the redirect is immediately usable, and there is no refresh token, which pushes implementations toward long token lifetimes to compensate.

OAuth 2.0 Security Best Current Practice (RFC 9700) says the implicit grant must not be used, and OAuth 2.1 removes it. The replacement for browser and mobile clients is the authorization code grant with PKCE, which keeps the token out of the URL and binds the code to the client that requested it. A spec that still declares implicit usually means the authorization server still accepts it.

How to fix it

  1. 1Replace the implicit flow declaration with authorizationCode and require PKCE on the authorization server.
  2. 2Stop accepting response_type=token at the authorization endpoint once clients have migrated.
  3. 3Shorten the lifetime of any token that was issued through the implicit flow and rotate refresh credentials.

Code examples

OpenAPI 3: authorization code instead of implicit

YAML
components:
  securitySchemes:
    oauth2:
      type: oauth2
      flows:
        authorizationCode:
          authorizationUrl: https://auth.example.com/authorize
          tokenUrl: https://auth.example.com/token
          scopes:
            read: Read access
            write: Write access

Authorization request with PKCE

text
GET /authorize
  ?response_type=code
  &client_id=spa-client
  &redirect_uri=https%3A%2F%2Fapp.example.com%2Fcallback
  &code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM
  &code_challenge_method=S256
  &state=<random>

References

Detected automatically by VulnRadar. The check id is api-openapi-oauth2-implicit-flow-declared, stable across every scan so you can filter or diff on it.

See every api check

Questions

How severe is OpenAPI document declares the OAuth2 implicit flow?
VulnRadar rates this medium severity in the api category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id api-openapi-oauth2-implicit-flow-declared, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does OpenAPI document declares the OAuth2 implicit flow map to?
It maps to CWE-522. In the OWASP Top 10 it falls under A07:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for openapi document declares the oauth2 implicit flow

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

OpenAPI document declares the OAuth2 implicit flow | VulnRadar