@@ -76,7 +76,7 @@ class InsecureLdapUrl extends Expr {
7676 */
7777predicate isProviderUrlSetter ( MethodAccess ma ) {
7878 ma .getMethod ( ) .getDeclaringType ( ) .getAnAncestor ( ) instanceof TypeHashtable and
79- ( ma .getMethod ( ) .hasName ( "put" ) or ma . getMethod ( ) . hasName ( "setProperty" ) ) and
79+ ma .getMethod ( ) .hasName ( [ "put" , "setProperty" ] ) and
8080 (
8181 ma .getArgument ( 0 ) .( CompileTimeConstantExpr ) .getStringValue ( ) = "java.naming.provider.url"
8282 or
@@ -89,27 +89,48 @@ predicate isProviderUrlSetter(MethodAccess ma) {
8989}
9090
9191/**
92- * Holds if `ma` sets `fieldValue` with attribute name `fieldName` to `envValue` in some `Hashtable`.
92+ * Holds if `ma` sets `fieldValue` to `envValue` in some `Hashtable`.
9393 */
9494bindingset [ fieldValue, envValue]
95- predicate hasEnvWithValue ( MethodAccess ma , string fieldValue , string envValue ) {
95+ predicate hasFieldValueEnv ( MethodAccess ma , string fieldValue , string envValue ) {
96+ // environment.put("java.naming.security.authentication", "simple")
9697 ma .getMethod ( ) .getDeclaringType ( ) .getAnAncestor ( ) instanceof TypeHashtable and
97- ( ma .getMethod ( ) .hasName ( "put" ) or ma . getMethod ( ) . hasName ( "setProperty" ) ) and
98+ ma .getMethod ( ) .hasName ( [ "put" , "setProperty" ] ) and
9899 ma .getArgument ( 0 ) .( CompileTimeConstantExpr ) .getStringValue ( ) = fieldValue and
99100 ma .getArgument ( 1 ) .( CompileTimeConstantExpr ) .getStringValue ( ) = envValue
100101}
101102
103+ /**
104+ * Holds if `ma` sets attribute name `fieldName` to `envValue` in some `Hashtable`.
105+ */
106+ bindingset [ fieldName, envValue]
107+ predicate hasFieldNameEnv ( MethodAccess ma , string fieldName , string envValue ) {
108+ // environment.put(Context.SECURITY_AUTHENTICATION, "simple")
109+ ma .getMethod ( ) .getDeclaringType ( ) .getAnAncestor ( ) instanceof TypeHashtable and
110+ ma .getMethod ( ) .hasName ( [ "put" , "setProperty" ] ) and
111+ exists ( Field f |
112+ ma .getArgument ( 0 ) = f .getAnAccess ( ) and
113+ f .hasName ( fieldName ) and
114+ f .getDeclaringType ( ) instanceof TypeNamingContext
115+ ) and
116+ ma .getArgument ( 1 ) .( CompileTimeConstantExpr ) .getStringValue ( ) = envValue
117+ }
118+
102119/**
103120 * Holds if `ma` sets `java.naming.security.authentication` (also known as `Context.SECURITY_AUTHENTICATION`) to `simple` in some `Hashtable`.
104121 */
105122predicate isBasicAuthEnv ( MethodAccess ma ) {
106- hasEnvWithValue ( ma , "java.naming.security.authentication" , "simple" )
123+ hasFieldValueEnv ( ma , "java.naming.security.authentication" , "simple" ) or
124+ hasFieldNameEnv ( ma , "SECURITY_AUTHENTICATION" , "simple" )
107125}
108126
109127/**
110128 * Holds if `ma` sets `java.naming.security.protocol` (also known as `Context.SECURITY_PROTOCOL`) to `ssl` in some `Hashtable`.
111129 */
112- predicate isSSLEnv ( MethodAccess ma ) { hasEnvWithValue ( ma , "java.naming.security.protocol" , "ssl" ) }
130+ predicate isSSLEnv ( MethodAccess ma ) {
131+ hasFieldValueEnv ( ma , "java.naming.security.protocol" , "ssl" ) or
132+ hasFieldNameEnv ( ma , "SECURITY_PROTOCOL" , "ssl" )
133+ }
113134
114135/**
115136 * A taint-tracking configuration for `ldap://` URL in LDAP authentication.
@@ -141,12 +162,12 @@ class InsecureUrlFlowConfig extends TaintTracking::Configuration {
141162/**
142163 * A taint-tracking configuration for `simple` basic-authentication in LDAP configuration.
143164 */
144- class BasicAuthFlowConfig extends TaintTracking :: Configuration {
165+ class BasicAuthFlowConfig extends DataFlow :: Configuration {
145166 BasicAuthFlowConfig ( ) { this = "InsecureLdapAuth:BasicAuthFlowConfig" }
146167
147168 /** Source of `simple` configuration. */
148169 override predicate isSource ( DataFlow:: Node src ) {
149- src . asExpr ( ) . ( CompileTimeConstantExpr ) . getStringValue ( ) = "simple"
170+ exists ( MethodAccess ma | isBasicAuthEnv ( ma ) and ma . getQualifier ( ) = src . asExpr ( ) )
150171 }
151172
152173 /** Sink of directory context creation. */
@@ -156,26 +177,17 @@ class BasicAuthFlowConfig extends TaintTracking::Configuration {
156177 sink .asExpr ( ) = cc .getArgument ( 0 )
157178 )
158179 }
159-
160- /** Method call of `env.put()`. */
161- override predicate isAdditionalTaintStep ( DataFlow:: Node pred , DataFlow:: Node succ ) {
162- exists ( MethodAccess ma |
163- pred .asExpr ( ) = ma .getArgument ( 1 ) and
164- isBasicAuthEnv ( ma ) and
165- succ .asExpr ( ) = ma .getQualifier ( )
166- )
167- }
168180}
169181
170182/**
171183 * A taint-tracking configuration for `ssl` configuration in LDAP authentication.
172184 */
173- class SSLFlowConfig extends TaintTracking :: Configuration {
185+ class SSLFlowConfig extends DataFlow :: Configuration {
174186 SSLFlowConfig ( ) { this = "InsecureLdapAuth:SSLFlowConfig" }
175187
176188 /** Source of `ssl` configuration. */
177189 override predicate isSource ( DataFlow:: Node src ) {
178- src . asExpr ( ) . ( CompileTimeConstantExpr ) . getStringValue ( ) = "ssl"
190+ exists ( MethodAccess ma | isSSLEnv ( ma ) and ma . getQualifier ( ) = src . asExpr ( ) )
179191 }
180192
181193 /** Sink of directory context creation. */
@@ -185,28 +197,12 @@ class SSLFlowConfig extends TaintTracking::Configuration {
185197 sink .asExpr ( ) = cc .getArgument ( 0 )
186198 )
187199 }
188-
189- /** Method call of `env.put()`. */
190- override predicate isAdditionalTaintStep ( DataFlow:: Node pred , DataFlow:: Node succ ) {
191- exists ( MethodAccess ma |
192- pred .asExpr ( ) = ma .getArgument ( 1 ) and
193- isSSLEnv ( ma ) and
194- succ .asExpr ( ) = ma .getQualifier ( )
195- )
196- }
197200}
198201
199- from DataFlow:: PathNode source , DataFlow:: PathNode sink , InsecureUrlFlowConfig config , VarAccess va
202+ from DataFlow:: PathNode source , DataFlow:: PathNode sink , InsecureUrlFlowConfig config
200203where
201204 config .hasFlowPath ( source , sink ) and
202- sink .getNode ( ) .asExpr ( ) = va and
203- exists ( BasicAuthFlowConfig bc , DataFlow:: PathNode source2 , DataFlow:: PathNode sink2 |
204- bc .hasFlowPath ( source2 , sink2 ) and
205- sink2 .getNode ( ) .asExpr ( ) = va
206- ) and
207- not exists ( SSLFlowConfig sc , DataFlow:: PathNode source3 , DataFlow:: PathNode sink3 |
208- sc .hasFlowPath ( source3 , sink3 ) and
209- sink3 .getNode ( ) .asExpr ( ) = va
210- )
205+ exists ( BasicAuthFlowConfig bc | bc .hasFlowTo ( sink .getNode ( ) ) ) and
206+ not exists ( SSLFlowConfig sc | sc .hasFlowTo ( sink .getNode ( ) ) )
211207select sink .getNode ( ) , source , sink , "Insecure LDAP authentication from $@." , source .getNode ( ) ,
212208 "LDAP connection string"
0 commit comments