Skip to content
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

Java: Convert implementations of LocalUserInput to Models-as-Data #14127

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
category: minorAnalysis
---
* Modified the `EnvInput` class in `semmle.code.java.dataflow.FlowSources` to include `environment` and `file` source nodes.
There are no changes to results unless you add source models using the `environment` or `file` source kinds.
* Added `environment` source models for the following methods:
* `java.lang.System#getenv`
* `java.lang.System#getProperties`
* `java.lang.System#getProperty`
* `java.util.Properties#get`
* `java.util.Properties#getProperty`
* Added `file` source models for the following methods:
* the `java.io.FileInputStream` constructor
* `hudson.FilePath#newInputStreamDenyingSymlinkAsNeeded`
* `hudson.FilePath#openInputStream`
* `hudson.FilePath#read`
* `hudson.FilePath#readFromOffset`
* `hudson.FilePath#readToString`
* Modified the `DatabaseInput` class in `semmle.code.java.dataflow.FlowSources` to include `database` source nodes.
There are no changes to results unless you add source models using the `database` source kind.
* Added `database` source models for the following method:
* `java.sql.ResultSet#getString`
5 changes: 5 additions & 0 deletions java/ql/lib/ext/hudson.model.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ extensions:
pack: codeql/java-all
extensible: sourceModel
data:
- ["hudson", "FilePath", False, "newInputStreamDenyingSymlinkAsNeeded", "", "", "ReturnValue", "file", "manual"]
- ["hudson", "FilePath", False, "openInputStream", "", "", "ReturnValue", "file", "manual"]
- ["hudson", "FilePath", False, "read", "", "", "ReturnValue", "file", "manual"]
- ["hudson", "FilePath", False, "readFromOffset", "", "", "ReturnValue", "file", "manual"]
- ["hudson", "FilePath", False, "readToString", "", "", "ReturnValue", "file", "manual"]
- ["hudson", "Plugin", True, "configure", "", "", "Parameter", "remote", "manual"]
- ["hudson", "Plugin", True, "newInstance", "", "", "Parameter", "remote", "manual"]
- addsTo:
Expand Down
5 changes: 5 additions & 0 deletions java/ql/lib/ext/java.io.model.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,8 @@ extensions:
# sink neutrals
- ["java.io", "File", "compareTo", "", "sink", "hq-manual"]
- ["java.io", "File", "exists", "()", "sink", "hq-manual"]
- addsTo:
pack: codeql/java-all
extensible: sourceModel
data:
- ["java.io", "FileInputStream", True, "FileInputStream", "", "", "Argument[this]", "file", "manual"]
7 changes: 7 additions & 0 deletions java/ql/lib/ext/java.lang.model.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ extensions:
- ["java.lang", "System$Logger", True, "log", "(System$Logger$Level,String,Supplier)", "", "Argument[1..2]", "log-injection", "manual"]
- ["java.lang", "System$Logger", True, "log", "(System$Logger$Level,String,Supplier,Throwable)", "", "Argument[1..2]", "log-injection", "manual"]
- ["java.lang", "System$Logger", True, "log", "(System$Logger$Level,String,Throwable)", "", "Argument[1]", "log-injection", "manual"]
- addsTo:
pack: codeql/java-all
extensible: sourceModel
data:
- ["java.lang", "System", False, "getenv", "", "", "ReturnValue", "environment", "manual"]
- ["java.lang", "System", False, "getProperties", "", "", "ReturnValue", "environment", "manual"]
- ["java.lang", "System", False, "getProperty", "", "", "ReturnValue", "environment", "manual"]
- addsTo:
pack: codeql/java-all
extensible: summaryModel
Expand Down
5 changes: 5 additions & 0 deletions java/ql/lib/ext/java.sql.model.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,8 @@ extensions:
- ["java.sql", "ResultSet", "getTimestamp", "(String)", "summary", "manual"] # taint-numeric
- ["java.sql", "Timestamp", "Timestamp", "(long)", "summary", "manual"] # taint-numeric
- ["java.sql", "Timestamp", "getTime", "()", "summary", "manual"] # taint-numeric
- addsTo:
pack: codeql/java-all
extensible: sourceModel
data:
- ["java.sql", "ResultSet", True, "getString", "", "", "ReturnValue", "database", "manual"]
7 changes: 7 additions & 0 deletions java/ql/lib/ext/java.util.model.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
extensions:
- addsTo:
pack: codeql/java-all
extensible: sourceModel
data:
- ["java.util", "Properties", True, "get", "", "", "ReturnValue", "environment", "manual"]
- ["java.util", "Properties", True, "getProperty", "", "", "ReturnValue", "environment", "manual"]

- addsTo:
pack: codeql/java-all
extensible: summaryModel
Expand Down
12 changes: 3 additions & 9 deletions java/ql/lib/semmle/code/java/dataflow/FlowSources.qll
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,7 @@ deprecated class EnvInput extends DataFlow::Node {
* environment variables.
*/
private class EnvironmentInput extends LocalUserInput {
EnvironmentInput() {
// Results from various specific methods.
this.asExpr().(MethodAccess).getMethod() instanceof EnvReadMethod
}
EnvironmentInput() { sourceNode(this, "environment") }

override string getThreatModel() { result = "environment" }
}
Expand Down Expand Up @@ -268,10 +265,7 @@ private class CliInput extends LocalUserInput {
private class FileInput extends LocalUserInput {
FileInput() {
// Access to files.
this.asExpr()
.(ConstructorCall)
.getConstructedType()
.hasQualifiedName("java.io", "FileInputStream")
sourceNode(this, "file")
}

override string getThreatModel() { result = "file" }
Expand All @@ -292,7 +286,7 @@ deprecated class DatabaseInput = DbInput;
* A node with input from a database.
*/
private class DbInput extends LocalUserInput {
DbInput() { this.asExpr().(MethodAccess).getMethod() instanceof ResultSetGetStringMethod }
DbInput() { sourceNode(this, "database") }

override string getThreatModel() { result = "database" }
}
Expand Down
15 changes: 0 additions & 15 deletions java/ql/lib/semmle/code/java/frameworks/hudson/Hudson.qll
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,6 @@ class HudsonWebMethod extends Method {
}
}

private class FilePathRead extends LocalUserInput {
FilePathRead() {
this.asExpr()
.(MethodAccess)
.getMethod()
.hasQualifiedName("hudson", "FilePath",
[
"newInputStreamDenyingSymlinkAsNeeded", "openInputStream", "read", "readFromOffset",
"readToString"
])
}

override string getThreatModel() { result = "file" }
}

private class HudsonUtilXssSanitizer extends XssSanitizer {
HudsonUtilXssSanitizer() {
this.asExpr()
Expand Down
6 changes: 3 additions & 3 deletions shared/mad/codeql/mad/ModelValidation.qll
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ module KindValidation<KindValidationConfigSig Config> {
this =
[
// shared
"local", "remote",
"local", "remote", "file",
// Java
"android-external-storage-dir", "contentprovider",
"android-external-storage-dir", "contentprovider", "database", "environment",
// C#
"file", "file-write",
"file-write",
// JavaScript
"database-access-result"
]
Expand Down