Skip to content

Commit 20d42df

Browse files
Add tests for webforms case
1 parent 2edd73e commit 20d42df

File tree

5 files changed

+32
-0
lines changed

5 files changed

+32
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.Web.UI;
3+
4+
class EditComment : System.Web.UI.Page {
5+
6+
// BAD - Any user can access this method.
7+
protected void btn1_Click(object sender, EventArgs e) {
8+
string commentId = Request.QueryString["Id"];
9+
Comment comment = getCommentById(commentId);
10+
comment.Text = "xyz";
11+
}
12+
13+
// GOOD - The user ID is verified.
14+
protected void btn2_Click(object sender, EventArgs e) {
15+
string commentId = Request.QueryString["Id"];
16+
Comment comment = getCommentById(commentId);
17+
if (comment.AuthorName == User.Identity.Name){
18+
comment.Text = "xyz";
19+
}
20+
}
21+
22+
class Comment {
23+
public string Text { get; set; }
24+
public string AuthorName { get; }
25+
}
26+
27+
Comment getCommentById(string id) { return null; }
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| EditComment.aspx.cs:7:20:7:29 | btn1_Click | This method may not verify which users should be able to access resources of the provided ID. |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Security Features/CWE-639/InsecureDirectObjectReference.ql
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle-extractor-options: /r:System.Collections.Specialized.dll ${testdir}/../../../../resources/stubs/System.Web.cs

csharp/ql/test/resources/stubs/System.Web.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public class Control
8282
public class Page
8383
{
8484
public System.Security.Principal.IPrincipal User { get; }
85+
public System.Web.HttpRequest Request { get; }
8586
}
8687

8788
interface IPostBackDataHandler

0 commit comments

Comments
 (0)