Skip to content

Commit f9b975c

Browse files
authored
Merge pull request #408 from DuendeSoftware/dh/code-scanning-alerts-plan
Encode logout id in WsFed remote-failure redirect
2 parents d836fef + 681e5ad commit f9b975c

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎IdentityServer/v7/UserInteraction/WsFederationDynamicProviders/IdentityServerHost/WsFed/WsFedConfigureOptions.cs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ protected override void Configure(ConfigureAuthenticationContext<WsFederationOpt
6666
ctx.Request.Path == ctx.Options.CallbackPath &&
6767
ctx.Request.Query.ContainsKey(identityServerOptions.UserInteraction.LogoutIdParameter))
6868
{
69-
ctx.Response.Redirect(identityServerOptions.UserInteraction.LogoutUrl + "?" + identityServerOptions.UserInteraction.LogoutIdParameter + "=" + ctx.Request.Query[identityServerOptions.UserInteraction.LogoutIdParameter]);
69+
// Redirect only to the local logout page; the logout id is URL-encoded so it cannot alter the target.
70+
var logoutId = ctx.Request.Query[identityServerOptions.UserInteraction.LogoutIdParameter].ToString();
71+
var query = QueryString.Create(identityServerOptions.UserInteraction.LogoutIdParameter, logoutId);
72+
ctx.Response.Redirect(identityServerOptions.UserInteraction.LogoutUrl + query.ToUriComponent());
7073
ctx.HandleResponse();
7174
}
7275

‎IdentityServer/v8/UserInteraction/WsFederationDynamicProviders/IdentityServerHost/WsFed/WsFedConfigureOptions.cs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ protected override void Configure(ConfigureAuthenticationContext<WsFederationOpt
6666
ctx.Request.Path == ctx.Options.CallbackPath &&
6767
ctx.Request.Query.ContainsKey(identityServerOptions.UserInteraction.LogoutIdParameter))
6868
{
69-
ctx.Response.Redirect(identityServerOptions.UserInteraction.LogoutUrl + "?" + identityServerOptions.UserInteraction.LogoutIdParameter + "=" + ctx.Request.Query[identityServerOptions.UserInteraction.LogoutIdParameter]);
69+
// Redirect only to the local logout page; the logout id is URL-encoded so it cannot alter the target.
70+
var logoutId = ctx.Request.Query[identityServerOptions.UserInteraction.LogoutIdParameter].ToString();
71+
var query = QueryString.Create(identityServerOptions.UserInteraction.LogoutIdParameter, logoutId);
72+
ctx.Response.Redirect(identityServerOptions.UserInteraction.LogoutUrl + query.ToUriComponent());
7073
ctx.HandleResponse();
7174
}
7275

0 commit comments

Comments
 (0)