mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Shared: move shared file to 'shared' folder and add parameterized module for 'getInvalidModelKind'
This commit is contained in:
@@ -6,6 +6,7 @@ extractor: go
|
||||
library: true
|
||||
upgrades: upgrades
|
||||
dependencies:
|
||||
codeql/mad: ${workspace}
|
||||
codeql/tutorial: ${workspace}
|
||||
codeql/util: ${workspace}
|
||||
dataExtensions:
|
||||
|
||||
@@ -68,7 +68,7 @@ private import internal.FlowSummaryImpl::Private::External
|
||||
private import internal.FlowSummaryImplSpecific
|
||||
private import internal.AccessPathSyntax
|
||||
private import FlowSummary
|
||||
private import internal.SharedModelValidation
|
||||
private import codeql.mad.ModelValidation as SharedModelVal
|
||||
|
||||
/**
|
||||
* A module importing the frameworks that provide external flow data,
|
||||
@@ -189,27 +189,20 @@ module ModelValidation {
|
||||
)
|
||||
}
|
||||
|
||||
/** Gets an error message relating to an invalid kind in a model. */
|
||||
private string getInvalidModelKind() {
|
||||
exists(string kind | summaryModel(_, _, _, _, _, _, _, _, kind, _) |
|
||||
not kind instanceof ValidSummaryKind and
|
||||
result = "Invalid kind \"" + kind + "\" in summary model."
|
||||
)
|
||||
or
|
||||
exists(string kind, string msg | sinkModel(_, _, _, _, _, _, _, kind, _) |
|
||||
not kind instanceof ValidSinkKind 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 instanceof ValidSourceKind and
|
||||
result = "Invalid kind \"" + kind + "\" in source model."
|
||||
)
|
||||
}
|
||||
/** Holds if a summary model exists for the given `kind`. */
|
||||
private predicate summaryKind(string kind) { summaryModel(_, _, _, _, _, _, _, _, kind, _) }
|
||||
|
||||
/** Holds if a sink model exists for the given `kind`. */
|
||||
private predicate sinkKind(string kind) { sinkModel(_, _, _, _, _, _, _, kind, _) }
|
||||
|
||||
/** Holds if a source model exists for the given `kind`. */
|
||||
private predicate sourceKind(string kind) { sourceModel(_, _, _, _, _, _, _, kind, _) }
|
||||
|
||||
/** Holds if a neutral model exists for the given `kind`. */
|
||||
private predicate neutralKind(string kind) { none() }
|
||||
|
||||
private module KindVal =
|
||||
SharedModelVal::KindValidation<summaryKind/1, sinkKind/1, sourceKind/1, neutralKind/1>;
|
||||
|
||||
private string getInvalidModelSignature() {
|
||||
exists(
|
||||
@@ -247,7 +240,7 @@ module ModelValidation {
|
||||
msg =
|
||||
[
|
||||
getInvalidModelSignature(), getInvalidModelInput(), getInvalidModelOutput(),
|
||||
getInvalidModelKind()
|
||||
KindVal::getInvalidModelKind()
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,143 +0,0 @@
|
||||
/**
|
||||
* INTERNAL: Do not use.
|
||||
*
|
||||
* Provides classes and predicates related to validating models-as-data rows.
|
||||
* Such that we can share this logic across our CodeQL analysis of different languages.
|
||||
*/
|
||||
|
||||
/** A valid models-as-data sink kind. */
|
||||
class ValidSinkKind extends string {
|
||||
bindingset[this]
|
||||
ValidSinkKind() {
|
||||
this =
|
||||
[
|
||||
// shared
|
||||
"code-injection", "command-injection", "file-content-store", "html-injection",
|
||||
"js-injection", "ldap-injection", "log-injection", "path-injection", "request-forgery",
|
||||
"sql-injection", "url-redirection",
|
||||
// Java-only currently, but may be shared in the future
|
||||
"bean-validation", "fragment-injection", "groovy-injection", "hostname-verification",
|
||||
"information-leak", "intent-redirection", "jexl-injection", "jndi-injection",
|
||||
"mvel-injection", "ognl-injection", "pending-intents", "response-splitting",
|
||||
"template-injection", "xpath-injection", "xslt-injection",
|
||||
// JavaScript-only currently, but may be shared in the future
|
||||
"mongodb.sink", "nosql-injection", "unsafe-deserialization",
|
||||
// Swift-only currently, but may be shared in the future
|
||||
"database-store", "format-string", "hash-iteration-count", "predicate-injection",
|
||||
"preferences-store", "tls-protocol-version", "transmission", "webview-fetch", "xxe"
|
||||
]
|
||||
or
|
||||
this.matches([
|
||||
// shared
|
||||
"encryption-%", "qltest%", "test-%",
|
||||
// Java-only currently, but may be shared in the future
|
||||
"regex-use%",
|
||||
// JavaScript-only currently, but may be shared in the future
|
||||
"credentials-%",
|
||||
// Swift-only currently, but may be shared in the future
|
||||
"%string-%length", "weak-hash-input-%"
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
/** An outdated models-as-data sink kind. */
|
||||
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", "command-line-injection",
|
||||
"code", "html", "remote", "uncontrolled-format-string", "js-eval"
|
||||
]
|
||||
}
|
||||
|
||||
/** Gets a replacement kind for an outdated sink kind. */
|
||||
private string replacementKind() {
|
||||
this = ["sql", "xpath", "groovy", "jexl", "mvel", "xslt", "ldap", "code", "html"] and
|
||||
result = this + "-injection"
|
||||
or
|
||||
this = "js-eval" and result = "code-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", "remote"] 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"
|
||||
or
|
||||
this = "command-line-injection" and result = "command-injection"
|
||||
or
|
||||
this = "uncontrolled-format-string" and result = "format-string"
|
||||
}
|
||||
|
||||
/** Gets an error message for an outdated sink kind. */
|
||||
string outdatedMessage() {
|
||||
result =
|
||||
"The kind \"" + this + "\" is outdated. Use \"" + this.replacementKind() + "\" instead."
|
||||
}
|
||||
}
|
||||
|
||||
/** A valid models-as-data source kind. */
|
||||
class ValidSourceKind extends string {
|
||||
bindingset[this]
|
||||
ValidSourceKind() {
|
||||
this =
|
||||
[
|
||||
// shared
|
||||
"local", "remote",
|
||||
// Java
|
||||
"android-external-storage-dir", "contentprovider",
|
||||
// C#
|
||||
"file", "file-write",
|
||||
// JavaScript
|
||||
"database-access-result", "remote-flow"
|
||||
]
|
||||
or
|
||||
this.matches([
|
||||
// shared
|
||||
"qltest%", "test-%",
|
||||
// Swift
|
||||
"%string-%length"
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
/** A valid models-as-data summary kind. */
|
||||
class ValidSummaryKind extends string {
|
||||
ValidSummaryKind() {
|
||||
this =
|
||||
[
|
||||
// shared
|
||||
"taint", "value",
|
||||
// JavaScript
|
||||
"type"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
/** A valid models-as-data neutral kind. */
|
||||
class ValidNeutralKind extends string {
|
||||
ValidNeutralKind() {
|
||||
this =
|
||||
[
|
||||
// Java/C# currently
|
||||
"sink", "source", "summary"
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user