A web service is running a very old version of Sitecore, with IdentityServer3 and no custom configuration. It's not possible to upgrade to a more recent version of Identity Server.
/identity/postexternallogout?ReturnUrl=<any URL here> acts as an open-URL redirect, with no validation at all! How can IdentityServer 3 be configured to avoid this vulnerability?
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Short version: IdentityServer3 doesn’t have a built-in switch to validate ReturnUrl on /postexternallogout. To close the open-redirect, you need to intercept that request and enforce “local-only” return URLs (or block the endpoint entirely if you don’t use external IdPs).
Here are safe, practical ways to do it without upgrading IdentityServer:
If you don’t use external identity providers: block the endpoint
E.g., IIS URL Rewrite rule to 404 /identity/postexternallogout.
If you do use external identity providers: validate ReturnUrl before IdSrv sees it
Add a tiny OWIN middleware before app.UseIdentityServer() that allows only relative, same-site ReturnUrls.
OWIN middleware example (place this before UseIdentityServer):
// in Startup.Configuration(IAppBuilder app)
app.Use(async (ctx, next) =>
{
if (ctx.Request.Path.Equals(new PathString("/identity/postexternallogout"), StringComparison.OrdinalIgnoreCase))
{
var returnUrl = ctx.Request.Query.Get("ReturnUrl");
code
if (!IsSafeLocalUrl(returnUrl))
{
ctx.Response.StatusCode = 400; // or redirect to a safe default within your site
await ctx.Response.WriteAsync("Invalid ReturnUrl");
return;
}
}
await next();
});
static bool IsSafeLocalUrl(string url)
{
if (string.IsNullOrWhiteSpace(url)) return true; // allow empty
if (Uri.TryCreate(url, UriKind.Absolute, out _)) return false; // reject absolute URLs
if (!url.StartsWith("/", StringComparison.Ordinal)) return false; // must start with /
if (url.StartsWith("//", StringComparison.Ordinal)) return false; // reject scheme-relative
// optionally tighten further:
// return url.StartsWith("/identity/", StringComparison.Ordinal);
return true;
}
IIS URL Rewrite example (front-door mitigation):
Notes:
This endpoint should only ever need to redirect to a local path as part of the legit sign-out flow. Enforcing “relative-only” won’t break the normal flow.
Whitelisting specific local paths (e.g., only /identity/logout and friends) is even safer if you can.
Client post-logout redirect URIs (the OIDC end_session parameter) are a different thing; tightening those won’t fix this particular open-redirect.
Bottom line: there’s no IdSrv3 config flag to fix this; add a small pre-IdentityServer check (or block the route entirely) to ensure ReturnUrl is local-only.