File tree Expand file tree Collapse file tree 4 files changed +27
-0
lines changed
csharp/ql/test/query-tests/Security Features/CWE-639/MVCTests Expand file tree Collapse file tree 4 files changed +27
-0
lines changed Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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. |
Original file line number Diff line number Diff line change
1
+ Security Features/CWE-639/InsecureDirectObjectReference.ql
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments