Skip to content

Shared: share MaD kind validation across languages #13324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e24e3a6
JS/Python/Ruby: add getInvalidModelKind as experiment
May 30, 2023
869f820
Shared: add 'SharedModelValidation' file as experiment
May 30, 2023
ddb5d92
Shared: add source, summary, and neutral shared valid kinds
May 30, 2023
0ab1848
JS/Python/Ruby: use 'SharedModelValidation' file
May 30, 2023
79f61cc
Java/C#/Go/Swift: use 'SharedModelValidation' file
Jun 2, 2023
7317c29
Shared: update kind information
Jun 2, 2023
9f42ae3
Shared: remove cpp note
Jun 2, 2023
615f2a5
Java/C#/Go/Swift: remove commented-out code
Jun 2, 2023
254e447
JS/Python/Ruby: update getInvalidModelKind
Jun 2, 2023
76508d1
Go/Swift: validate source/sink kinds
Jun 2, 2023
7b629f5
Shared: include 'qltest%' and 'test-%'
Jun 5, 2023
76f5dca
Shared: move 'OutdatedSinkKind' to shared file and add outdated JS an…
Jun 5, 2023
62ac0dc
Shared: add outdated sink kind msg to 'getInvalidModelKind' for all l…
Jun 5, 2023
3f1dc8e
Shared: add outdated Swift sink kinds
Jun 5, 2023
9d5972a
Shared: update qldocs
Jun 5, 2023
6c46cd9
Java/C#/Go/Swift: move 'SharedModelValidation.qll' to internal folder
Jun 5, 2023
7a4b74d
C#: fix typo with outdated sink msg location
Jun 5, 2023
5a23421
Shared: minor updates to comments
Jun 5, 2023
da58b2a
Shared: move shared file to 'shared' folder and add parameterized mod…
Jun 9, 2023
3bfb5f9
Shared: update comment and remove 'remote-flow' as a source kind
Jun 9, 2023
bcba1f3
Shared: update pack files
Jun 9, 2023
9abe3e3
Shared: use a module as input to 'KindValidation'
Jun 9, 2023
3559111
Merge branch 'main' into jcogs33/shared-sink-kind-validation
jcogs33 Jun 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions csharp/ql/lib/qlpack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extractor: csharp
library: true
upgrades: upgrades
dependencies:
codeql/mad: ${workspace}
codeql/ssa: ${workspace}
codeql/tutorial: ${workspace}
codeql/util: ${workspace}
Expand Down
35 changes: 12 additions & 23 deletions csharp/ql/lib/semmle/code/csharp/dataflow/ExternalFlow.qll
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ private import internal.DataFlowPublic
private import internal.FlowSummaryImpl::Public
private import internal.FlowSummaryImpl::Private::External
private import internal.FlowSummaryImplSpecific
private import codeql.mad.ModelValidation as SharedModelVal

/** Holds if a source model exists for the given parameters. */
predicate sourceModel = Extensions::sourceModel/9;
Expand Down Expand Up @@ -204,30 +205,18 @@ module ModelValidation {
)
}

private string getInvalidModelKind() {
exists(string kind | summaryModel(_, _, _, _, _, _, _, _, kind, _) |
not kind = ["taint", "value"] and
result = "Invalid kind \"" + kind + "\" in summary model."
)
or
exists(string kind | sinkModel(_, _, _, _, _, _, _, kind, _) |
not kind =
["code-injection", "sql-injection", "js-injection", "html-injection", "file-content-store"] and
not kind.matches("encryption-%") and
result = "Invalid kind \"" + kind + "\" in sink model."
)
or
exists(string kind | sourceModel(_, _, _, _, _, _, _, kind, _) |
not kind = ["local", "remote", "file", "file-write"] and
result = "Invalid kind \"" + kind + "\" in source model."
)
or
exists(string kind | neutralModel(_, _, _, _, kind, _) |
not kind = ["summary", "source", "sink"] and
result = "Invalid kind \"" + kind + "\" in neutral model."
)
private module KindValConfig implements SharedModelVal::KindValidationConfigSig {
predicate summaryKind(string kind) { summaryModel(_, _, _, _, _, _, _, _, kind, _) }

predicate sinkKind(string kind) { sinkModel(_, _, _, _, _, _, _, kind, _) }

predicate sourceKind(string kind) { sourceModel(_, _, _, _, _, _, _, kind, _) }

predicate neutralKind(string kind) { neutralModel(_, _, _, _, kind, _) }
}

private module KindVal = SharedModelVal::KindValidation<KindValConfig>;

private string getInvalidModelSignature() {
exists(
string pred, string namespace, string type, string name, string signature, string ext,
Expand Down Expand Up @@ -269,7 +258,7 @@ module ModelValidation {
msg =
[
getInvalidModelSignature(), getInvalidModelInput(), getInvalidModelOutput(),
getInvalidModelKind()
KindVal::getInvalidModelKind()
]
}
}
Expand Down
1 change: 1 addition & 0 deletions go/ql/lib/qlpack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extractor: go
library: true
upgrades: upgrades
dependencies:
codeql/mad: ${workspace}
codeql/tutorial: ${workspace}
codeql/util: ${workspace}
dataExtensions:
Expand Down
16 changes: 10 additions & 6 deletions go/ql/lib/semmle/go/dataflow/ExternalFlow.qll
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ private import internal.FlowSummaryImpl::Private::External
private import internal.FlowSummaryImplSpecific
private import internal.AccessPathSyntax
private import FlowSummary
private import codeql.mad.ModelValidation as SharedModelVal

/**
* A module importing the frameworks that provide external flow data,
Expand Down Expand Up @@ -188,13 +189,16 @@ module ModelValidation {
)
}

private string getInvalidModelKind() {
exists(string kind | summaryModel(_, _, _, _, _, _, _, _, kind, _) |
not kind = ["taint", "value"] and
result = "Invalid kind \"" + kind + "\" in summary model."
)
private module KindValConfig implements SharedModelVal::KindValidationConfigSig {
predicate summaryKind(string kind) { summaryModel(_, _, _, _, _, _, _, _, kind, _) }

predicate sinkKind(string kind) { sinkModel(_, _, _, _, _, _, _, kind, _) }

predicate sourceKind(string kind) { sourceModel(_, _, _, _, _, _, _, kind, _) }
}

private module KindVal = SharedModelVal::KindValidation<KindValConfig>;

private string getInvalidModelSignature() {
exists(
string pred, string package, string type, string name, string signature, string ext,
Expand Down Expand Up @@ -231,7 +235,7 @@ module ModelValidation {
msg =
[
getInvalidModelSignature(), getInvalidModelInput(), getInvalidModelOutput(),
getInvalidModelKind()
KindVal::getInvalidModelKind()
]
}
}
Expand Down
1 change: 1 addition & 0 deletions java/ql/lib/qlpack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extractor: java
library: true
upgrades: upgrades
dependencies:
codeql/mad: ${workspace}
codeql/regex: ${workspace}
codeql/tutorial: ${workspace}
codeql/typetracking: ${workspace}
Expand Down
88 changes: 10 additions & 78 deletions java/ql/lib/semmle/code/java/dataflow/ExternalFlow.qll
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ private import internal.FlowSummaryImplSpecific as FlowSummaryImplSpecific
private import internal.AccessPathSyntax
private import ExternalFlowExtensions as Extensions
private import FlowSummary
private import codeql.mad.ModelValidation as SharedModelVal

/**
* A class for activating additional model rows.
Expand Down Expand Up @@ -265,87 +266,18 @@ module ModelValidation {
)
}

private class OutdatedSinkKind extends string {
OutdatedSinkKind() {
this =
[
"sql", "url-redirect", "xpath", "ssti", "logging", "groovy", "jexl", "mvel", "xslt",
"ldap", "pending-intent-sent", "intent-start", "set-hostname-verifier",
"header-splitting", "xss", "write-file", "create-file", "read-file", "open-url",
"jdbc-url"
]
}

private string replacementKind() {
this = ["sql", "xpath", "groovy", "jexl", "mvel", "xslt", "ldap"] and
result = this + "-injection"
or
this = "url-redirect" and result = "url-redirection"
or
this = "ssti" and result = "template-injection"
or
this = "logging" and result = "log-injection"
or
this = "pending-intent-sent" and result = "pending-intents"
or
this = "intent-start" and result = "intent-redirection"
or
this = "set-hostname-verifier" and result = "hostname-verification"
or
this = "header-splitting" and result = "response-splitting"
or
this = "xss" and result = "html-injection\" or \"js-injection"
or
this = "write-file" and result = "file-content-store"
or
this = ["create-file", "read-file"] and result = "path-injection"
or
this = ["open-url", "jdbc-url"] and result = "request-forgery"
}
private module KindValConfig implements SharedModelVal::KindValidationConfigSig {
predicate summaryKind(string kind) { summaryModel(_, _, _, _, _, _, _, _, kind, _) }

string outdatedMessage() {
result =
"The kind \"" + this + "\" is outdated. Use \"" + this.replacementKind() + "\" instead."
}
}
predicate sinkKind(string kind) { sinkModel(_, _, _, _, _, _, _, kind, _) }

private string getInvalidModelKind() {
exists(string kind | summaryModel(_, _, _, _, _, _, _, _, kind, _) |
not kind = ["taint", "value"] and
result = "Invalid kind \"" + kind + "\" in summary model."
)
or
exists(string kind, string msg | sinkModel(_, _, _, _, _, _, _, kind, _) |
not kind =
[
"request-forgery", "jndi-injection", "ldap-injection", "sql-injection", "log-injection",
"mvel-injection", "xpath-injection", "groovy-injection", "html-injection", "js-injection",
"ognl-injection", "intent-redirection", "pending-intents", "url-redirection",
"path-injection", "file-content-store", "hostname-verification", "response-splitting",
"information-leak", "xslt-injection", "jexl-injection", "bean-validation",
"template-injection", "fragment-injection", "command-injection"
] and
not kind.matches("regex-use%") and
not kind.matches("qltest%") and
msg = "Invalid kind \"" + kind + "\" in sink model." and
// The part of this message that refers to outdated sink kinds can be deleted after June 1st, 2024.
if kind instanceof OutdatedSinkKind
then result = msg + " " + kind.(OutdatedSinkKind).outdatedMessage()
else result = msg
)
or
exists(string kind | sourceModel(_, _, _, _, _, _, _, kind, _) |
not kind = ["remote", "contentprovider", "android-external-storage-dir"] and
not kind.matches("qltest%") and
result = "Invalid kind \"" + kind + "\" in source model."
)
or
exists(string kind | neutralModel(_, _, _, _, kind, _) |
not kind = ["summary", "source", "sink"] and
result = "Invalid kind \"" + kind + "\" in neutral model."
)
predicate sourceKind(string kind) { sourceModel(_, _, _, _, _, _, _, kind, _) }

predicate neutralKind(string kind) { neutralModel(_, _, _, _, kind, _) }
}

private module KindVal = SharedModelVal::KindValidation<KindValConfig>;

private string getInvalidModelSignature() {
exists(
string pred, string package, string type, string name, string signature, string ext,
Expand Down Expand Up @@ -387,7 +319,7 @@ module ModelValidation {
msg =
[
getInvalidModelSignature(), getInvalidModelInput(), getInvalidModelOutput(),
getInvalidModelKind()
KindVal::getInvalidModelKind()
]
}
}
Expand Down
1 change: 1 addition & 0 deletions javascript/ql/lib/qlpack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extractor: javascript
library: true
upgrades: upgrades
dependencies:
codeql/mad: ${workspace}
codeql/regex: ${workspace}
codeql/tutorial: ${workspace}
codeql/util: ${workspace}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,17 @@ module ModelOutput {

import Cached
import Specific::ModelOutputSpecific
private import codeql.mad.ModelValidation as SharedModelVal

private module KindValConfig implements SharedModelVal::KindValidationConfigSig {
predicate summaryKind(string kind) { summaryModel(_, _, _, _, kind) }

predicate sinkKind(string kind) { sinkModel(_, _, kind) }

predicate sourceKind(string kind) { sourceModel(_, _, kind) }
}

private module KindVal = SharedModelVal::KindValidation<KindValConfig>;

/**
* Gets an error message relating to an invalid CSV row in a model.
Expand Down Expand Up @@ -698,5 +709,8 @@ module ModelOutput {
not isValidNoArgumentTokenInIdentifyingAccessPath(token.getName()) and
result = "Invalid token '" + token + "' is missing its arguments, in access path: " + path
)
or
// Check for invalid model kinds
result = KindVal::getInvalidModelKind()
}
}
1 change: 1 addition & 0 deletions python/ql/lib/qlpack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extractor: python
library: true
upgrades: upgrades
dependencies:
codeql/mad: ${workspace}
codeql/regex: ${workspace}
codeql/tutorial: ${workspace}
codeql/util: ${workspace}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,17 @@ module ModelOutput {

import Cached
import Specific::ModelOutputSpecific
private import codeql.mad.ModelValidation as SharedModelVal

private module KindValConfig implements SharedModelVal::KindValidationConfigSig {
predicate summaryKind(string kind) { summaryModel(_, _, _, _, kind) }

predicate sinkKind(string kind) { sinkModel(_, _, kind) }

predicate sourceKind(string kind) { sourceModel(_, _, kind) }
}

private module KindVal = SharedModelVal::KindValidation<KindValConfig>;

/**
* Gets an error message relating to an invalid CSV row in a model.
Expand Down Expand Up @@ -698,5 +709,8 @@ module ModelOutput {
not isValidNoArgumentTokenInIdentifyingAccessPath(token.getName()) and
result = "Invalid token '" + token + "' is missing its arguments, in access path: " + path
)
or
// Check for invalid model kinds
result = KindVal::getInvalidModelKind()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,17 @@ module ModelOutput {

import Cached
import Specific::ModelOutputSpecific
private import codeql.mad.ModelValidation as SharedModelVal

private module KindValConfig implements SharedModelVal::KindValidationConfigSig {
predicate summaryKind(string kind) { summaryModel(_, _, _, _, kind) }

predicate sinkKind(string kind) { sinkModel(_, _, kind) }

predicate sourceKind(string kind) { sourceModel(_, _, kind) }
}

private module KindVal = SharedModelVal::KindValidation<KindValConfig>;

/**
* Gets an error message relating to an invalid CSV row in a model.
Expand Down Expand Up @@ -698,5 +709,8 @@ module ModelOutput {
not isValidNoArgumentTokenInIdentifyingAccessPath(token.getName()) and
result = "Invalid token '" + token + "' is missing its arguments, in access path: " + path
)
or
// Check for invalid model kinds
result = KindVal::getInvalidModelKind()
}
}
1 change: 1 addition & 0 deletions ruby/ql/lib/qlpack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dbscheme: ruby.dbscheme
upgrades: upgrades
library: true
dependencies:
codeql/mad: ${workspace}
codeql/regex: ${workspace}
codeql/ssa: ${workspace}
codeql/tutorial: ${workspace}
Expand Down
Loading