Azure AD B2C 易受开放重定向攻击?

Azure AD B2C vulnerable to Open Redirect?

我正在使用 OWIN 和 OpenId 通过 Azure AD B2C 对我的 Web 应用程序的用户进行身份验证,Startup.Auth.cs 的代码如下:

app.UseOpenIdConnectAuthentication(
            new OpenIdConnectAuthenticationOptions
            {
                 MetadataAddress = string.Format(AadInstance, Tenant, policy),
                AuthenticationType = policy,
                ClientId = clientId,
                Authority = authority,
                PostLogoutRedirectUri = postLogoutRedirectUri,
                RedirectUri = postLogoutRedirectUri,
                Notifications = new OpenIdConnectAuthenticationNotifica....

注销时,它会导致重定向到 postLogoutRedirectUrl,就像这样

https://login.microsoftonline.com/MY_TENANT/oauth2/logout?p=my_policy&post_logout_redirect_uri=https%3A%2F%2Fgoogle.com%2F

门户中的重定向 URI 中存在 post 注销重定向 URI。

如果我停止浏览器并将地址栏中的 post 注销 uri 更改为 https%3A%2F%2Fevil.com%2F,即使 url https://evil.com/ 不在允许的重定向 uri 中。

为什么 AD B2C 不停止重定向?这不是对漏洞开放吗?

当您使用 Azure AD B2C 登录时,B2C 服务会向 "redirect_uri"(应用程序)发送一个令牌。由于令牌需要保持安全,B2C 服务要求您将 URL 的令牌发送到的白名单。

当您注销时,没有任何安全信息从 B2C 服务传输回应用程序。因此,即使用户被重定向到恶意站点,也不会丢失任何安全信息。

您可以更改此行为以强制 Azure AD B2C 仅在有效 ID 令牌作为注销请求中的参数传入时才处理注销重定向。要让 B2C 自动包含 ID 令牌并检查其是否存在,只需在 Azure 门户中编辑您的登录/注册策略,即:

或者,如果您使用自定义策略,您可以将 SingleSignOn 元素添加到 UserJourneyBehaviors 部分,并将 EnforceIdTokenHintOnLogout 设置为 true,即:

<UserJourneyBehaviors>
     <SingleSignOn Scope="Tenant" EnforceIdTokenHintOnLogout="true" />

</UserJourneyBehaviors>