-
Notifications
You must be signed in to change notification settings - Fork 10.3k
AddIdentityServerJwt might accidentally use the wrong issuer URL. #28880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for contacting us, @SebastianStehle. |
Thanks for contacting us. |
This is by design and matches what identity server itself does. If you have multiple host names you must select an canonical one by setting the Authority on the actual underlying identity server options. services.AddIdentityServer(options => options.IssuerUri = "https://localhost")
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>(); The JWT pieces should then use the identity server metadata to resolve the issuer. However what I'm seeing at that point is that the URL in the template for the metadata is wrong, and doesn't have the port number. As I'm not a react person, I can't help further, but it feels more like a template issue that identity itself. |
Thank your @blowdart for your answer. I also solved the problem with IssuerUri before writing this bug report. I think it is a very weird behavior. It first happened to me, when I had no health check at all, so I was not using a second host by purpose. So you actually make your server unusable by accident and it took my days to figure out what the problem is. If you think the behavior is okay there should be at least a warning. e.g. a Middleware that writes all the hosts to a hashset and logs a warning if 2 or more hosts are received. I had a similar problem a while ago in another project: https://github.com/squidex/squidex. A java client of a customer was using a library that always added the port number to the host header. So instead of adding If I check my logs I see a lot of requests to paths like |
To be fair this isn't us, this is Identity Server's behaviour, we're just not overriding it. Whilst I can't speak for Dom & Brock, when we make decisions like this, it's because customers want an f5 experience, where you can run a project immediately without having to think about configuration. As for bringing hosts down, I'd say maybe, but again it's something to take up with the identity server folks. We tend to lean towards saying not to listen on * and not to bind to IP addresses, but rather host names, and once you're thinking about host names, you tend to start thinking about configuration of everything more. Hopefully :) |
I don't see that this is a identity server behavior. The problem is the "caching" and that the options property is changed. If you would always use the You need to hook into this place:
I totally agree to the host name thing, but the question is: Who handles that. There are load balancers, requests and stuff like kubernetes wo make requests and manipulate the request and especially if your software is hosted in so many crazy ways you do not have full control over everything. |
I still don't understand how a behavior that can bring your system down without any warning can be by design. |
Doc/release note issue filed to track this for 6.0 #36676 |
Describe the bug
When using
AddIdentityServerJwt
the IssuerURL seems to be derived from the actual request. The option management hooks into the events and enriches the options with the host name from the request:aspnetcore/src/Identity/ApiAuthorization.IdentityServer/src/Authentication/IdentityServerJwtBearerOptionsConfiguration.cs
Line 63 in b795ac3
When the first request that comes in is not the public host name, the options is enriched with the wrong host and all subsequent calls to authorize fail because the issuer URL does not match.
Consider a scenario where you have a health check running. The health service uses the internal IP (e.g. in kubernetes) to call the health endpoint and the issuer URL is configured with the IP address.
To Reproduce
The result in Chrome:
Further technical details
The text was updated successfully, but these errors were encountered: