-
Notifications
You must be signed in to change notification settings - Fork 10.3k
HttpsRedirectionMiddleware unsafe fallback behavior when app is misconfigured #27951
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
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
Yes, the code comment is outdated and should be corrected. The default behavior during the initial development was to throw but that caused significant usability issues for apps that didn't have https enabled at all. I think we can split this conversation into three scenarios:
When we talked offline you mentioned that you were lucky not to require this (3), you were able to select one of your https ports and ignore the other one. Any improvements here would not be to unblock you, but to prevent the unwary from stumbling into the same issue. |
Thanks for contacting us. |
Triage: Let's try throwing a runtime error when there are multiple https endpoints. To resolve the ambiguity the developer can explicitly set the port (if there's only one valid port) or we can implement #21291 for more complex mappings. |
@Tratcher +1, your proposal is reasonable and fully addresses my concern. |
Describe the bug
Applications that explicitly include
app.UseHttpsRedirection()
to their pipeline should (reasonably) expect that anything beyond that point would be HTTPS only, and may make security assumptions based on that expected fact.However, the implementation of
HttpsRedirectionMiddleware
in ASP .NET Core 3.1, as well as latest master, have an unsafe, unreasonable and unexpected fallback when the application is misconfigured and the middleware is unable to determine the target HTTPS port. Seeaspnetcore/src/Middleware/HttpsPolicy/src/HttpsRedirectionMiddleware.cs
Lines 89 to 92 in 5747cb3
Ideally, misconfiguration that triggers that condition should be detected at startup -- fail fast, making it trivial for someone to analyze and fix a potential vulnerability.
Failing that, the condition should be detected at runtime, causing the pipeline to abort (
throw new InvalidOperationException(...)
of some kind).However, ASP .NET Core today simply skips HTTPS redirection, allowing the request to proceed over an insecure HTTP channel**. This is a significant issue and may lead to inadvertent transmission of sensitive data that can be easily intercepted.
Under no circumstances should the framework allow an insecure request to proceed when the app explicitly added a step to enforce HTTPS to their pipeline. This is a an unreasonable and unsafe fallback that puts entire applications at risk.
Example scenario where this can be particularly problematic -- a seemingly innocuous change to add a second HTTPS listener address on Kestrel means that, all of a sudden, the
HttpsRedirectionMiddleware
is no longer able to determine a single HTTPS target port, making an entire application insecure just because a new endpoint was added. This behavior violates the Principle of Least Astonishment.To Reproduce
http://localhost:80
,https://localhost:443
,https://localhost:444
app.UseHttpsRedirection()
early in its pipeline, without any additional custom configurationhttp://localhost:80
Relevant source:
aspnetcore/src/Middleware/HttpsPolicy/src/HttpsRedirectionMiddleware.cs
Lines 149 to 154 in 5747cb3
Notice the comment says
If we find multiple different https ports specified, throw
, yet the actual code does not throw, and instead proceeds.Exceptions (if any)
N/A
Further technical details
The text was updated successfully, but these errors were encountered: