-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Throw when UseAuthorization is incorrectly configured #14401
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
Conversation
13f482e
to
479c8a9
Compare
var endpoint = context.GetEndpoint(); | ||
|
||
if (endpoint != null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment about why the flag is only set if an endpoint is present
// Flag to indicate to the system that the middleware was run in the context of endpoint routing. | ||
// Setting this flag allows a check in EndpointRoutingMiddleware that verifies if the middleware | ||
// pipeline is wired correctly to succeed. | ||
context.Items[AuthorizationMiddlewareInvokedKey] = AuthorizationMiddlewareInvokedValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename key/value to indicate this is endpoint specific.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have any suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EndpointAuthInvoked?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AuthorizationInvokedWithEndpointsKey?
bf3e9ab
to
63ac5f0
Compare
🆙 📅 |
@aspnet/build what's up with this error:
|
|
||
var type = (INamedTypeSymbol)context.Symbol; | ||
|
||
foreach (var middlewareAnalysis in _context.GetRelatedAnalyses<MiddlewareAnalysis>(type)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
YSK: this doesn't do control-flow analysis - ie, it's trivial to cause false positives or false negatives when .Map
is involved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. We can always recommend turning the analyzer for users where this becomes problematic. Doing flow analysis for this sounds like a lot more effort
{ | ||
// This sort of setup would be useful if the user wants to use Auth for non-endpoint content to be handled using the Fallback policy, while | ||
// using the second instance for regular endpoint routing based auth. We do not want to produce a warning in this case. | ||
app.UseAuthorization(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't super get this - it only makes sense if there's a terminal middleware between here and routing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll toss in a Static files to appear after this.
public void Configure(IApplicationBuilder app) | ||
{ | ||
app.UseRouting(); | ||
app.UseAuthorization(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File is called UseAuthMultipleTimes
- yet it uses auth a single time. How can this be possible?
{ | ||
app.UseRouting(); | ||
app.UseEndpoints(b => b.Map("/", TestDelegate).RequireAuthorization()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3a587df
to
219827c
Compare
* Update AuthZ & Cors middlewares to only set endpoint routing metadata when executing in the context of endpoint routing * Add analyzers for incorrect UseAuth use Fixes #14049
219827c
to
5256b76
Compare
executing in the context of endpoint routing
Fixes #14049