C#: Relax condition for authorize attributes on cs/web/missing-function-level-access-control.#19302
Merged
michaelnebel merged 5 commits intogithub:mainfrom Apr 23, 2025
Conversation
…attribute that has an authorization like name.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR relaxes the authorization conditions in the missing-function-level-access-control query and enhances test coverage around authorization attributes.
- Introduces a new RequirePermissionAttribute (extending AuthorizeAttribute) for testing inheritance-based authorization
- Reformats several controller action methods to improve clarity in the test cases
- Updates the change note to document improved detection of authorization checks
Reviewed Changes
Copilot reviewed 2 out of 5 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| csharp/ql/test/query-tests/Security Features/CWE-285/MissingAccessControl/MVCTests/ProfileController.cs | Updated test controllers with various authorization scenarios, including the new RequirePermissionAttribute |
| csharp/ql/src/change-notes/2025-04-15-missing-function-level-access-control.md | Added change note documenting enhanced query detection for authorization checks |
Files not reviewed (3)
- csharp/ql/lib/semmle/code/csharp/security/auth/MissingFunctionLevelAccessControlQuery.qll: Language not supported
- csharp/ql/test/query-tests/Security Features/CWE-285/MissingAccessControl/MVCTests/MissingAccessControl.expected: Language not supported
- csharp/ql/test/query-tests/Security Features/CWE-285/MissingAccessControl/MVCTests/MissingAccessControl.qlref: Language not supported
Comments suppressed due to low confidence (2)
csharp/ql/test/query-tests/Security Features/CWE-285/MissingAccessControl/MVCTests/ProfileController.cs:12
- [nitpick] The '// $ Alert' marker is used to indicate a test case for missing authorization; consider adding a brief comment explaining its purpose to avoid confusion for new readers.
public ActionResult Delete1(int id) // $ Alert
csharp/ql/test/query-tests/Security Features/CWE-285/MissingAccessControl/MVCTests/ProfileController.cs:23
- Using 'return null;' in an action method may cause unexpected behavior; consider returning a proper ActionResult (e.g., a ForbiddenResult) if this branch is meant to simulate unauthorized access.
return null;
hvitved
approved these changes
Apr 23, 2025
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.
The change note was made mostly using CoPilot chat.
With the right context (the query, query module and another change note) it produced reasonable output.
DCA is uneventful.