Skip to content

Commit 205d2e5

Browse files
committed
PS: Add dot sourcing as a sink.
1 parent 670ad74 commit 205d2e5

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class CallOperator extends CmdCall {
8383
class DotSourcingOperator extends CmdCall {
8484
DotSourcingOperator() { getRawAst(this) instanceof Raw::DotSourcingOperator }
8585

86-
Expr getPath() { result = this.getCallee() }
86+
Expr getCommand() { result = this.getCallee() }
8787
}
8888

8989
class JoinPath extends CmdCall {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,21 @@ module ExprNodes {
608608
ExprCfgNode getCommand() { result = this.getCallee() }
609609
}
610610

611+
private class DotSourcingOperatorChildMapping extends CallExprChildMapping instanceof DotSourcingOperator
612+
{
613+
override predicate relevantChild(Ast child) { super.relevantChild(child) }
614+
}
615+
616+
class DotSourcingOperatorCfgNode extends CallExprCfgNode {
617+
override string getAPrimaryQlClass() { result = "DotSourcingOperatorCfgNode" }
618+
619+
override DotSourcingOperatorChildMapping e;
620+
621+
override DotSourcingOperator getExpr() { result = e }
622+
623+
ExprCfgNode getCommand() { result = this.getCallee() }
624+
}
625+
611626
private class ToStringCallChildmapping extends CallExprChildMapping instanceof ToStringCall {
612627
override predicate relevantChild(Ast child) { super.relevantChild(child) }
613628
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,14 @@ class CallNode extends ExprNode {
544544
class CallOperatorNode extends CallNode {
545545
override CfgNodes::ExprNodes::CallOperatorCfgNode call;
546546

547-
Node getCommand() { result.asExpr() = call.getCommand() } // TODO: Alternatively, we could remap calls to & as command expressions.
547+
Node getCommand() { result.asExpr() = call.getCommand() }
548+
}
549+
550+
/** A call to operator `.`, viewed as a node in a data flow graph. */
551+
class DotSourcingOperatorNode extends CallNode {
552+
override CfgNodes::ExprNodes::DotSourcingOperatorCfgNode call;
553+
554+
Node getCommand() { result.asExpr() = call.getCommand() }
548555
}
549556

550557
/**

powershell/ql/lib/semmle/code/powershell/security/CommandInjectionCustomizations.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ module CommandInjection {
4646
call.getAnArgument() = this
4747
)
4848
or
49-
// Or the call command itself in case it's a use of operator &.
49+
// Or the call command itself in case it's a use of "operator &" or "operator .".
5050
any(DataFlow::CallOperatorNode call).getCommand() = this
51+
or
52+
any(DataFlow::DotSourcingOperatorNode call).getCommand() = this
5153
}
5254

5355
override string getSinkType() { result = "call to Invoke-Expression" }

0 commit comments

Comments
 (0)