Skip to content

Commit 271c512

Browse files
author
Alvaro Muñoz
committed
better identification of Composite Actions input and output nodes
1 parent cc3f2ee commit 271c512

File tree

4 files changed

+31
-27
lines changed

4 files changed

+31
-27
lines changed

ql/lib/codeql/actions/Ast.qll

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ class OutputsStmt extends Statement instanceof YamlMapping {
9292
* Gets a specific output expression (YamlMapping) by name.
9393
*/
9494
OutputExpr getOutputExpr(string name) {
95-
this.(YamlMapping).lookup(name).(YamlMapping).lookup("value") = result
95+
this.(YamlMapping).lookup(name).(YamlMapping).lookup("value") = result or
96+
this.(YamlMapping).lookup(name) = result
9697
}
9798
}
9899

@@ -101,7 +102,12 @@ class InputExpr extends Expression instanceof YamlString {
101102
}
102103

103104
class OutputExpr extends Expression instanceof YamlString {
104-
OutputExpr() { exists(OutputsStmt outputs | outputs.(YamlMapping).maps(_, this)) }
105+
OutputExpr() {
106+
exists(OutputsStmt outputs |
107+
outputs.(YamlMapping).lookup(_).(YamlMapping).lookup("value") = this or
108+
outputs.(YamlMapping).lookup(_) = this
109+
)
110+
}
105111
}
106112

107113
/**

ql/lib/codeql/actions/dataflow/internal/DataFlowPublic.qll

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,22 @@ class ExprNode extends Node, TExprNode {
4848
* Reusable workflow input nodes
4949
*/
5050
class ParameterNode extends ExprNode {
51-
private InputExpr parameter;
51+
private InputExpr input;
5252

5353
ParameterNode() {
54-
this.asExpr() = parameter and
55-
parameter = any(ReusableWorkflowStmt w).getInputsStmt().getInputExpr(_)
54+
this.asExpr() = input and
55+
input = any(InputsStmt s).getInputExpr(_)
5656
}
5757

5858
predicate isParameterOf(DataFlowCallable c, ParameterPosition pos) {
59-
parameter = c.(ReusableWorkflowStmt).getInputsStmt().getInputExpr(pos)
59+
input = c.(ReusableWorkflowStmt).getInputsStmt().getInputExpr(pos)
6060
}
6161

62-
override string toString() { result = parameter.toString() }
62+
override string toString() { result = "input " + input.toString() }
6363

64-
override Location getLocation() { result = parameter.getLocation() }
64+
override Location getLocation() { result = input.getLocation() }
6565

66-
InputExpr getInputExpr() { result = parameter }
66+
InputExpr getInputExpr() { result = input }
6767
}
6868

6969
/**
@@ -83,19 +83,18 @@ class ArgumentNode extends ExprNode {
8383
* Reusable workflow output nodes
8484
*/
8585
class ReturnNode extends ExprNode {
86-
private Cfg::Node node;
86+
private OutputExpr output;
8787

8888
ReturnNode() {
89-
this.getCfgNode() = node and
90-
(node.getAstNode() = any(ReusableWorkflowStmt w).getOutputsStmt().getOutputExpr(_) or
91-
node.getAstNode() = any(CompositeActionStmt a).getOutputsStmt().getOutputExpr(_))
89+
this.asExpr() = output and
90+
output = any(OutputsStmt s).getOutputExpr(_)
9291
}
9392

9493
ReturnKind getKind() { result = TNormalReturn() }
9594

96-
override string toString() { result = "return " + node.toString() }
95+
override string toString() { result = "output " + output.toString() }
9796

98-
override Location getLocation() { result = node.getLocation() }
97+
override Location getLocation() { result = output.getLocation() }
9998
}
10099

101100
/** Gets the node corresponding to `e`. */

ql/src/Security/CWE-020/CompositeActionSummaries.ql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ import codeql.actions.TaintTracking
1515
import codeql.actions.dataflow.FlowSources
1616
import codeql.actions.dataflow.ExternalFlow
1717

18-
private class OutputVariableSink extends DataFlow::Node {
19-
OutputVariableSink() { exists(OutputsStmt s | s.getOutputExpr(_) = this.asExpr()) }
20-
}
21-
2218
private module MyConfig implements DataFlow::ConfigSig {
2319
predicate isSource(DataFlow::Node source) {
20+
source instanceof DataFlow::ParameterNode and
2421
exists(CompositeActionStmt c | c.getInputsStmt().getInputExpr(_) = source.asExpr())
2522
}
2623

27-
predicate isSink(DataFlow::Node sink) { sink instanceof OutputVariableSink }
24+
predicate isSink(DataFlow::Node sink) {
25+
sink instanceof DataFlow::ReturnNode and
26+
exists(CompositeActionStmt c | c.getOutputsStmt().getOutputExpr(_) = sink.asExpr())
27+
}
2828
}
2929

3030
module MyFlow = TaintTracking::Global<MyConfig>;

ql/src/Security/CWE-020/CompositeActionsSources.ql

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,17 @@ import codeql.actions.TaintTracking
1515
import codeql.actions.dataflow.FlowSources
1616
import codeql.actions.dataflow.ExternalFlow
1717

18-
private class OutputVariableSink extends DataFlow::Node {
19-
OutputVariableSink() { exists(OutputsStmt s | s.getOutputExpr(_) = this.asExpr()) }
20-
}
21-
2218
private module MyConfig implements DataFlow::ConfigSig {
2319
predicate isSource(DataFlow::Node source) {
2420
source instanceof RemoteFlowSource and
25-
exists(CompositeActionStmt c | c.getAChildNode*() = source.asExpr()) and
26-
not exists(CompositeActionStmt c | c.getInputsStmt().getInputExpr(_) = source.asExpr())
21+
not source instanceof DataFlow::ParameterNode and
22+
exists(CompositeActionStmt c | c.getAChildNode*() = source.asExpr())
2723
}
2824

29-
predicate isSink(DataFlow::Node sink) { sink instanceof OutputVariableSink }
25+
predicate isSink(DataFlow::Node sink) {
26+
sink instanceof DataFlow::ReturnNode and
27+
exists(CompositeActionStmt c | c.getOutputsStmt().getOutputExpr(_) = sink.asExpr())
28+
}
3029
}
3130

3231
module MyFlow = TaintTracking::Global<MyConfig>;

0 commit comments

Comments
 (0)