为什么重定向 URL 在 Azure AD B2C 中完全合格?
Why is Redirect URL Fully Qualified in Azure AD B2C?
为什么 redirect URL 必须完全匹配?域级别的匹配是否足以确保适当的安全性?
如果我有数百条路径怎么办?
示例网址:
- https://myawesomesite.com
- https://myawesomesite.com/account/profile
- https://myawesomesite.com/games/fungame/points
- https://www.myawesomesite.com/games/fungame/points
...
我必须在我的 B2C 应用程序配置中输入上述 4 个重定向网址。
所有身份验证请求通常(也是最简单的)包含两个重定向 URLs:
- 在"redirect_uri"参数中传递的一个(通常称为回复URL),必须 注册到 Azure AD B2C,所有 身份验证响应从 Azure AD B2C returned 到依赖方应用程序。例如
https://www.myawesomesite.com/oidc-signin
.
- 另一个(通常称为returnURL)在"state"参数中进行往返,其中 不必 向 Azure AD B2C 注册,在依赖方应用程序处理身份验证响应后,最终用户将 return 注册到 Azure AD B2C。例如
https://www.myawesomesite.com/games/fungame/points
.
身份验证处理程序,例如 the ASP.NET Core authentication middleware,为您管理这些重定向 URL。
例如,当身份验证处理程序创建身份验证请求时,它会在 "state" 请求参数中对当前受保护的 URL(例如 https://www.myawesomesite.com/games/fungame/points
)进行编码。
为确保此 URL 不被篡改,应使用加密或签名保护 "state" 参数。
当身份验证处理程序处理身份验证响应时,假设它是一个成功的响应,它会创建一个身份 cookie 并将最终用户从 https://www.myawesomesite.com/oidc-signin
重定向到 [=] 中最初受保护的 URL 42=]响应参数。
这实际上在 RFC 6819 "OAuth 2.0 Threat Model and Security Considerations" sections 4.1.5, 4.2.4 and 5.2.3.5 中讨论过。
4.1.5. Threat: Open Redirectors on Client
An open redirector is an endpoint using a parameter to automatically
redirect a user agent to the location specified by the parameter value
without any validation. If the authorization server allows the client
to register only part of the redirect URI, an attacker can use an open
redirector operated by the client to construct a redirect URI that
will pass the authorization server validation but will send the
authorization "code" or access token to an endpoint under the control
of the attacker.
Impact: An attacker could gain access to authorization "codes" or access tokens.
Countermeasures:
o Require clients to register full redirect URI (Section 5.2.3.5)."
Section 5.2.3.5 讨论了这可能过于严格的情况,并提出了替代解决方案。
通常,state
参数也可用于确定性地重定向,正如 Chris 所建议的那样。但是,您必须确保这样的解决方案最终也不会成为一个开放的重定向器,因此 state
参数要么需要受到保护(例如 encrypted/signed),要么与 cookie 一起使用。
为什么 redirect URL 必须完全匹配?域级别的匹配是否足以确保适当的安全性?
如果我有数百条路径怎么办?
示例网址:
- https://myawesomesite.com
- https://myawesomesite.com/account/profile
- https://myawesomesite.com/games/fungame/points
- https://www.myawesomesite.com/games/fungame/points
...
我必须在我的 B2C 应用程序配置中输入上述 4 个重定向网址。
所有身份验证请求通常(也是最简单的)包含两个重定向 URLs:
- 在"redirect_uri"参数中传递的一个(通常称为回复URL),必须 注册到 Azure AD B2C,所有 身份验证响应从 Azure AD B2C returned 到依赖方应用程序。例如
https://www.myawesomesite.com/oidc-signin
. - 另一个(通常称为returnURL)在"state"参数中进行往返,其中 不必 向 Azure AD B2C 注册,在依赖方应用程序处理身份验证响应后,最终用户将 return 注册到 Azure AD B2C。例如
https://www.myawesomesite.com/games/fungame/points
.
身份验证处理程序,例如 the ASP.NET Core authentication middleware,为您管理这些重定向 URL。
例如,当身份验证处理程序创建身份验证请求时,它会在 "state" 请求参数中对当前受保护的 URL(例如 https://www.myawesomesite.com/games/fungame/points
)进行编码。
为确保此 URL 不被篡改,应使用加密或签名保护 "state" 参数。
当身份验证处理程序处理身份验证响应时,假设它是一个成功的响应,它会创建一个身份 cookie 并将最终用户从 https://www.myawesomesite.com/oidc-signin
重定向到 [=] 中最初受保护的 URL 42=]响应参数。
这实际上在 RFC 6819 "OAuth 2.0 Threat Model and Security Considerations" sections 4.1.5, 4.2.4 and 5.2.3.5 中讨论过。
4.1.5. Threat: Open Redirectors on Client
An open redirector is an endpoint using a parameter to automatically redirect a user agent to the location specified by the parameter value without any validation. If the authorization server allows the client to register only part of the redirect URI, an attacker can use an open redirector operated by the client to construct a redirect URI that will pass the authorization server validation but will send the authorization "code" or access token to an endpoint under the control of the attacker.
Impact: An attacker could gain access to authorization "codes" or access tokens.
Countermeasures:
o Require clients to register full redirect URI (Section 5.2.3.5)."
Section 5.2.3.5 讨论了这可能过于严格的情况,并提出了替代解决方案。
通常,state
参数也可用于确定性地重定向,正如 Chris 所建议的那样。但是,您必须确保这样的解决方案最终也不会成为一个开放的重定向器,因此 state
参数要么需要受到保护(例如 encrypted/signed),要么与 cookie 一起使用。