Skip to content

Commit 5c44f8b

Browse files
authored
Merge pull request github#14370 from michaelnebel/java/enablethreatmodels
Java: Enable threat models for most Java queries.
2 parents 5cb3543 + cf3a62d commit 5c44f8b

File tree

78 files changed

+107
-95
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+107
-95
lines changed

java/ql/lib/semmle/code/java/dataflow/internal/TaintTrackingUtil.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ private MethodAccess callReturningSameType(Expr ref) {
618618
}
619619

620620
private SrcRefType entrypointType() {
621-
exists(RemoteFlowSource s, RefType t |
621+
exists(ThreatModelFlowSource s, RefType t |
622622
s instanceof DataFlow::ExplicitParameterNode and
623623
t = pragma[only_bind_out](s).getType() and
624624
not t instanceof TypeObject and
@@ -629,6 +629,10 @@ private SrcRefType entrypointType() {
629629
}
630630

631631
private predicate entrypointFieldStep(DataFlow::Node src, DataFlow::Node sink) {
632-
src = DataFlow::getFieldQualifier(sink.asExpr().(FieldRead)) and
632+
exists(FieldRead fa |
633+
fa = sink.asExpr() and
634+
src = DataFlow::getFieldQualifier(fa) and
635+
not fa.getField().isStatic()
636+
) and
633637
src.getType().(RefType).getSourceDeclaration() = entrypointType()
634638
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ deprecated class IntentRedirectionConfiguration extends TaintTracking::Configura
3030

3131
/** A taint tracking configuration for tainted Intents being used to start Android components. */
3232
module IntentRedirectionConfig implements DataFlow::ConfigSig {
33-
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
33+
predicate isSource(DataFlow::Node source) { source instanceof ThreatModelFlowSource }
3434

3535
predicate isSink(DataFlow::Node sink) { sink instanceof IntentRedirectionSink }
3636

@@ -57,7 +57,7 @@ private class OriginalIntentSanitizer extends IntentRedirectionSanitizer {
5757
* flowing directly to sinks that start Android components.
5858
*/
5959
private module SameIntentBeingRelaunchedConfig implements DataFlow::ConfigSig {
60-
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
60+
predicate isSource(DataFlow::Node source) { source instanceof ThreatModelFlowSource }
6161

6262
predicate isSink(DataFlow::Node sink) { sink instanceof IntentRedirectionSink }
6363

@@ -93,7 +93,7 @@ private class IntentWithTaintedComponent extends DataFlow::Node {
9393
* A taint tracking configuration for tainted data flowing to an `Intent`'s component.
9494
*/
9595
private module TaintedIntentComponentConfig implements DataFlow::ConfigSig {
96-
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
96+
predicate isSource(DataFlow::Node source) { source instanceof ThreatModelFlowSource }
9797

9898
predicate isSink(DataFlow::Node sink) {
9999
any(IntentSetComponent setComponent).getSink() = sink.asExpr()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class ExternalApkSource extends DataFlow::Node {
7474
sourceNode(this, "android-external-storage-dir") or
7575
this.asExpr().(MethodAccess).getMethod() instanceof UriConstructorMethod or
7676
this.asExpr().(StringLiteral).getValue().matches("file://%") or
77-
this instanceof RemoteFlowSource
77+
this instanceof ThreatModelFlowSource
7878
}
7979
}
8080

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ private import semmle.code.java.security.ArithmeticCommon
66

77
/** A taint-tracking configuration to reason about overflow from unvalidated user input. */
88
module RemoteUserInputOverflowConfig implements DataFlow::ConfigSig {
9-
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
9+
predicate isSource(DataFlow::Node source) { source instanceof ThreatModelFlowSource }
1010

1111
predicate isSink(DataFlow::Node sink) { overflowSink(_, sink.asExpr()) }
1212

@@ -17,7 +17,7 @@ module RemoteUserInputOverflowConfig implements DataFlow::ConfigSig {
1717

1818
/** A taint-tracking configuration to reason about underflow from unvalidated user input. */
1919
module RemoteUserInputUnderflowConfig implements DataFlow::ConfigSig {
20-
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
20+
predicate isSource(DataFlow::Node source) { source instanceof ThreatModelFlowSource }
2121

2222
predicate isSink(DataFlow::Node sink) { underflowSink(_, sink.asExpr()) }
2323

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private class DefaultCommandInjectionSanitizer extends CommandInjectionSanitizer
5252
* A taint-tracking configuration for unvalidated user input that is used to run an external process.
5353
*/
5454
module RemoteUserInputToArgumentToExecFlowConfig implements DataFlow::ConfigSig {
55-
predicate isSource(DataFlow::Node src) { src instanceof RemoteFlowSource }
55+
predicate isSource(DataFlow::Node src) { src instanceof ThreatModelFlowSource }
5656

5757
predicate isSink(DataFlow::Node sink) { sink instanceof CommandInjectionSink }
5858

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ deprecated class ConditionalBypassFlowConfig extends TaintTracking::Configuratio
5757
* A taint tracking configuration for untrusted data flowing to sensitive conditions.
5858
*/
5959
module ConditionalBypassFlowConfig implements DataFlow::ConfigSig {
60-
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
60+
predicate isSource(DataFlow::Node source) { source instanceof ThreatModelFlowSource }
6161

6262
predicate isSink(DataFlow::Node sink) { conditionControlsMethod(_, sink.asExpr()) }
6363

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ deprecated class UntrustedDataToExternalApiConfig extends TaintTracking::Configu
106106
}
107107

108108
/**
109-
* Taint tracking configuration for flow from `RemoteFlowSource`s to `ExternalApiDataNode`s.
109+
* Taint tracking configuration for flow from `ThreatModelFlowSource`s to `ExternalApiDataNode`s.
110110
*/
111111
module UntrustedDataToExternalApiConfig implements DataFlow::ConfigSig {
112-
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
112+
predicate isSource(DataFlow::Node source) { source instanceof ThreatModelFlowSource }
113113

114114
predicate isSink(DataFlow::Node sink) { sink instanceof ExternalApiDataNode }
115115
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ private import semmle.code.java.StringFormat
88
* A taint-tracking configuration for externally controlled format string vulnerabilities.
99
*/
1010
module ExternallyControlledFormatStringConfig implements DataFlow::ConfigSig {
11-
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
11+
predicate isSource(DataFlow::Node source) { source instanceof ThreatModelFlowSource }
1212

1313
predicate isSink(DataFlow::Node sink) {
1414
sink.asExpr() = any(StringFormat formatCall).getFormatArgument()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ deprecated class FragmentInjectionTaintConf extends TaintTracking::Configuration
2828
* that is used to create Android fragments dynamically.
2929
*/
3030
module FragmentInjectionTaintConfig implements DataFlow::ConfigSig {
31-
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
31+
predicate isSource(DataFlow::Node source) { source instanceof ThreatModelFlowSource }
3232

3333
predicate isSink(DataFlow::Node sink) { sink instanceof FragmentInjectionSink }
3434

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ deprecated class GroovyInjectionConfig extends TaintTracking::Configuration {
2828
* that is used to evaluate a Groovy expression.
2929
*/
3030
module GroovyInjectionConfig implements DataFlow::ConfigSig {
31-
predicate isSource(DataFlow::Node source) { source instanceof RemoteFlowSource }
31+
predicate isSource(DataFlow::Node source) { source instanceof ThreatModelFlowSource }
3232

3333
predicate isSink(DataFlow::Node sink) { sink instanceof GroovyInjectionSink }
3434

0 commit comments

Comments
 (0)