Skip to content

Commit 8d57167

Browse files
committed
C#: Convert cs/missing-access-control to inline expectations test.
1 parent 53c4b29 commit 8d57167

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| ProfileController.cs:9:25:9:31 | Delete1 | This action is missing an authorization check. |
1+
| ProfileController.cs:10:25:10:31 | Delete1 | This action is missing an authorization check. |
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
Security Features/CWE-285/MissingAccessControl.ql
1+
query: Security Features/CWE-285/MissingAccessControl.ql
2+
postprocess:
3+
- utils/test/PrettyPrintModels.ql
4+
- utils/test/InlineExpectationsTestQuery.ql
Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
using Microsoft.AspNetCore.Mvc;
22
using Microsoft.AspNetCore.Authorization;
33

4-
public class ProfileController : Controller {
4+
public class ProfileController : Controller
5+
{
56
private void doThings() { }
67
private bool isAuthorized() { return false; }
78

89
// BAD: This is a Delete method, but no auth is specified.
9-
public ActionResult Delete1(int id) {
10+
public ActionResult Delete1(int id) // $ Alert
11+
{
1012
doThings();
1113
return View();
1214
}
1315

1416
// GOOD: isAuthorized is checked.
15-
public ActionResult Delete2(int id) {
16-
if (!isAuthorized()) {
17+
public ActionResult Delete2(int id)
18+
{
19+
if (!isAuthorized())
20+
{
1721
return null;
1822
}
1923
doThings();
@@ -22,35 +26,42 @@ public ActionResult Delete2(int id) {
2226

2327
// GOOD: The Authorize attribute is used.
2428
[Authorize]
25-
public ActionResult Delete3(int id) {
29+
public ActionResult Delete3(int id)
30+
{
2631
doThings();
2732
return View();
2833
}
2934

3035
}
3136

3237
[Authorize]
33-
public class AuthBaseController : Controller {
38+
public class AuthBaseController : Controller
39+
{
3440
protected void doThings() { }
3541
}
3642

37-
public class SubController : AuthBaseController {
43+
public class SubController : AuthBaseController
44+
{
3845
// GOOD: The Authorize attribute is used on the base class.
39-
public ActionResult Delete4(int id) {
46+
public ActionResult Delete4(int id)
47+
{
4048
doThings();
4149
return View();
4250
}
4351
}
4452

4553
[Authorize]
46-
public class AuthBaseGenericController<T> : Controller {
54+
public class AuthBaseGenericController<T> : Controller
55+
{
4756
protected void doThings() { }
4857
}
4958

50-
public class SubGenericController : AuthBaseGenericController<string> {
59+
public class SubGenericController : AuthBaseGenericController<string>
60+
{
5161
// GOOD: The Authorize attribute is used on the base class.
52-
public ActionResult Delete5(int id) {
62+
public ActionResult Delete5(int id)
63+
{
5364
doThings();
5465
return View();
5566
}
56-
}
67+
}

0 commit comments

Comments
 (0)