Repository navigation
Fix authz metadata guard consistency - #67742
Merged
cincuranet merged 7 commits intoJul 22, 2026
Merged
Conversation
…unhandled-security-metadata guard
…nhandled-security-metadata guards
…rt-circuit guards
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens the routing “unhandled authorization metadata” guards so they detect all authorization metadata shapes that AuthorizationMiddleware can process, improving consistency and defense-in-depth for endpoints that would otherwise silently skip auth policy evaluation.
Changes:
- Introduced
AuthorizationMetadataHelper.HasAuthorizationMetadata(Endpoint)to detectIAuthorizeData,AuthorizationPolicy, andIAuthorizationRequirementData. - Updated both guard sites (
EndpointRoutingMiddleware.ExecuteShortCircuitandEndpointMiddleware.Invoke) to use the shared helper. - Added unit tests to cover
AuthorizationPolicy-only andIAuthorizationRequirementData-only metadata scenarios at both guard sites.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Http/Routing/src/AuthorizationMetadataHelper.cs | Adds a shared internal helper to detect all authorization metadata shapes used by AuthorizationMiddleware. |
| src/Http/Routing/src/EndpointRoutingMiddleware.cs | Uses the shared helper when validating short-circuit endpoints for unhandled authorization metadata. |
| src/Http/Routing/src/EndpointMiddleware.cs | Uses the shared helper when validating endpoints for missing authorization middleware invocation. |
| src/Http/Routing/test/UnitTests/EndpointRoutingMiddlewareTest.cs | Adds short-circuit guard tests for AuthorizationPolicy-only and IAuthorizationRequirementData-only endpoints (currently missing required using/qualification). |
| src/Http/Routing/test/UnitTests/EndpointMiddlewareTest.cs | Adds missing-auth-middleware guard tests for AuthorizationPolicy-only and IAuthorizationRequirementData-only endpoints. |
…intRoutingMiddlewareTest
….com/GrantTotinov/aspnetcore into fix-authz-metadata-guard-consistency
Contributor
Author
|
@halter73 The failing checks (Helix Subset 1, components-e2e) don't seem related to this change based on what I can see, but let me know if I'm missing something. Happy to make any adjustments needed. Thanks! |
Member
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). 2 pipeline(s) were filtered out due to trigger conditions. |
github-actions Bot
added a commit
that referenced
this pull request
Jul 25, 2026
…rMode_Top_AppendKeepsViewportStable The test has shown intermittent failures in CI across multiple builds against unrelated PRs (#67742, #67929). Associated issue: #aw_qgridtop Co-authored-by: Copilot <[email protected]>
ilonatommy
pushed a commit
that referenced
this pull request
Jul 27, 2026
…rMode_Top_AppendKeepsViewportStable (#68018) The test has shown intermittent failures in CI across multiple builds against unrelated PRs (#67742, #67929). Associated issue: #68017 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix unhandled-security-metadata guard to cover AuthorizationPolicy and IAuthorizationRequirementData
Fix unhandled-security-metadata guard to cover AuthorizationPolicy and IAuthorizationRequirementData
Description
Routing has a defensive guard that throws
InvalidOperationExceptionwhen an endpoint carries authorization metadata that would otherwise not be processed — once inEndpointRoutingMiddleware.ExecuteShortCircuit(short-circuited endpoints) and once inEndpointMiddleware.Invoke(when the authorization middleware didn't run).AuthorizationMiddlewarebuilds its effective policy from three metadata shapes:IAuthorizeDataAuthorizationPolicyIAuthorizationRequirementDataBoth guard checks only looked for
IAuthorizeData. As a result, for endpoints configured with anAuthorizationPolicyor anIAuthorizationRequirementData-only attribute (without anyIAuthorizeData), the intended fail-fast validation did not fire, and the guard silently under-reported. This was a consistency / defense-in-depth gap, not a change in documented behavior for[Authorize]/RequireAuthorization.Changes
AuthorizationMetadataHelper.HasAuthorizationMetadata(Endpoint), that checks all three metadata shapes:IAuthorizeDatachecks at both guard sites with calls to this shared helper, keeping them in sync withAuthorizationMiddlewareas the existing "kept in sync" comments intend.AuthorizationMiddlewareInvokedKeycondition inEndpointMiddleware— only the metadata-detection part was extracted, not the overall guard logic.Microsoft.AspNetCore.Authorization.[Authorize]/RequireAuthorizationis unchanged.Testing
Added tests covering
AuthorizationPolicy-only andIAuthorizationRequirementData-only endpoints at both guard sites:EndpointMiddlewareTest.cs— verifiesInvokethrows when the authorization middleware wasn't invoked and the endpoint carries onlyAuthorizationPolicyor onlyIAuthorizationRequirementDatametadata.EndpointRoutingMiddlewareTest.cs— verifiesExecuteShortCircuitthrows when a short-circuited endpoint carries onlyAuthorizationPolicyor onlyIAuthorizationRequirementDatametadata.Fixes #67559