Skip to content

Commit 5f12d7c

Browse files
committed
PS: Taint flow through all calls to 'toString'.
1 parent 763effb commit 5f12d7c

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

powershell/ql/lib/semmle/code/powershell/ast/internal/InvokeMemberExpression.qll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,14 @@ class ConstructorCall extends InvokeMemberExpr {
7272
/** Gets the name of the type being constructed by this constructor call. */
7373
string getConstructedTypeName() { result = typename.getName() }
7474
}
75+
76+
/**
77+
* A call to a `toString` method. For example:
78+
*
79+
* ```powershell
80+
* $x.ToString()
81+
* ```
82+
*/
83+
class ToStringCall extends InvokeMemberExpr {
84+
ToStringCall() { this.getName().toLowerCase() = "toString" }
85+
}

powershell/ql/lib/semmle/code/powershell/controlflow/CfgNodes.qll

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ module ExprNodes {
587587
}
588588

589589
private class CallOperatorChildMapping extends CallExprChildMapping instanceof CallOperator {
590-
override predicate relevantChild(Ast child) { none() }
590+
override predicate relevantChild(Ast child) { super.relevantChild(child) }
591591
}
592592

593593
class CallOperatorCfgNode extends CallExprCfgNode {
@@ -600,6 +600,18 @@ module ExprNodes {
600600
ExprCfgNode getCommand() { result = this.getArgument(0) }
601601
}
602602

603+
private class ToStringCallChildmapping extends CallExprChildMapping instanceof ToStringCall {
604+
override predicate relevantChild(Ast child) { super.relevantChild(child) }
605+
}
606+
607+
class ToStringCallCfgNode extends CallExprCfgNode {
608+
override string getAPrimaryQlClass() { result = "ToStringCallCfgNode" }
609+
610+
override ToStringCallChildmapping e;
611+
612+
override ToStringCall getExpr() { result = e }
613+
}
614+
603615
private class MemberExprChildMapping extends ExprChildMapping, MemberExpr {
604616
override predicate relevantChild(Ast child) {
605617
child = this.getQualifier()

powershell/ql/lib/semmle/code/powershell/dataflow/internal/DataFlowPublic.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,13 @@ class CallOperatorNode extends CallNode {
534534
Node getCommand() { result.asExpr() = call.getCommand() } // TODO: Alternatively, we could remap calls to & as command expressions.
535535
}
536536

537+
/**
538+
* A call to `ToString`, viewed as a node in a data flow graph.
539+
*/
540+
class ToStringCallNode extends CallNode {
541+
override CfgNodes::ExprNodes::ToStringCallCfgNode call;
542+
}
543+
537544
/** A use of a type name, viewed as a node in a data flow graph. */
538545
class TypeNameNode extends ExprNode {
539546
override CfgNodes::ExprNodes::TypeNameExprCfgNode n;

powershell/ql/lib/semmle/code/powershell/dataflow/internal/TaintTrackingPrivate.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ private module Cached {
5757
or
5858
c.isAnyElement()
5959
)
60+
or
61+
nodeTo.(DataFlow::ToStringCallNode).getQualifier() = nodeFrom
6062
) and
6163
model = ""
6264
or

0 commit comments

Comments
 (0)