Skip to content

Commit c7b57b5

Browse files
author
Alvaro Muñoz
committed
Merge command and file store steps
1 parent 48fa296 commit c7b57b5

2 files changed

Lines changed: 18 additions & 44 deletions

File tree

ql/lib/codeql/actions/dataflow/FlowSteps.qll

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,15 @@ predicate envToEnvStoreStep(DataFlow::Node pred, DataFlow::Node succ, DataFlow::
4949
* echo "bar=${foo}" >> "$GITHUB_OUTPUT"
5050
*/
5151
predicate commandToOutputStoreStep(DataFlow::Node pred, DataFlow::Node succ, DataFlow::ContentSet c) {
52-
exists(CommandSource source, Run run, string key, string cmd |
53-
source.getCommand() = cmd and
52+
exists(Run run, string key, string cmd |
53+
(
54+
exists(CommandSource source | source.getCommand() = cmd)
55+
or
56+
exists(FileSource source |
57+
source.asExpr().(Step).getAFollowingStep() = run and
58+
Bash::outputsPartialFileContent(run, cmd)
59+
)
60+
) and
5461
Bash::cmdReachingGitHubFileWrite(run, cmd, "GITHUB_OUTPUT", key) and
5562
c = any(DataFlow::FieldContent ct | ct.getName() = key) and
5663
pred.asExpr() = run.getScriptScalar() and
@@ -67,50 +74,19 @@ predicate commandToOutputStoreStep(DataFlow::Node pred, DataFlow::Node succ, Dat
6774
* echo "bar=${foo}" >> "$GITHUB_ENV"
6875
*/
6976
predicate commandToEnvStoreStep(DataFlow::Node pred, DataFlow::Node succ, DataFlow::ContentSet c) {
70-
exists(CommandSource source, Run run, string key, string cmd |
71-
source.getCommand() = cmd and
77+
exists(Run run, string key, string cmd |
78+
(
79+
exists(CommandSource source | source.getCommand() = cmd)
80+
or
81+
exists(FileSource source |
82+
source.asExpr().(Step).getAFollowingStep() = run and
83+
Bash::outputsPartialFileContent(run, cmd)
84+
)
85+
) and
7286
Bash::cmdReachingGitHubFileWrite(run, cmd, "GITHUB_ENV", key) and
7387
c = any(DataFlow::FieldContent ct | ct.getName() = key) and
7488
pred.asExpr() = run.getScriptScalar() and
7589
// we store the taint on the enclosing job since there may not be an implicit env attribute
7690
succ.asExpr() = run.getEnclosingJob()
7791
)
7892
}
79-
80-
/**
81-
* A downloaded artifact that gets assigned to a Run step output.
82-
* - uses: actions/download-artifact@v2
83-
* - run: echo "::set-output name=id::$(<pr-id.txt)"
84-
* - run: |
85-
* foo=$(<pr-id.txt)"
86-
* echo "::set-output name=id::$foo
87-
*/
88-
predicate fileToOutputStoreStep(DataFlow::Node pred, DataFlow::Node succ, DataFlow::ContentSet c) {
89-
exists(FileSource source, Run run, string key, string cmd |
90-
source.asExpr().(Step).getAFollowingStep() = run and
91-
Bash::cmdReachingGitHubFileWrite(run, cmd, "GITHUB_OUTPUT", key) and
92-
Bash::outputsPartialFileContent(run, cmd) and
93-
c = any(DataFlow::FieldContent ct | ct.getName() = key) and
94-
pred.asExpr() = run.getScriptScalar() and
95-
succ.asExpr() = run
96-
)
97-
}
98-
99-
/**
100-
* A downloaded artifact that gets assigned to an environment variable.
101-
* - run: echo "foo=$(<pr-id.txt)" >> "$GITHUB_ENV"
102-
* - run: |
103-
* foo=$(<pr-id.txt)"
104-
* echo "bar=${foo}" >> "$GITHUB_ENV"
105-
*/
106-
predicate fileToEnvStoreStep(DataFlow::Node pred, DataFlow::Node succ, DataFlow::ContentSet c) {
107-
exists(FileSource source, Run run, string key, string cmd |
108-
source.asExpr().(Step).getAFollowingStep() = run and
109-
Bash::cmdReachingGitHubFileWrite(run, cmd, "GITHUB_ENV", key) and
110-
Bash::outputsPartialFileContent(run, cmd) and
111-
c = any(DataFlow::FieldContent ct | ct.getName() = key) and
112-
pred.asExpr() = run.getScriptScalar() and
113-
// we store the taint on the enclosing job since there may not be an implicit env attribute
114-
succ.asExpr() = run.getEnclosingJob()
115-
)
116-
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,6 @@ predicate storeStep(Node node1, ContentSet c, Node node2) {
351351
madStoreStep(node1, node2, c) or
352352
envToOutputStoreStep(node1, node2, c) or
353353
envToEnvStoreStep(node1, node2, c) or
354-
fileToOutputStoreStep(node1, node2, c) or
355-
fileToEnvStoreStep(node1, node2, c) or
356354
commandToOutputStoreStep(node1, node2, c) or
357355
commandToEnvStoreStep(node1, node2, c)
358356
}

0 commit comments

Comments
 (0)