OAUTH2-CODE-INJECTION-001 security auth_error ai_generated true

OAuth2授权码可通过客户端开放重定向被攻击者注入

OAuth2 authorization code can be injected by attacker via open redirector on client

ID: security/oauth2-authorization-code-injection-via-open-redirector

其他格式: JSON · Markdown 中文 · English
85%修复率
88%置信度
1证据数
2024-03-15首次发现

版本兼容性

版本状态引入弃用备注
OAuth 2.0 RFC 6749 active
Spring Security OAuth2 2.5.x active
Microsoft Identity Platform v2.0 active

根因分析

客户端应用程序允许开放重定向,攻击者可以利用它将窃取的授权码注入到重定向URI中,如果状态参数可预测或重用,则绕过状态参数检查。

English

Client application allows open redirects that an attacker can use to inject a stolen authorization code into the redirect URI, bypassing the state parameter check if the state is predictable or reused.

generic

官方文档

https://datatracker.ietf.org/doc/html/rfc6749#section-10.12

解决方案

  1. 在客户端实施严格的重定向URI验证:精确匹配已注册的URI,不允许通配符或部分匹配。Spring Security示例:`http.authorizeRequests().oauth2Login().authorizationEndpoint().authorizationRequestRepository(new HttpSessionOAuth2AuthorizationRequestRepository())`。
  2. 确保state参数是每个授权请求的加密随机且不可重用的值。Node.js示例:`const state = crypto.randomBytes(16).toString('hex');` 并将其存储在会话中供验证。
  3. 完全禁用客户端应用程序上的开放重定向功能。审计所有重定向端点,并将其删除或限制到允许的白名单中。

无效尝试

常见但无效的做法:

  1. 70% 失败

    If the state is predictable (e.g., timestamp-based) or reused, an attacker can craft a valid redirect with a stolen code.

  2. 60% 失败

    Wildcard patterns can be exploited to match attacker-controlled subdomains.

  3. 90% 失败

    The client must validate the redirect_uri to prevent code injection via open redirectors.