|
| 1 | +/** |
| 2 | + * Provides default sources, sinks and sanitizers for detecting |
| 3 | + * LDAP Injections, as well as extension points for adding your own |
| 4 | + */ |
| 5 | + |
| 6 | +private import codeql.ruby.Concepts |
| 7 | +private import codeql.ruby.DataFlow |
| 8 | +private import codeql.ruby.dataflow.BarrierGuards |
| 9 | +private import codeql.ruby.dataflow.RemoteFlowSources |
| 10 | +private import codeql.ruby.ApiGraphs |
| 11 | + |
| 12 | +/** |
| 13 | + * Provides default sources, sinks and sanitizers for detecting |
| 14 | + * LDAP Injections, as well as extension points for adding your own |
| 15 | + */ |
| 16 | +module LdapInjection { |
| 17 | + /** A data flow source for LDAP Injection vulnerabilities */ |
| 18 | + abstract class Source extends DataFlow::Node { } |
| 19 | + |
| 20 | + /** A data flow sink for LDAP Injection vulnerabilities */ |
| 21 | + abstract class Sink extends DataFlow::Node { } |
| 22 | + |
| 23 | + /** A sanitizer for LDAP Injection vulnerabilities. */ |
| 24 | + abstract class Sanitizer extends DataFlow::Node { } |
| 25 | + |
| 26 | + /** |
| 27 | + * Additional taint steps for "LDAP Injection" vulnerabilities. |
| 28 | + */ |
| 29 | + predicate isAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) { |
| 30 | + attributeArrayTaintStep(nodeFrom, nodeTo) |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Additional taint step to handle elements inside an array, |
| 35 | + * specifically in the context of the following LDAP search function: |
| 36 | + * |
| 37 | + * ldap.search(base: "", filter: "", attributes: [name]) |
| 38 | + */ |
| 39 | + private predicate attributeArrayTaintStep(DataFlow::Node n1, DataFlow::Node n2) { |
| 40 | + exists(DataFlow::CallNode filterCall | |
| 41 | + filterCall.getMethodName() = "[]" and |
| 42 | + n1 = filterCall.getArgument(_) and |
| 43 | + n2 = filterCall |
| 44 | + ) |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * A source of remote user input, considered as a flow source. |
| 49 | + */ |
| 50 | + private class RemoteFlowSourceAsSource extends Source, RemoteFlowSource { } |
| 51 | + |
| 52 | + /** |
| 53 | + * An LDAP query execution considered as a flow sink. |
| 54 | + */ |
| 55 | + private class LdapExecutionAsSink extends Sink { |
| 56 | + LdapExecutionAsSink() { this = any(LdapExecution l).getQuery() } |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * A comparison with a constant string, considered as a sanitizer-guard. |
| 61 | + */ |
| 62 | + private class StringConstCompareAsSanitizerGuard extends Sanitizer, StringConstCompareBarrier { } |
| 63 | + |
| 64 | + /** |
| 65 | + * An inclusion check against an array of constant strings, considered as a |
| 66 | + * sanitizer-guard. |
| 67 | + */ |
| 68 | + private class StringConstArrayInclusionCallAsSanitizer extends Sanitizer, |
| 69 | + StringConstArrayInclusionCallBarrier |
| 70 | + { } |
| 71 | + |
| 72 | + /** |
| 73 | + * A call to `Net::LDAP::Filter.escape`, considered as a sanitizer. |
| 74 | + */ |
| 75 | + class NetLdapFilterEscapeSanitization extends Sanitizer { |
| 76 | + NetLdapFilterEscapeSanitization() { |
| 77 | + this = |
| 78 | + API::getTopLevelMember("Net").getMember("LDAP").getMember("Filter").getAMethodCall("escape") |
| 79 | + } |
| 80 | + } |
| 81 | +} |
0 commit comments