Skip to content

Commit 6d704be

Browse files
Rewrite checks for index expressions in terms of dataflow
1 parent a2dce6b commit 6d704be

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import csharp
44
import semmle.code.csharp.dataflow.flowsources.Remote
5+
import DataFlow as DF
6+
import TaintTracking as TT
57
import ActionMethods
68

79
/**
@@ -12,8 +14,6 @@ import ActionMethods
1214
// Other queries check that there are authorization checks in place for admin methods.
1315
private predicate needsChecks(ActionMethod m) { m.isEdit() and not m.isAdmin() }
1416

15-
private Expr getParentExpr(Expr ex) { result.getAChildExpr() = ex }
16-
1717
/**
1818
* Holds if `m` has a parameter or access a remote flow source
1919
* that may indicate that it's used as the ID for some resource
@@ -23,9 +23,10 @@ private predicate hasIdParameter(ActionMethod m) {
2323
src.asParameter().getName().toLowerCase().matches(["%id", "%idx"])
2424
or
2525
// handle cases like `Request.QueryString["Id"]`
26-
exists(StringLiteral idStr |
26+
exists(StringLiteral idStr, IndexerCall idx |
2727
idStr.getValue().toLowerCase().matches(["%id", "%idx"]) and
28-
getParentExpr*(src.asExpr()) = getParentExpr*(idStr)
28+
TT::localTaint(src, DataFlow::exprNode(idx.getQualifier())) and
29+
DF::localExprFlow(idStr, idx.getArgument(0))
2930
)
3031
)
3132
}

0 commit comments

Comments
 (0)