-
-
Notifications
You must be signed in to change notification settings - Fork 799
Add Analyzer for Microsoft.AspNetCore.Authorization attribute usage on GraphQL members #8869
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
5a32df7 to
8913986
Compare
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.
Pull Request Overview
This PR adds a new analyzer to detect and prevent the use of Microsoft's ASP.NET Core authorization attributes (Microsoft.AspNetCore.Authorization.AuthorizeAttribute and AllowAnonymousAttribute) in HotChocolate GraphQL types. It enforces the use of HotChocolate's own authorization attributes instead.
Key Changes:
- New analyzer (
WrongAuthorizationAttributeAnalyzer) that reports errors when Microsoft authorization attributes are used on GraphQL types, root types, or their members - Code fix provider that automatically replaces Microsoft attributes with HotChocolate equivalents, including transformation of the
Rolesparameter from string to collection expression - Comprehensive test coverage with 15 test cases covering various scenarios
Reviewed Changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| WrongAuthorizationAttributeAnalyzer.cs | Implements the diagnostic analyzer to detect Microsoft authorization attributes on GraphQL types and members |
| WrongAuthorizationAttributeCodeFixProvider.cs | Provides automatic code fixes to replace Microsoft attributes with HotChocolate equivalents |
| Errors.cs | Adds the diagnostic descriptor HC0106 for the wrong authorization attribute error |
| WrongAuthorizationAttributeAnalyzerTests.cs | Contains test cases for both error and no-error scenarios |
| TestHelper.cs | Updated to include required assembly references and register the new analyzer |
| 15 snapshot files | Expected test output snapshots showing generated code and analyzer diagnostics |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
🚀 Performance Test Results📊 Response TimeCurrent
Baseline
Change vs Baseline
⚡ Throughput
🎯 Reliability
🔍 Analysis✅ No significant performance regression detected Run 19083356710 • Commit 9b419ea • Tue, 04 Nov 2025 21:45:05 GMT |
8913986 to
d25869a
Compare
🚀 Performance Test Results📊 Response TimeCurrent
Baseline
Change vs Baseline
⚡ Throughput
🎯 Reliability
🔍 Analysis✅ No significant performance regression detected Run 19094534550 • Commit e6014f0 • Wed, 05 Nov 2025 07:43:51 GMT |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8869 +/- ##
============================
============================
☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Fixes #7688
Supersedes #7696
Rolesto a collection if necessary