@@ -7,9 +7,11 @@ import semmle.code.java.dataflow.DataFlow
7
7
import HardcodedCredentials
8
8
9
9
/**
10
+ * DEPRECATED: Use `HardcodedCredentialApiCallFlow` instead.
11
+ *
10
12
* A data-flow configuration that tracks flow from a hard-coded credential in a call to a sensitive Java API which may compromise security.
11
13
*/
12
- class HardcodedCredentialApiCallConfiguration extends DataFlow:: Configuration {
14
+ deprecated class HardcodedCredentialApiCallConfiguration extends DataFlow:: Configuration {
13
15
HardcodedCredentialApiCallConfiguration ( ) { this = "HardcodedCredentialApiCallConfiguration" }
14
16
15
17
override predicate isSource ( DataFlow:: Node n ) {
@@ -52,3 +54,53 @@ class HardcodedCredentialApiCallConfiguration extends DataFlow::Configuration {
52
54
n .asExpr ( ) .( MethodAccess ) .getMethod ( ) instanceof MethodSystemGetenv
53
55
}
54
56
}
57
+
58
+ /**
59
+ * A data-flow configuration that tracks flow from a hard-coded credential in a call to a sensitive Java API which may compromise security.
60
+ */
61
+ private module HardcodedCredentialApiCallConfig implements DataFlow:: ConfigSig {
62
+ predicate isSource ( DataFlow:: Node n ) {
63
+ n .asExpr ( ) instanceof HardcodedExpr and
64
+ not n .asExpr ( ) .getEnclosingCallable ( ) instanceof ToStringMethod
65
+ }
66
+
67
+ predicate isSink ( DataFlow:: Node n ) { n .asExpr ( ) instanceof CredentialsApiSink }
68
+
69
+ predicate isAdditionalFlowStep ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
70
+ node1 .asExpr ( ) .getType ( ) instanceof TypeString and
71
+ (
72
+ exists ( MethodAccess ma | ma .getMethod ( ) .hasName ( [ "getBytes" , "toCharArray" ] ) |
73
+ node2 .asExpr ( ) = ma and
74
+ ma .getQualifier ( ) = node1 .asExpr ( )
75
+ )
76
+ or
77
+ // These base64 routines are usually taint propagators, and this is not a general
78
+ // TaintTracking::Configuration, so we must specifically include them here
79
+ // as a common transform applied to a constant before passing to a remote API.
80
+ exists ( MethodAccess ma |
81
+ ma .getMethod ( )
82
+ .hasQualifiedName ( [
83
+ "java.util" , "cn.hutool.core.codec" , "org.apache.shiro.codec" ,
84
+ "apache.commons.codec.binary" , "org.springframework.util"
85
+ ] , [ "Base64$Encoder" , "Base64$Decoder" , "Base64" , "Base64Utils" ] ,
86
+ [
87
+ "encode" , "encodeToString" , "decode" , "decodeBase64" , "encodeBase64" ,
88
+ "encodeBase64Chunked" , "encodeBase64String" , "encodeBase64URLSafe" ,
89
+ "encodeBase64URLSafeString"
90
+ ] )
91
+ |
92
+ node1 .asExpr ( ) = ma .getArgument ( 0 ) and
93
+ node2 .asExpr ( ) = ma
94
+ )
95
+ )
96
+ }
97
+
98
+ predicate isBarrier ( DataFlow:: Node n ) {
99
+ n .asExpr ( ) .( MethodAccess ) .getMethod ( ) instanceof MethodSystemGetenv
100
+ }
101
+ }
102
+
103
+ /**
104
+ * Tracks flow from a hard-coded credential in a call to a sensitive Java API which may compromise security.
105
+ */
106
+ module HardcodedCredentialApiCallFlow = DataFlow:: Global< HardcodedCredentialApiCallConfig > ;
0 commit comments