mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
C# CSRF query: add support for ASP.NET Core
This commit is contained in:
@@ -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()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
| MissingAntiForgeryTokenValidation.cs:7:25:7:29 | Login | Method 'Login' handles a POST request without performing CSRF token validation. |
|
||||
@@ -0,0 +1 @@
|
||||
query: Security Features/CWE-352/MissingAntiForgeryTokenValidation.ql
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user