Skip to content

Commit 664c1eb

Browse files
committed
Add "" and nil as sources
1 parent f301e46 commit 664c1eb

File tree

4 files changed

+65
-2
lines changed

4 files changed

+65
-2
lines changed

ruby/ql/lib/codeql/ruby/security/ImproperLdapAuthCustomizations.qll

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ module ImproperLdapAuth {
2727
*/
2828
private class RemoteFlowSourceAsSource extends Source, RemoteFlowSource { }
2929

30+
/**
31+
* A source of empty input, considered as a flow source.
32+
*/
33+
private class EmptySourceAsSource extends Source, EmptySource { }
34+
35+
class EmptySource extends DataFlow::Node {
36+
/** Gets a string that describes the type of this remote flow source. */
37+
EmptySource() {
38+
(
39+
this.getConstantValue().isStringlikeValue("")
40+
or
41+
this.(DataFlow::ExprNode).getConstantValue().isNil()
42+
)
43+
}
44+
}
45+
3046
/**
3147
* An LDAP query execution considered as a flow sink.
3248
*/
@@ -44,5 +60,6 @@ module ImproperLdapAuth {
4460
* sanitizer-guard.
4561
*/
4662
private class StringConstArrayInclusionCallAsSanitizer extends Sanitizer,
47-
StringConstArrayInclusionCallBarrier { }
63+
StringConstArrayInclusionCallBarrier
64+
{ }
4865
}

ruby/ql/src/experimental/ldap-improper-auth/ImproperLdapAuth.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ import DataFlow::PathGraph
1717
from Configuration config, DataFlow::PathNode source, DataFlow::PathNode sink
1818
where config.hasFlowPath(source, sink)
1919
select sink.getNode(), source, sink, "This LDAP authencation depends on a $@.", source.getNode(),
20-
"user-provided value"
20+
"user-provided value or the password is empty"

ruby/ql/test/query-tests/experimental/ImproperLdapAuth/ImproperLdapAuth.expected

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ edges
55
| ImproperLdapAuth.rb:24:5:24:8 | pass | ImproperLdapAuth.rb:31:24:31:27 | pass |
66
| ImproperLdapAuth.rb:24:12:24:17 | call to params | ImproperLdapAuth.rb:24:12:24:24 | ...[...] |
77
| ImproperLdapAuth.rb:24:12:24:24 | ...[...] | ImproperLdapAuth.rb:24:5:24:8 | pass |
8+
| ImproperLdapAuth.rb:37:5:37:8 | pass | ImproperLdapAuth.rb:47:23:47:26 | pass |
9+
| ImproperLdapAuth.rb:37:12:37:14 | nil | ImproperLdapAuth.rb:37:5:37:8 | pass |
10+
| ImproperLdapAuth.rb:55:5:55:8 | pass | ImproperLdapAuth.rb:62:24:62:27 | pass |
11+
| ImproperLdapAuth.rb:55:12:55:13 | "" | ImproperLdapAuth.rb:55:5:55:8 | pass |
812
nodes
913
| ImproperLdapAuth.rb:5:5:5:8 | pass | semmle.label | pass |
1014
| ImproperLdapAuth.rb:5:12:5:17 | call to params | semmle.label | call to params |
@@ -14,7 +18,17 @@ nodes
1418
| ImproperLdapAuth.rb:24:12:24:17 | call to params | semmle.label | call to params |
1519
| ImproperLdapAuth.rb:24:12:24:24 | ...[...] | semmle.label | ...[...] |
1620
| ImproperLdapAuth.rb:31:24:31:27 | pass | semmle.label | pass |
21+
| ImproperLdapAuth.rb:37:5:37:8 | pass | semmle.label | pass |
22+
| ImproperLdapAuth.rb:37:12:37:14 | nil | semmle.label | nil |
23+
| ImproperLdapAuth.rb:47:23:47:26 | pass | semmle.label | pass |
24+
| ImproperLdapAuth.rb:55:5:55:8 | pass | semmle.label | pass |
25+
| ImproperLdapAuth.rb:55:12:55:13 | "" | semmle.label | "" |
26+
| ImproperLdapAuth.rb:62:24:62:27 | pass | semmle.label | pass |
1727
subpaths
1828
#select
1929
| ImproperLdapAuth.rb:15:23:15:26 | pass | ImproperLdapAuth.rb:5:12:5:17 | call to params | ImproperLdapAuth.rb:15:23:15:26 | pass | This LDAP authencation depends on a $@. | ImproperLdapAuth.rb:5:12:5:17 | call to params | user-provided value |
2030
| ImproperLdapAuth.rb:31:24:31:27 | pass | ImproperLdapAuth.rb:24:12:24:17 | call to params | ImproperLdapAuth.rb:31:24:31:27 | pass | This LDAP authencation depends on a $@. | ImproperLdapAuth.rb:24:12:24:17 | call to params | user-provided value |
31+
| ImproperLdapAuth.rb:47:23:47:26 | pass | ImproperLdapAuth.rb:37:12:37:14 | nil | ImproperLdapAuth.rb:47:23:47:26 | pass | This LDAP authencation depends on a $@. | ImproperLdapAuth.rb:37:12:37:14 | nil | user-provided value |
32+
| ImproperLdapAuth.rb:47:23:47:26 | pass | ImproperLdapAuth.rb:47:23:47:26 | pass | ImproperLdapAuth.rb:47:23:47:26 | pass | This LDAP authencation depends on a $@. | ImproperLdapAuth.rb:47:23:47:26 | pass | user-provided value |
33+
| ImproperLdapAuth.rb:62:24:62:27 | pass | ImproperLdapAuth.rb:55:12:55:13 | "" | ImproperLdapAuth.rb:62:24:62:27 | pass | This LDAP authencation depends on a $@. | ImproperLdapAuth.rb:55:12:55:13 | "" | user-provided value |
34+
| ImproperLdapAuth.rb:62:24:62:27 | pass | ImproperLdapAuth.rb:62:24:62:27 | pass | ImproperLdapAuth.rb:62:24:62:27 | pass | This LDAP authencation depends on a $@. | ImproperLdapAuth.rb:62:24:62:27 | pass | user-provided value |

ruby/ql/test/query-tests/experimental/ImproperLdapAuth/ImproperLdapAuth.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,38 @@ def some_request_handler
3131
ldap.auth "admin", pass
3232
ldap.bind
3333
end
34+
35+
def some_request_handler
36+
# An empty password is used
37+
pass = nil
38+
39+
# BAD: empty password
40+
ldap = Net::LDAP.new(
41+
host: 'ldap.example.com',
42+
port: 636,
43+
encryption: :simple_tls,
44+
auth: {
45+
method: :simple,
46+
username: 'uid=admin,dc=example,dc=com',
47+
password: pass
48+
}
49+
)
50+
ldap.bind
51+
end
52+
53+
def some_request_handler
54+
# An empty password is used
55+
pass = ""
56+
57+
# BAD: empty password
58+
ldap = Net::LDAP.new
59+
ldap.host = your_server_ip_address
60+
ldap.encryption(:method => :simple_tls)
61+
ldap.port = 639
62+
ldap.auth "admin", pass
63+
ldap.bind
64+
end
65+
3466
end
3567

3668
class BarController < ApplicationController

0 commit comments

Comments
 (0)