mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
Add test cases for authorization from attributes
This commit is contained in:
@@ -16,6 +16,21 @@ public class CommentController : Controller {
|
||||
return View();
|
||||
}
|
||||
|
||||
// GOOD: The Authorize attribute is used
|
||||
[Authorize]
|
||||
public ActionResult Edit3(int commentId, string text) {
|
||||
editComment(commentId, text);
|
||||
return View();
|
||||
}
|
||||
|
||||
// BAD: The AllowAnonymous attribute overrides the Authorize attribute
|
||||
[Authorize]
|
||||
[AllowAnonymous]
|
||||
public ActionResult Edit4(int commentId, string text) {
|
||||
editComment(commentId, text);
|
||||
return View();
|
||||
}
|
||||
|
||||
void editComment(int commentId, string text) { }
|
||||
|
||||
bool canEditComment(int commentId, string userName) { return false; }
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
| CommentController.cs:6:25:6:29 | Edit1 | This method may be missing authorization checks for which users can access the resource of the provided ID. |
|
||||
| CommentController.cs:29:25:29:29 | Edit4 | This method may be missing authorization checks for which users can access the resource of the provided ID. |
|
||||
| ProfileController.cs:14:25:14:29 | Edit2 | This method may be missing authorization checks for which users can access the resource of the provided ID. |
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
[Authorize]
|
||||
public class ProfileController : Controller {
|
||||
// GOOD: The Authorize attribute of the class restricts access to this method.
|
||||
public ActionResult Edit1(int profileId, string text) {
|
||||
editProfileName(profileId, text);
|
||||
return View();
|
||||
}
|
||||
|
||||
// BAD: The AllowAnonymous attribute therides the Authorize attribute on the class.
|
||||
[AllowAnonymous]
|
||||
public ActionResult Edit2(int profileId, string text) {
|
||||
editProfileName(profileId, text);
|
||||
return View();
|
||||
}
|
||||
|
||||
void editProfileName(int profileId, string text) { }
|
||||
}
|
||||
Reference in New Issue
Block a user