-
Notifications
You must be signed in to change notification settings - Fork 1.9k
C# CSRF query: add support for ASP.NET Core #20983
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
Merged
smowton
merged 2 commits into
github:main
from
smowton:smowton/feature/csharp-csrf-aspnetcore
Dec 8, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --- | ||
| category: minorAnalysis | ||
| --- | ||
| * The `Missing cross-site request forgery token validation` query was extended to support ASP.NET Core. |
31 changes: 31 additions & 0 deletions
31
...y-tests/Security Features/CWE-352/missing-aspnetcore/MissingAntiForgeryTokenValidation.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| using Microsoft.AspNetCore.Mvc; | ||
|
|
||
| public class HomeController : Controller | ||
| { | ||
| // BAD: Anti forgery token has been forgotten | ||
| [HttpPost] | ||
| public ActionResult Login() | ||
| { | ||
| return View(); | ||
| } | ||
|
|
||
| // GOOD: Anti forgery token is validated | ||
| [HttpPost] | ||
| [ValidateAntiForgeryToken] | ||
| public ActionResult UpdateDetails() | ||
| { | ||
| return View(); | ||
| } | ||
|
|
||
| // No validation required, as this is a GET method. | ||
| public ActionResult ShowHelp() | ||
| { | ||
| return View(); | ||
| } | ||
|
|
||
| // Should be ignored, because it is not an action method | ||
| [NonAction] | ||
| public void UtilityMethod() | ||
| { | ||
| } | ||
| } |
1 change: 1 addition & 0 deletions
1
...s/Security Features/CWE-352/missing-aspnetcore/MissingAntiForgeryTokenValidation.expected
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| | MissingAntiForgeryTokenValidation.cs:7:25:7:29 | Login | Method 'Login' handles a POST request without performing CSRF token validation. | |
1 change: 1 addition & 0 deletions
1
...ests/Security Features/CWE-352/missing-aspnetcore/MissingAntiForgeryTokenValidation.qlref
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| query: Security Features/CWE-352/MissingAntiForgeryTokenValidation.ql | ||
2 changes: 2 additions & 0 deletions
2
csharp/ql/test/query-tests/Security Features/CWE-352/missing-aspnetcore/options
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| semmle-extractor-options: /nostdlib /noconfig | ||
| semmle-extractor-options: --load-sources-from-project:${testdir}/../../../../resources/stubs/_frameworks/Microsoft.AspNetCore.App/Microsoft.AspNetCore.App.csproj |
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.
Check warning
Code scanning / CodeQL
Query test without inline test expectations Warning test