Skip to content

Commit ebaac5f

Browse files
author
Alvaro Muñoz
committed
fix: enforce input,output,env prefixes in MaD
1 parent 7139d3b commit ebaac5f

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,22 @@ predicate externallyDefinedSource(DataFlow::Node source, string sourceType, stri
5050
) and
5151
(
5252
if fieldName.trim().matches("env.%")
53-
then source.asExpr() = uses.getEnvExpr(fieldName.trim().replaceAll("env\\.", ""))
53+
then source.asExpr() = uses.getEnvExpr(fieldName.trim().replaceAll("env.", ""))
5454
else
5555
if fieldName.trim().matches("output.%")
56-
then
57-
// 'output.' is the default qualifier
58-
source.asExpr() = uses
56+
then source.asExpr() = uses
5957
else none()
6058
) and
6159
sourceType = kind
6260
)
6361
}
6462

65-
predicate externallyDefinedSummary(DataFlow::Node pred, DataFlow::Node succ, DataFlow::ContentSet c) {
63+
predicate externallyDefinedStoreStep(
64+
DataFlow::Node pred, DataFlow::Node succ, DataFlow::ContentSet c
65+
) {
6666
exists(UsesExpr uses, string action, string version, string input, string output |
67-
c = any(DataFlow::FieldContent ct | ct.getName() = output.replaceAll("output\\.", "")) and
6867
summaryModel(action, version, input, output, "taint") and
68+
c = any(DataFlow::FieldContent ct | ct.getName() = output.replaceAll("output.", "")) and
6969
uses.getCallee() = action.toLowerCase() and
7070
(
7171
if version.trim() = "*"
@@ -74,10 +74,11 @@ predicate externallyDefinedSummary(DataFlow::Node pred, DataFlow::Node succ, Dat
7474
) and
7575
(
7676
if input.trim().matches("env.%")
77-
then pred.asExpr() = uses.getEnvExpr(input.trim().replaceAll("env\\.", ""))
77+
then pred.asExpr() = uses.getEnvExpr(input.trim().replaceAll("env.", ""))
7878
else
79-
// 'input.' is the default qualifier
80-
pred.asExpr() = uses.getArgumentExpr(input.trim().replaceAll("input\\.", ""))
79+
if input.trim().matches("input.%")
80+
then pred.asExpr() = uses.getArgumentExpr(input.trim().replaceAll("input.", ""))
81+
else none()
8182
) and
8283
succ.asExpr() = uses
8384
)
@@ -87,8 +88,11 @@ predicate externallyDefinedSink(DataFlow::ExprNode sink, string kind) {
8788
exists(UsesExpr uses, string action, string version, string input |
8889
(
8990
if input.trim().matches("env.%")
90-
then sink.asExpr() = uses.getEnvExpr(input.trim().replaceAll("input\\.", ""))
91-
else sink.asExpr() = uses.getArgumentExpr(input.trim())
91+
then sink.asExpr() = uses.getEnvExpr(input.trim().replaceAll("env.", ""))
92+
else
93+
if input.trim().matches("input.%")
94+
then sink.asExpr() = uses.getArgumentExpr(input.trim().replaceAll("input.", ""))
95+
else none()
9296
) and
9397
sinkModel(action, version, input, kind) and
9498
uses.getCallee() = action.toLowerCase() and

ql/lib/ext/PLACEHOLDER.model.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/actions-all
4+
extensible: sinkModel
5+
data:
6+
- ["","","",""]
7+

ql/lib/ext/frabert_replace-string-action.model.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ extensions:
33
pack: codeql/actions-all
44
extensible: summaryModel
55
data:
6-
- ["frabert/replace-string-action", "*", "string", "replaced", "taint"]
7-
- ["frabert/replace-string-action", "*", "replace-with", "replaced", "taint"]
6+
- ["frabert/replace-string-action", "*", "input.string", "output.replaced", "taint"]
7+
- ["frabert/replace-string-action", "*", "input.replace-with", "output.replaced", "taint"]

ql/lib/ext/mad9000_actions-find-and-replace-string.model.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ extensions:
33
pack: codeql/actions-all
44
extensible: summaryModel
55
data:
6-
- ["mad9000/actions-find-and-replace-string", "*", "source", "value", "taint"]
7-
- ["mad9000/actions-find-and-replace-string", "*", "replace", "value", "taint"]
6+
- ["mad9000/actions-find-and-replace-string", "*", "input.source", "output.value", "taint"]
7+
- ["mad9000/actions-find-and-replace-string", "*", "input.replace", "output.value", "taint"]

0 commit comments

Comments
 (0)