fix: enforce input,output,env prefixes in MaD

This commit is contained in:
Alvaro Muñoz
2024-02-14 14:03:11 +01:00
parent 7139d3b6d2
commit ebaac5f5cb
4 changed files with 26 additions and 15 deletions

View File

@@ -50,22 +50,22 @@ predicate externallyDefinedSource(DataFlow::Node source, string sourceType, stri
) and
(
if fieldName.trim().matches("env.%")
then source.asExpr() = uses.getEnvExpr(fieldName.trim().replaceAll("env\\.", ""))
then source.asExpr() = uses.getEnvExpr(fieldName.trim().replaceAll("env.", ""))
else
if fieldName.trim().matches("output.%")
then
// 'output.' is the default qualifier
source.asExpr() = uses
then source.asExpr() = uses
else none()
) and
sourceType = kind
)
}
predicate externallyDefinedSummary(DataFlow::Node pred, DataFlow::Node succ, DataFlow::ContentSet c) {
predicate externallyDefinedStoreStep(
DataFlow::Node pred, DataFlow::Node succ, DataFlow::ContentSet c
) {
exists(UsesExpr uses, string action, string version, string input, string output |
c = any(DataFlow::FieldContent ct | ct.getName() = output.replaceAll("output\\.", "")) and
summaryModel(action, version, input, output, "taint") and
c = any(DataFlow::FieldContent ct | ct.getName() = output.replaceAll("output.", "")) and
uses.getCallee() = action.toLowerCase() and
(
if version.trim() = "*"
@@ -74,10 +74,11 @@ predicate externallyDefinedSummary(DataFlow::Node pred, DataFlow::Node succ, Dat
) and
(
if input.trim().matches("env.%")
then pred.asExpr() = uses.getEnvExpr(input.trim().replaceAll("env\\.", ""))
then pred.asExpr() = uses.getEnvExpr(input.trim().replaceAll("env.", ""))
else
// 'input.' is the default qualifier
pred.asExpr() = uses.getArgumentExpr(input.trim().replaceAll("input\\.", ""))
if input.trim().matches("input.%")
then pred.asExpr() = uses.getArgumentExpr(input.trim().replaceAll("input.", ""))
else none()
) and
succ.asExpr() = uses
)
@@ -87,8 +88,11 @@ predicate externallyDefinedSink(DataFlow::ExprNode sink, string kind) {
exists(UsesExpr uses, string action, string version, string input |
(
if input.trim().matches("env.%")
then sink.asExpr() = uses.getEnvExpr(input.trim().replaceAll("input\\.", ""))
else sink.asExpr() = uses.getArgumentExpr(input.trim())
then sink.asExpr() = uses.getEnvExpr(input.trim().replaceAll("env.", ""))
else
if input.trim().matches("input.%")
then sink.asExpr() = uses.getArgumentExpr(input.trim().replaceAll("input.", ""))
else none()
) and
sinkModel(action, version, input, kind) and
uses.getCallee() = action.toLowerCase() and

View File

@@ -0,0 +1,7 @@
extensions:
- addsTo:
pack: codeql/actions-all
extensible: sinkModel
data:
- ["","","",""]

View File

@@ -3,5 +3,5 @@ extensions:
pack: codeql/actions-all
extensible: summaryModel
data:
- ["frabert/replace-string-action", "*", "string", "replaced", "taint"]
- ["frabert/replace-string-action", "*", "replace-with", "replaced", "taint"]
- ["frabert/replace-string-action", "*", "input.string", "output.replaced", "taint"]
- ["frabert/replace-string-action", "*", "input.replace-with", "output.replaced", "taint"]

View File

@@ -3,5 +3,5 @@ extensions:
pack: codeql/actions-all
extensible: summaryModel
data:
- ["mad9000/actions-find-and-replace-string", "*", "source", "value", "taint"]
- ["mad9000/actions-find-and-replace-string", "*", "replace", "value", "taint"]
- ["mad9000/actions-find-and-replace-string", "*", "input.source", "output.value", "taint"]
- ["mad9000/actions-find-and-replace-string", "*", "input.replace", "output.value", "taint"]