Skip to content

Commit 009a7bf

Browse files
Add MVC tests
1 parent 20d42df commit 009a7bf

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using Microsoft.AspNetCore.Authorization;
3+
4+
public class CommentController : Controller {
5+
// BAD: Any user can access this.
6+
public ActionResult Edit1(int commentId, string text) {
7+
editComment(commentId, text);
8+
return View();
9+
}
10+
11+
// GOOD: The user's authorization is checked.
12+
public ActionResult Edit2(int commentId, string text) {
13+
if (canEditComment(commentId, User.Identity.Name)){
14+
editComment(commentId, text);
15+
}
16+
return View();
17+
}
18+
19+
void editComment(int commentId, string text) { }
20+
21+
bool canEditComment(int commentId, string userName) { return false; }
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| CommentController.cs:6:25:6:29 | Edit1 | This method may not verify which users should be able to access resources of the provided ID. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Security Features/CWE-639/InsecureDirectObjectReference.ql
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
semmle-extractor-options: /nostdlib /noconfig
2+
semmle-extractor-options: --load-sources-from-project:${testdir}/../../../../resources/stubs/_frameworks/Microsoft.NETCore.App/Microsoft.NETCore.App.csproj
3+
semmle-extractor-options: --load-sources-from-project:${testdir}/../../../../resources/stubs/_frameworks/Microsoft.AspNetCore.App/Microsoft.AspNetCore.App.csproj

0 commit comments

Comments
 (0)