mirror of
https://github.com/github/codeql.git
synced 2025-12-22 03:36:30 +01:00
Query to detect LDAP injections in Java
Cleanup
This commit is contained in:
@@ -6,7 +6,6 @@ import semmle.code.java.frameworks.UnboundId
|
|||||||
import semmle.code.java.frameworks.SpringLdap
|
import semmle.code.java.frameworks.SpringLdap
|
||||||
import semmle.code.java.frameworks.ApacheLdap
|
import semmle.code.java.frameworks.ApacheLdap
|
||||||
|
|
||||||
|
|
||||||
/** Holds if the parameter of `c` at index `paramIndex` is varargs. */
|
/** Holds if the parameter of `c` at index `paramIndex` is varargs. */
|
||||||
bindingset[paramIndex]
|
bindingset[paramIndex]
|
||||||
predicate isVarargs(Callable c, int paramIndex) {
|
predicate isVarargs(Callable c, int paramIndex) {
|
||||||
@@ -20,8 +19,8 @@ abstract class LdapInjectionSource extends DataFlow::Node { }
|
|||||||
abstract class LdapInjectionSink extends DataFlow::ExprNode { }
|
abstract class LdapInjectionSink extends DataFlow::ExprNode { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A taint-tracking configuration for unvalidated user input that is used to construct LDAP queries.
|
* A taint-tracking configuration for unvalidated user input that is used to construct LDAP queries.
|
||||||
*/
|
*/
|
||||||
class LdapInjectionFlowConfig extends TaintTracking::Configuration {
|
class LdapInjectionFlowConfig extends TaintTracking::Configuration {
|
||||||
LdapInjectionFlowConfig() { this = "LdapInjectionFlowConfig" }
|
LdapInjectionFlowConfig() { this = "LdapInjectionFlowConfig" }
|
||||||
|
|
||||||
@@ -79,7 +78,7 @@ class JndiLdapInjectionSink extends LdapInjectionSink {
|
|||||||
|
|
|
|
||||||
m.getDeclaringType().getAnAncestor() instanceof TypeDirContext and
|
m.getDeclaringType().getAnAncestor() instanceof TypeDirContext and
|
||||||
m.hasName("search") and
|
m.hasName("search") and
|
||||||
index in [0..1]
|
index in [0 .. 1]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,16 +128,13 @@ class SpringLdapInjectionSink extends LdapInjectionSink {
|
|||||||
) and
|
) and
|
||||||
(
|
(
|
||||||
// Parameter index is 1 (DN or query) or 2 (filter) if method is not authenticate
|
// Parameter index is 1 (DN or query) or 2 (filter) if method is not authenticate
|
||||||
(
|
index in [0 .. 1] and
|
||||||
index in [0..1] and
|
not m instanceof MethodSpringLdapTemplateAuthenticate
|
||||||
not m instanceof MethodSpringLdapTemplateAuthenticate
|
or
|
||||||
) or
|
|
||||||
// But it's not the last parameter in case of authenticate method (last param is password)
|
// But it's not the last parameter in case of authenticate method (last param is password)
|
||||||
(
|
index in [0 .. 1] and
|
||||||
index in [0..1] and
|
index < m.getNumberOfParameters() - 1 and
|
||||||
index < m.getNumberOfParameters() - 1 and
|
m instanceof MethodSpringLdapTemplateAuthenticate
|
||||||
m instanceof MethodSpringLdapTemplateAuthenticate
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,5 @@ class TypeApacheSearchRequest extends Interface {
|
|||||||
|
|
||||||
/** The class `org.apache.directory.api.ldap.model.name.Dn`. */
|
/** The class `org.apache.directory.api.ldap.model.name.Dn`. */
|
||||||
class TypeApacheDn extends Class {
|
class TypeApacheDn extends Class {
|
||||||
TypeApacheDn() {
|
TypeApacheDn() { this.hasQualifiedName("org.apache.directory.api.ldap.model.name", "Dn") }
|
||||||
this.hasQualifiedName("org.apache.directory.api.ldap.model.name", "Dn")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,9 @@ import semmle.code.java.Member
|
|||||||
/*--- Types ---*/
|
/*--- Types ---*/
|
||||||
/** The class `org.springframework.ldap.core.LdapTemplate`. */
|
/** The class `org.springframework.ldap.core.LdapTemplate`. */
|
||||||
class TypeSpringLdapTemplate extends Class {
|
class TypeSpringLdapTemplate extends Class {
|
||||||
TypeSpringLdapTemplate() { this.hasQualifiedName("org.springframework.ldap.core", "LdapTemplate") }
|
TypeSpringLdapTemplate() {
|
||||||
|
this.hasQualifiedName("org.springframework.ldap.core", "LdapTemplate")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The class `org.springframework.ldap.query.LdapQueryBuilder`. */
|
/** The class `org.springframework.ldap.query.LdapQueryBuilder`. */
|
||||||
|
|||||||
Reference in New Issue
Block a user