OAuth Security refers to a security control or process that protects systems and data from unauthorized access and threats.
Essential for preventing unauthorized system access, protecting sensitive data, and ensuring compliance with security regulations.
Used continuously across all systems to verify and manage access based on authorization policies and procedures.
Implements security measures and controls to identify, authenticate, and authorize users or systems before granting access to resources.
All organizations managing digital systems and data must implement controls to protect employees, customers, and business assets.
Apply best practices, regularly audit security controls, update policies, integrate with overall security strategy, and provide training.
Common OAuth vulnerabilities include open redirect exploitation through lax redirect URI validation, authorization code interception in mobile apps, CSRF attacks on the authorization endpoint, token leakage through referrer headers or browser history, insufficient scope validation granting excessive permissions, client secret exposure in public applications, and mixed-up attacks in multi-provider configurations that enable token theft.
Redirect URI attacks exploit insufficient validation of the redirect_uri parameter. Attackers register near-matching URIs or exploit open redirects on legitimate domains to redirect authorization codes or tokens to attacker-controlled endpoints. Strict exact-match validation, avoiding wildcard patterns, and prohibiting localhost and IP-based redirect URIs are essential. OAuth 2.1 mandates exact redirect URI matching to eliminate this attack class.
Proof Key for Code Exchange protects against authorization code interception by binding the code to the client that requested it. The client generates a random code verifier and sends its hash as a challenge in the authorization request. When exchanging the code, the client provides the original verifier, which the server validates against the stored challenge. PKCE is now recommended for all OAuth clients, not just mobile apps.
Access tokens should use short expiration times of 5 to 15 minutes, be transmitted only over TLS, stored securely using appropriate platform mechanisms, and validated on every API request. Implement sender-constrained tokens using DPoP or mutual TLS to prevent token theft. Avoid including tokens in URLs or query parameters. Use opaque tokens externally and validate JWTs with proper signature and claim verification internally.
OAuth 2.1 consolidates security best practices by mandating PKCE for all authorization code flows, requiring exact redirect URI matching, deprecating the implicit grant flow, removing the resource owner password credentials grant, requiring refresh token rotation or sender constraining, and mandating that authorization servers support the authorization code grant. These changes eliminate several well-known vulnerability classes.
Mobile OAuth security requires using the authorization code flow with PKCE, implementing custom URI schemes or app links for redirects, avoiding embedded web views that enable credential interception, storing tokens in platform secure storage like Keychain or Keystore, implementing certificate pinning for token endpoint communication, and using claimed HTTPS URI redirects to prevent scheme hijacking by malicious applications.
Token theft occurs when access or refresh tokens are intercepted or extracted by attackers. Prevention methods include implementing sender-constrained tokens that are cryptographically bound to the requesting client, using short-lived access tokens with refresh token rotation, monitoring for token reuse from unusual locations, implementing token revocation on suspicious activity, and using secure token storage mechanisms appropriate to the platform.
OAuth scopes should follow least privilege principles with granular permissions rather than broad access grants. Define scopes that map to specific API operations, implement scope validation on every protected resource, document scope requirements clearly for developers, provide scope downgrade capabilities, and audit scope usage to identify overprivileged applications. Avoid designing scopes that grant write access when only read access is needed.