Throw when UseAuthorization is incorrectly configured#14401
Throw when UseAuthorization is incorrectly configured#14401mkArtakMSFT merged 1 commit intorelease/3.1-preview1from
Conversation
13f482e to
479c8a9
Compare
|
|
||
| var endpoint = context.GetEndpoint(); | ||
|
|
||
| if (endpoint != null) |
There was a problem hiding this comment.
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.
Rename key/value to indicate this is endpoint specific.
There was a problem hiding this comment.
Do you have any suggestions?
There was a problem hiding this comment.
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.
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.
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.
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.
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.
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()); | ||
|
|
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