Back

duendesoftware.com

7 common security pitfalls in OAuth 2.0 implementations

Updated 3/4/2026
https://duendesoftware.com/learn/7-common-security-pitfalls-oauth-2-0-implementations

Security issues in OAuth 2.0 rarely stem from problems in the specification itself. Instead, they arise from how individual applications interpret or configure OAuth in real-world environments. This article highlights seven common security pitfalls that appear frequently in real-world systems — issues that weaken defenses, undermine trust boundaries, or introduce subtle vulnerabilities that attackers can exploit. … ## 1. Choosing the Wrong Grant Type for the Scenario OAuth 2.0 offers several grant types, each intended for a specific kind of client and deployment environment. A common source of problems is using these flows without considering whether the client is public or confidential — that is, whether it can securely store secrets. A common example is using the Client Credentials grant (`client_credentials`) for user authentication. Because this flow has no end user, it is only appropriate for machine-to-machine communication. Applying it to a login flow blurs the line between a user and an application and leaves the system with no cryptographic proof of who is actually present. … ## 3. Redirect URI Pitfalls A redirect URI is the callback URL an application registers with the authorization server — for example, `https://app.example.com/auth/callback`. Problems arise when these URIs are either too permissive or incorrectly configured. *Overly permissive redirect URIs* may be accepted by some providers but are insecure in practice, especially when they include wildcards, broad domain patterns, or allow both HTTP and HTTPS — giving potential attackers more flexibility to redirect authorization codes to malicious endpoints. *Misconfigured redirect URIs*, on the other hand, may be valid or invalid and can break the flow or open the door to unintended redirection behavior. Examples include mismatched callback paths (even small differences such as a single forward slash matter), typos in the URL, and unused registered redirect URIs. Redirect URIs should be treated as strict allow-lists, matching exactly what the authorization server expects. As has been pointed out, even small inconsistencies can undermine OAuth's protections and create opportunities for token interception. ## 4. Incomplete or Incorrect Token Validation in APIs Once an access token reaches an API, proper validation is essential. APIs are responsible for verifying several core properties of every token, and security weaknesses emerge when these checks are skipped or implemented incorrectly. In ASP.NET Core, much of this validation is enabled by default, but it can still be misconfigured or overridden inadvertently. At a minimum, APIs should validate: - **Issuer (`iss`)**: ensuring the token was issued by the expected authorization server - **Audience (`aud`)**: confirming the token was intended for this API - **Expiration (`exp`)**: rejecting tokens that are expired or outside their valid window - **Signature**: verifying that the token has not been tampered with OAuth token validation may include additional checks depending on the system's architecture and requirements, but these core fields form the minimum required for an API to enforce its trust boundary. When APIs omit or weaken these checks, they may inadvertently accept tokens from the wrong tenant, tokens issued for different services, or tokens that are expired or replayed. … ## 5. Storing Tokens Insecurely on the Client Even when OAuth flows are configured correctly, applications can weaken security by storing tokens in an unsafe manner. In browser-based applications, placing tokens in `localStorage` or `sessionStorage` exposes them to any script running on the page, including malicious scripts injected through Cross-Site Scripting (XSS) attacks. A script with access to the page can read the tokens and send them to a potential attacker. … ## 6. Overly Broad Scopes and Excessive Permissions OAuth scopes determine which resources a client is allowed to access, but they are easy to misuse. A common pitfall is treating scopes as if they are roles or broad access tiers instead of precise, task-specific permissions. When scopes are defined too broadly — or when clients request more access than necessary — the system begins to violate the principle of least privilege. Overly broad scopes increase the impact of token leakage — situations where an access token is exposed to an unauthorized party. If a leaked token grants wide-ranging permissions, an attacker may be able to call multiple APIs, read or modify high-value data, or perform privileged operations. This risk grows in distributed systems, where a single access token can unlock several downstream services. A more secure pattern is to keep scopes narrowly defined and to grant only the minimum access required for each scenario. In practice, this means: - Designing small, task-specific scopes - Requiring clients to request only the permissions needed for the operation they are performing - Reviewing scope definitions periodically as APIs and access patterns evolve … ## 7. Using Long-Lived Access Tokens Long-lived access tokens are widely discouraged in the OAuth ecosystem. The longer an access token remains valid, the greater the opportunity for an attacker to steal and reuse it. Most access tokens are self-contained, so APIs will treat them as valid for their entire lifetime.

Related Pain Points5