Skip to content

Commit f8b1b38

Browse files
Update alert message and make user checks more precise
1 parent 009a7bf commit f8b1b38

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

csharp/ql/lib/semmle/code/csharp/security/auth/InsecureDirectObjectReferenceQuery.qll

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ private predicate hasIdParameter(ActionMethod m) {
2222
exists(RemoteFlowSource src | src.getEnclosingCallable() = m |
2323
src.asParameter().getName().toLowerCase().matches(["%id", "%idx"])
2424
or
25+
// handle cases like `Request.QueryString["Id"]`
2526
exists(StringLiteral idStr |
2627
idStr.getValue().toLowerCase().matches(["%id", "%idx"]) and
2728
getParentExpr*(src.asExpr()) = getParentExpr*(idStr)
@@ -31,8 +32,10 @@ private predicate hasIdParameter(ActionMethod m) {
3132

3233
/** Holds if `m` at some point in its call graph may make some kind of check against the current user. */
3334
private predicate checksUser(ActionMethod m) {
34-
exists(Property p | p.getName().toLowerCase().matches(["%user%", "%session%"]) |
35-
m.calls*(p.getGetter())
35+
exists(Callable c, string name | name = c.getName().toLowerCase() |
36+
name.matches(["%user%", "%session%"]) and
37+
not name.matches("%get%by%") and // methods like `getUserById` or `getXByUsername` aren't likely to be referring to the current user
38+
m.calls*(c)
3639
)
3740
}
3841

csharp/ql/src/Security Features/CWE-639/InsecureDirectObjectReference.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ import semmle.code.csharp.security.auth.InsecureDirectObjectReferenceQuery
1717
from ActionMethod m
1818
where hasInsecureDirectObjectReference(m)
1919
select m,
20-
"This method may not verify which users should be able to access resources of the provided ID."
20+
"This method may be missing authorization checks for which users can access the resource of the provided ID."
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +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. |
1+
| 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. |
Original file line numberDiff line numberDiff line change
@@ -1 +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. |
1+
| EditComment.aspx.cs:7:20:7:29 | btn1_Click | This method may be missing authorization checks for which users can access the resource of the provided ID. |

0 commit comments

Comments
 (0)