Skip to content

Commit 79f54fb

Browse files
committed
Java: Improve API sinks implementation.
1 parent a7b39e4 commit 79f54fb

27 files changed

+61
-107
lines changed

java/ql/lib/semmle/code/java/dataflow/ApiSinks.qll

Lines changed: 5 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22

33
private import semmle.code.java.dataflow.DataFlow
44
private import semmle.code.java.dataflow.ExternalFlow
5+
private import semmle.code.java.dataflow.FlowSinks as FlowSinks
56

6-
/**
7-
* A data flow sink node.
8-
*/
9-
abstract class SinkNode extends DataFlow::Node { }
7+
class SinkNode = FlowSinks::ApiSinkNode;
108

119
/**
1210
* Module that adds all API like sinks to `SinkNode`, excluding sinks for cryptography based
1311
* queries, and queries where sinks are not succifiently defined (eg. using broad method name matching).
1412
*/
15-
private module ApiSinks {
13+
private module AllApiSinks {
1614
private import semmle.code.java.security.AndroidSensitiveCommunicationQuery as AndroidSensitiveCommunicationQuery
1715
private import semmle.code.java.security.ArbitraryApkInstallation as ArbitraryApkInstallation
1816
private import semmle.code.java.security.CleartextStorageAndroidDatabaseQuery as CleartextStorageAndroidDatabaseQuery
@@ -41,82 +39,12 @@ private module ApiSinks {
4139
private import semmle.code.java.security.XPath as Xpath
4240
private import semmle.code.java.security.XSS as Xss
4341

44-
private class AndoidIntentRedirectionQuerySinks extends SinkNode instanceof AndroidSensitiveCommunicationQuery::SensitiveCommunicationSink
45-
{ }
46-
47-
private class ArbitraryApkInstallationSinks extends SinkNode instanceof ArbitraryApkInstallation::SetDataSink
48-
{ }
49-
50-
private class CleartextStorageAndroidDatabaseQuerySinks extends SinkNode instanceof CleartextStorageAndroidDatabaseQuery::LocalDatabaseSink
51-
{ }
52-
53-
private class CleartextStorageAndroidFilesystemQuerySinks extends SinkNode instanceof CleartextStorageAndroidFilesystemQuery::LocalFileSink
54-
{ }
55-
56-
private class CleartextStorageCookieQuerySinks extends SinkNode instanceof CleartextStorageCookieQuery::CookieStoreSink
57-
{ }
58-
59-
private class CleartextStorageSharedPrefsQuerySinks extends SinkNode instanceof CleartextStorageSharedPrefsQuery::SharedPreferencesSink
60-
{ }
61-
62-
private class ExternallyControlledFormatStringQuerySinks extends SinkNode instanceof ExternallyControlledFormatStringQuery::StringFormatSink
63-
{ }
64-
65-
private class InsecureBasicAuthSinks extends SinkNode instanceof InsecureBasicAuth::InsecureBasicAuthSink
66-
{ }
67-
68-
private class InsecureTrustManagerSinks extends SinkNode instanceof InsecureTrustManager::InsecureTrustManagerSink
69-
{ }
70-
71-
private class IntentUriPermissionManipulationSinks extends SinkNode instanceof IntentUriPermissionManipulation::IntentUriPermissionManipulationSink
72-
{ }
73-
74-
private class InsecureLdapAuthSinks extends SinkNode instanceof InsecureLdapAuth::InsecureLdapUrlSink
75-
{ }
76-
77-
private class JndiInjectionSinks extends SinkNode instanceof JndiInjection::JndiInjectionSink { }
78-
79-
private class JwtSinks extends SinkNode instanceof Jwt::JwtParserWithInsecureParseSink { }
80-
81-
private class OgnlInjectionSinks extends SinkNode instanceof OgnlInjection::OgnlInjectionSink { }
82-
83-
private class SensitiveResultReceiverQuerySinks extends SinkNode instanceof SensitiveResultReceiverQuery::SensitiveResultReceiverSink
84-
{ }
85-
86-
private class SensitiveUiQuerySinks extends SinkNode instanceof SensitiveUiQuery::TextFieldSink {
87-
}
88-
89-
private class SpelInjectionSinks extends SinkNode instanceof SpelInjection::SpelExpressionEvaluationSink
90-
{ }
91-
92-
private class QueryInjectionSinks extends SinkNode instanceof QueryInjection::QueryInjectionSink {
93-
}
94-
95-
private class TempDirLocalInformationDisclosureSinks extends SinkNode instanceof TempDirLocalInformationDisclosureQuery::MethodFileDirectoryCreationSink
96-
{ }
97-
98-
private class UnsafeAndroidAccessSinks extends SinkNode instanceof UnsafeAndroidAccess::UrlResourceSink
99-
{ }
100-
101-
private class UnsafeContentUriResolutionSinks extends SinkNode instanceof UnsafeContentUriResolution::ContentUriResolutionSink
102-
{ }
103-
104-
private class UnsafeDeserializationQuerySinks extends SinkNode instanceof UnsafeDeserializationQuery::UnsafeDeserializationSink
105-
{ }
106-
107-
private class UrlRedirectSinks extends SinkNode instanceof UrlRedirect::UrlRedirectSink { }
108-
109-
private class WebviewDebugEnabledQuery extends SinkNode instanceof WebviewDebuggingEnabledQuery::WebviewDebugSink
110-
{ }
111-
112-
private class XPathSinks extends SinkNode instanceof Xpath::XPathInjectionSink { }
113-
11442
private class XssSinks extends SinkNode instanceof Xss::XssSink { }
11543

11644
/**
11745
* Add all models as data sinks.
11846
*/
119-
private class SinkNodeExternal extends SinkNode {
120-
SinkNodeExternal() { sinkNode(this, _) }
47+
private class ApiSinkNodeExternal extends SinkNode {
48+
ApiSinkNodeExternal() { sinkNode(this, _) }
12149
}
12250
}

java/ql/lib/semmle/code/java/security/AndroidSensitiveCommunicationQuery.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import java
44
import semmle.code.java.dataflow.TaintTracking
55
import semmle.code.java.frameworks.android.Intent
66
import semmle.code.java.security.SensitiveActions
7+
private import semmle.code.java.dataflow.FlowSinks
78

89
/**
910
* Gets regular expression for matching names of Android variables that indicate the value being held contains sensitive information.
@@ -154,7 +155,7 @@ deprecated class SensitiveCommunicationConfig extends TaintTracking::Configurati
154155
/**
155156
* A class of sensitive communication sink nodes.
156157
*/
157-
class SensitiveCommunicationSink extends DataFlow::Node {
158+
class SensitiveCommunicationSink extends ApiSinkNode {
158159
SensitiveCommunicationSink() {
159160
isSensitiveBroadcastSink(this)
160161
or

java/ql/lib/semmle/code/java/security/ArbitraryApkInstallation.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import java
44
import semmle.code.java.frameworks.android.Intent
55
import semmle.code.java.dataflow.DataFlow
66
private import semmle.code.java.dataflow.ExternalFlow
7+
private import semmle.code.java.dataflow.FlowSinks
78
private import semmle.code.java.dataflow.FlowSources
89

910
/** A string literal that represents the MIME type for Android APKs. */
@@ -48,7 +49,7 @@ class SetDataMethod extends Method {
4849
}
4950

5051
/** A dataflow sink for the URI of an intent. */
51-
class SetDataSink extends DataFlow::ExprNode {
52+
class SetDataSink extends ApiSinkNode, DataFlow::ExprNode {
5253
SetDataSink() {
5354
exists(MethodCall ma |
5455
this.getExpr() = ma.getQualifier() and

java/ql/lib/semmle/code/java/security/CleartextStorageAndroidDatabaseQuery.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import semmle.code.java.frameworks.android.ContentProviders
66
import semmle.code.java.frameworks.android.Intent
77
import semmle.code.java.frameworks.android.SQLite
88
import semmle.code.java.security.CleartextStorageQuery
9+
private import semmle.code.java.dataflow.FlowSinks
910
private import semmle.code.java.dataflow.FlowSources
1011

1112
private class LocalDatabaseCleartextStorageSink extends CleartextStorageSink {
@@ -107,7 +108,7 @@ class LocalDatabaseOpenMethodCallSource extends ApiSourceNode {
107108
/**
108109
* A class of local database sink nodes.
109110
*/
110-
class LocalDatabaseSink extends DataFlow::Node {
111+
class LocalDatabaseSink extends ApiSinkNode {
111112
LocalDatabaseSink() { localDatabaseInput(this, _) or localDatabaseStore(this, _) }
112113
}
113114

java/ql/lib/semmle/code/java/security/CleartextStorageAndroidFilesystemQuery.qll

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55

66
import java
77
import semmle.code.java.dataflow.DataFlow
8-
private import semmle.code.java.dataflow.ExternalFlow
9-
private import semmle.code.java.dataflow.FlowSources
108
import semmle.code.java.security.CleartextStorageQuery
119
import semmle.code.xml.AndroidManifest
10+
private import semmle.code.java.dataflow.ExternalFlow
11+
private import semmle.code.java.dataflow.FlowSinks
12+
private import semmle.code.java.dataflow.FlowSources
1213

1314
private class AndroidFilesystemCleartextStorageSink extends CleartextStorageSink {
1415
AndroidFilesystemCleartextStorageSink() {
@@ -90,7 +91,7 @@ class LocalFileOpenCallSource extends ApiSourceNode {
9091
/**
9192
* A class of local file sink nodes.
9293
*/
93-
class LocalFileSink extends DataFlow::Node {
94+
class LocalFileSink extends ApiSinkNode {
9495
LocalFileSink() {
9596
filesystemInput(this, _) or
9697
closesFile(this, _)

java/ql/lib/semmle/code/java/security/CleartextStorageCookieQuery.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import java
44
import semmle.code.java.dataflow.DataFlow
55
deprecated import semmle.code.java.dataflow.DataFlow3
66
import semmle.code.java.security.CleartextStorageQuery
7+
private import semmle.code.java.dataflow.FlowSinks
78
private import semmle.code.java.dataflow.FlowSources
89

910
private class CookieCleartextStorageSink extends CleartextStorageSink {
@@ -48,7 +49,7 @@ class CookieSource extends ApiSourceNode {
4849
/**
4950
* A class of cookie store sink nodes.
5051
*/
51-
class CookieStoreSink extends DataFlow::Node {
52+
class CookieStoreSink extends ApiSinkNode {
5253
CookieStoreSink() { cookieStore(this, _) }
5354
}
5455

java/ql/lib/semmle/code/java/security/CleartextStorageSharedPrefsQuery.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import java
44
import semmle.code.java.dataflow.DataFlow
55
import semmle.code.java.frameworks.android.SharedPreferences
66
import semmle.code.java.security.CleartextStorageQuery
7+
private import semmle.code.java.dataflow.FlowSinks
78
private import semmle.code.java.dataflow.FlowSources
89

910
private class SharedPrefsCleartextStorageSink extends CleartextStorageSink {
@@ -80,7 +81,7 @@ class SharedPreferencesEditorMethodCallSource extends ApiSourceNode {
8081
/**
8182
* A class of shared preferences sink nodes.
8283
*/
83-
class SharedPreferencesSink extends DataFlow::Node {
84+
class SharedPreferencesSink extends ApiSinkNode {
8485
SharedPreferencesSink() {
8586
sharedPreferencesInput(this, _) or
8687
sharedPreferencesStore(this, _)

java/ql/lib/semmle/code/java/security/ExternallyControlledFormatStringQuery.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/** Provides a taint-tracking configuration to reason about externally controlled format string vulnerabilities. */
22

33
import java
4+
private import semmle.code.java.dataflow.FlowSinks
45
private import semmle.code.java.dataflow.FlowSources
56
private import semmle.code.java.StringFormat
67

78
/**
89
* A class of string format sink nodes.
910
*/
10-
class StringFormatSink extends DataFlow::Node {
11+
class StringFormatSink extends ApiSinkNode {
1112
StringFormatSink() { this.asExpr() = any(StringFormat formatCall).getFormatArgument() }
1213
}
1314

java/ql/lib/semmle/code/java/security/InsecureBasicAuth.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import java
44
import semmle.code.java.dataflow.DataFlow
55
import semmle.code.java.dataflow.TaintTracking
66
import semmle.code.java.security.HttpsUrls
7+
private import semmle.code.java.dataflow.FlowSinks
78

89
/**
910
* A source that represents HTTP URLs.
@@ -20,7 +21,7 @@ private class DefaultInsecureBasicAuthSource extends InsecureBasicAuthSource {
2021
* A sink that represents a method that sets Basic Authentication.
2122
* Extend this class to add your own Insecure Basic Authentication sinks.
2223
*/
23-
abstract class InsecureBasicAuthSink extends DataFlow::Node { }
24+
abstract class InsecureBasicAuthSink extends ApiSinkNode { }
2425

2526
/** A default sink representing methods that set an Authorization header. */
2627
private class DefaultInsecureBasicAuthSink extends InsecureBasicAuthSink {

java/ql/lib/semmle/code/java/security/InsecureLdapAuth.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java
44
private import semmle.code.java.dataflow.DataFlow
5+
private import semmle.code.java.dataflow.FlowSinks
56
private import semmle.code.java.frameworks.Networking
67
private import semmle.code.java.frameworks.Jndi
78

@@ -32,7 +33,7 @@ class InsecureLdapUrl extends Expr {
3233
/**
3334
* A sink representing the construction of a `DirContextEnvironment`.
3435
*/
35-
class InsecureLdapUrlSink extends DataFlow::Node {
36+
class InsecureLdapUrlSink extends ApiSinkNode {
3637
InsecureLdapUrlSink() {
3738
exists(ConstructorCall cc |
3839
cc.getConstructedType().getAnAncestor() instanceof TypeDirContext and

0 commit comments

Comments
 (0)