mirror of
https://github.com/github/codeql.git
synced 2026-05-05 21:55:19 +02:00
C#: Remove splitting-awareness for taint steps.
This commit is contained in:
@@ -45,82 +45,58 @@ predicate defaultImplicitTaintRead(DataFlow::Node node, DataFlow::ContentSet c)
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private class LocalTaintExprStepConfiguration extends ControlFlowReachabilityConfiguration {
|
private predicate localTaintExprStep(Expr e1, Expr e2) {
|
||||||
LocalTaintExprStepConfiguration() { this = "LocalTaintExprStepConfiguration" }
|
e1 = e2.(ElementAccess).getQualifier()
|
||||||
|
or
|
||||||
override predicate candidate(
|
e1 = e2.(AddExpr).getAnOperand()
|
||||||
Expr e1, Expr e2, ControlFlowElement scope, boolean exactScope, boolean isSuccessor
|
or
|
||||||
) {
|
// A comparison expression where taint can flow from one of the
|
||||||
exactScope = false and
|
// operands if the other operand is a constant value.
|
||||||
isSuccessor = true and
|
exists(ComparisonTest ct, Expr other |
|
||||||
(
|
ct.getExpr() = e2 and
|
||||||
e1 = e2.(ElementAccess).getQualifier() and
|
e1 = ct.getAnArgument() and
|
||||||
scope = e2
|
other = ct.getAnArgument() and
|
||||||
or
|
other.stripCasts().hasValue() and
|
||||||
e1 = e2.(AddExpr).getAnOperand() and
|
e1 != other
|
||||||
scope = e2
|
|
||||||
or
|
|
||||||
// A comparison expression where taint can flow from one of the
|
|
||||||
// operands if the other operand is a constant value.
|
|
||||||
exists(ComparisonTest ct, Expr other |
|
|
||||||
ct.getExpr() = e2 and
|
|
||||||
e1 = ct.getAnArgument() and
|
|
||||||
other = ct.getAnArgument() and
|
|
||||||
other.stripCasts().hasValue() and
|
|
||||||
e1 != other and
|
|
||||||
scope = e2
|
|
||||||
)
|
|
||||||
or
|
|
||||||
e1 = e2.(UnaryLogicalOperation).getAnOperand() and
|
|
||||||
scope = e2
|
|
||||||
or
|
|
||||||
e1 = e2.(BinaryLogicalOperation).getAnOperand() and
|
|
||||||
scope = e2
|
|
||||||
or
|
|
||||||
e1 = e2.(InterpolatedStringExpr).getAChild() and
|
|
||||||
scope = e2
|
|
||||||
or
|
|
||||||
e1 = e2.(InterpolatedStringInsertExpr).getInsert() and
|
|
||||||
scope = e2
|
|
||||||
or
|
|
||||||
e2 =
|
|
||||||
any(OperatorCall oc |
|
|
||||||
oc.getTarget().(ConversionOperator).fromLibrary() and
|
|
||||||
e1 = oc.getAnArgument() and
|
|
||||||
scope = e2
|
|
||||||
)
|
|
||||||
or
|
|
||||||
e1 = e2.(AwaitExpr).getExpr() and
|
|
||||||
scope = e2
|
|
||||||
or
|
|
||||||
// Taint flows from the operand of a cast to the cast expression if the cast is to an interpolated string handler.
|
|
||||||
e2 =
|
|
||||||
any(CastExpr ce |
|
|
||||||
e1 = ce.getExpr() and
|
|
||||||
scope = ce and
|
|
||||||
ce.getTargetType()
|
|
||||||
.(Attributable)
|
|
||||||
.getAnAttribute()
|
|
||||||
.getType()
|
|
||||||
.hasFullyQualifiedName("System.Runtime.CompilerServices",
|
|
||||||
"InterpolatedStringHandlerAttribute")
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private ControlFlow::Nodes::ExprNode getALastEvalNode(ControlFlow::Nodes::ExprNode cfn) {
|
|
||||||
exists(OperatorCall oc | any(LocalTaintExprStepConfiguration x).hasExprPath(_, result, oc, cfn) |
|
|
||||||
oc.getTarget() instanceof ImplicitConversionOperator
|
|
||||||
)
|
)
|
||||||
|
or
|
||||||
|
e1 = e2.(UnaryLogicalOperation).getAnOperand()
|
||||||
|
or
|
||||||
|
e1 = e2.(BinaryLogicalOperation).getAnOperand()
|
||||||
|
or
|
||||||
|
e1 = e2.(InterpolatedStringExpr).getAChild()
|
||||||
|
or
|
||||||
|
e1 = e2.(InterpolatedStringInsertExpr).getInsert()
|
||||||
|
or
|
||||||
|
e2 =
|
||||||
|
any(OperatorCall oc |
|
||||||
|
oc.getTarget().(ConversionOperator).fromLibrary() and
|
||||||
|
e1 = oc.getAnArgument()
|
||||||
|
)
|
||||||
|
or
|
||||||
|
e1 = e2.(AwaitExpr).getExpr()
|
||||||
|
or
|
||||||
|
// Taint flows from the operand of a cast to the cast expression if the cast is to an interpolated string handler.
|
||||||
|
e2 =
|
||||||
|
any(CastExpr ce |
|
||||||
|
e1 = ce.getExpr() and
|
||||||
|
ce.getTargetType()
|
||||||
|
.(Attributable)
|
||||||
|
.getAnAttribute()
|
||||||
|
.getType()
|
||||||
|
.hasFullyQualifiedName("System.Runtime.CompilerServices",
|
||||||
|
"InterpolatedStringHandlerAttribute")
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private ControlFlow::Nodes::ExprNode getPostUpdateReverseStep(ControlFlow::Nodes::ExprNode e) {
|
private Expr getALastEvalNode(OperatorCall oc) {
|
||||||
result = getALastEvalNode(e)
|
localTaintExprStep(result, oc) and oc.getTarget() instanceof ImplicitConversionOperator
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Expr getPostUpdateReverseStep(Expr e) { result = getALastEvalNode(e) }
|
||||||
|
|
||||||
private predicate localTaintStepCommon(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
|
private predicate localTaintStepCommon(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
|
||||||
hasNodePath(any(LocalTaintExprStepConfiguration x), nodeFrom, nodeTo)
|
localTaintExprStep(nodeFrom.asExpr(), nodeTo.asExpr())
|
||||||
}
|
}
|
||||||
|
|
||||||
cached
|
cached
|
||||||
@@ -191,12 +167,8 @@ private module Cached {
|
|||||||
// Allow reverse update flow for implicit conversion operator calls.
|
// Allow reverse update flow for implicit conversion operator calls.
|
||||||
// This is needed to support flow out of method call arguments, where an implicit conversion is applied
|
// This is needed to support flow out of method call arguments, where an implicit conversion is applied
|
||||||
// to a call argument.
|
// to a call argument.
|
||||||
nodeTo.(PostUpdateNode).getPreUpdateNode().(DataFlow::ExprNode).getControlFlowNode() =
|
nodeTo.(PostUpdateNode).getPreUpdateNode().asExpr() =
|
||||||
getPostUpdateReverseStep(nodeFrom
|
getPostUpdateReverseStep(nodeFrom.(PostUpdateNode).getPreUpdateNode().asExpr())
|
||||||
.(PostUpdateNode)
|
|
||||||
.getPreUpdateNode()
|
|
||||||
.(DataFlow::ExprNode)
|
|
||||||
.getControlFlowNode())
|
|
||||||
) and
|
) and
|
||||||
model = ""
|
model = ""
|
||||||
or
|
or
|
||||||
|
|||||||
Reference in New Issue
Block a user