Skip to content

Commit d4de5e3

Browse files
committed
refactoring and renamings in the ldap model
1 parent bcf4626 commit d4de5e3

File tree

5 files changed

+73
-109
lines changed

5 files changed

+73
-109
lines changed

javascript/ql/lib/javascript.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ import semmle.javascript.frameworks.History
9999
import semmle.javascript.frameworks.Immutable
100100
import semmle.javascript.frameworks.Knex
101101
import semmle.javascript.frameworks.LazyCache
102-
import semmle.javascript.frameworks.Ldapjs
102+
import semmle.javascript.frameworks.LDAPjs
103103
import semmle.javascript.frameworks.LodashUnderscore
104104
import semmle.javascript.frameworks.Logging
105105
import semmle.javascript.frameworks.HttpFrameworks
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* Provides classes for working with [LDAPjs](https://www.npmjs.com/package/ldapjs)
3+
*/
4+
5+
import javascript
6+
7+
module LDAPjs {
8+
/** Gets a reference to the ldapjs library. */
9+
API::Node ldapjs() { result = API::moduleImport("ldapjs") }
10+
11+
/** Gets an LDAPjs client. */
12+
private API::Node ldapClient() { result = ldapjs().getMember("createClient").getReturn() }
13+
14+
/** A call to a LDAPjs Client API method. */
15+
class ClientCall extends API::CallNode {
16+
string methodName;
17+
18+
ClientCall() {
19+
methodName = ["add", "bind", "compare", "del", "modify", "modifyDN", "search"] and
20+
this = ldapClient().getMember(methodName).getACall()
21+
}
22+
23+
string getMethodName() { result = methodName }
24+
}
25+
26+
/** A reference to a LDAPjs client `search` options. */
27+
class SearchOptions extends API::Node {
28+
ClientCall call;
29+
30+
SearchOptions() { call.getMethodName() = "search" and this = call.getParameter(1) }
31+
}
32+
33+
/** A creation of an LDAPjs filter, or object containing a filter, that doesn't sanitizes the input. */
34+
abstract class LDAPFilterStep extends DataFlow::Node {
35+
/** The input that creates (part of) an LDAPjs filter. */
36+
abstract DataFlow::Node getInput();
37+
38+
/** The resulting LDAPjs filter. */
39+
abstract DataFlow::Node getOutput();
40+
}
41+
42+
/** A call to the ldap utility method "parseFilter". */
43+
private class ParseFilter extends LDAPFilterStep, API::CallNode {
44+
ParseFilter() { this = ldapjs().getMember("parseFilter").getACall() }
45+
46+
override DataFlow::Node getInput() { result = this.getArgument(0) }
47+
48+
override DataFlow::Node getOutput() { result = this }
49+
}
50+
51+
/**
52+
* A filter used in call to "search" on an LDAPjs client.
53+
* We model that as a step from the ".filter" write to the options object itself.
54+
*/
55+
private class SearchFilter extends LDAPFilterStep {
56+
SearchOptions options;
57+
58+
SearchFilter() {
59+
options = ldapClient().getMember("search").getACall().getParameter(1) and
60+
this = options.getARhs()
61+
}
62+
63+
override DataFlow::Node getInput() { result = options.getMember("filter").getARhs() }
64+
65+
override DataFlow::Node getOutput() { result = this }
66+
}
67+
}

javascript/ql/lib/semmle/javascript/frameworks/Ldapjs.qll

Lines changed: 0 additions & 105 deletions
This file was deleted.

javascript/ql/lib/semmle/javascript/security/dataflow/SqlInjectionCustomizations.qll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ module SqlInjection {
4747
*/
4848
class LdapJSSink extends Sink {
4949
LdapJSSink() {
50-
this instanceof Ldapjs::LdapjsDNArgument
50+
// A distinguished name (DN) used in a call to the client API.
51+
this = any(LDAPjs::ClientCall call).getArgument(0)
5152
or
52-
this = any(Ldapjs::LdapjsSearchOptions opt).getARhs()
53+
// A search options object, which contains a filter and a baseDN.
54+
this = any(LDAPjs::SearchOptions opt).getARhs()
5355
}
5456
}
5557

javascript/ql/lib/semmle/javascript/security/dataflow/SqlInjectionQuery.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Configuration extends TaintTracking::Configuration {
2626
}
2727

2828
override predicate isAdditionalTaintStep(DataFlow::Node pred, DataFlow::Node succ) {
29-
exists(Ldapjs::LdapFilter filter |
29+
exists(LDAPjs::LDAPFilterStep filter |
3030
pred = filter.getInput() and
3131
succ = filter.getOutput()
3232
)

0 commit comments

Comments
 (0)