mirror of
https://github.com/github/codeql.git
synced 2026-05-05 21:55:19 +02:00
Add an additional example and additional test cases for authorize attribute cases
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
| 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. |
|
||||
| MiscTestControllers.cs:26:33:26:40 | EditAnon | This method may be missing authorization checks for which users can access the resource of the provided ID. |
|
||||
| MiscTestControllers.cs:34:34:34:41 | EditAnon | This method may be missing authorization checks for which users can access the resource of the provided ID. |
|
||||
| MiscTestControllers.cs:45:25:45: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,46 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
public class BaseController : Controller {
|
||||
// GOOD
|
||||
[Authorize]
|
||||
public virtual ActionResult Edit1(int id) { return View(); }
|
||||
}
|
||||
|
||||
class MyAuthorizeAttribute : AuthorizeAttribute { }
|
||||
class MyAllowAnonymousAttribute : AllowAnonymousAttribute { }
|
||||
|
||||
public class AController : BaseController {
|
||||
// GOOD - Authorize is inherited from overridden method
|
||||
public override ActionResult Edit1(int id) { return View(); }
|
||||
|
||||
// GOOD - A subclass of Authorize is used
|
||||
[MyAuthorize]
|
||||
public ActionResult Edit2(int id) { return View(); }
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public class BaseAuthController : Controller {
|
||||
// BAD - A subclass of AllowAnonymous is used
|
||||
[MyAllowAnonymous]
|
||||
public virtual ActionResult EditAnon(int id) { return View(); }
|
||||
}
|
||||
|
||||
public class BController : BaseAuthController {
|
||||
// GOOD - Authorize is inherited from parent class
|
||||
public ActionResult Edit3(int id) { return View(); }
|
||||
|
||||
// BAD - MyAllowAnonymous is inherited from overridden method
|
||||
public override ActionResult EditAnon(int id) { return View(); }
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
public class BaseAnonController : Controller {
|
||||
|
||||
}
|
||||
|
||||
public class CController : BaseAnonController {
|
||||
// BAD - AllowAnonymous is inherited from base class and overrides Authorize
|
||||
[Authorize]
|
||||
public ActionResult Edit4(int id) { return View(); }
|
||||
}
|
||||
Reference in New Issue
Block a user