Skip to content

Commit d45d046

Browse files
committed
Add test file and .expected
1 parent d8bc818 commit d45d046

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
class FooController < ActionController::Base
2+
def some_request_handler
3+
# A string tainted by user input is used directly as DN
4+
# (i.e a remote flow source)
5+
dc = params[:dc]
6+
7+
# A string tainted by user input is used directly as search filter or attribute
8+
# (i.e a remote flow source)
9+
name = params[:user_name]
10+
11+
# LDAP Connection
12+
ldap = Net::LDAP.new(
13+
host: 'ldap.example.com',
14+
port: 636,
15+
encryption: :simple_tls,
16+
auth: {
17+
method: :simple,
18+
username: 'uid=admin,dc=example,dc=com',
19+
password: 'adminpassword'
20+
}
21+
)
22+
23+
# BAD: user input is used as DN
24+
# where dc is unsanitized
25+
ldap.search(base: "ou=people,dc=#{dc},dc=com", filter: "cn=George", attributes: [""])
26+
27+
# BAD: user input is used as search filter
28+
# where name is unsanitized
29+
ldap.search(base: "ou=people,dc=example,dc=com", filter: "cn=#{name}", attributes: [""])
30+
31+
# BAD: user input is used as attribute
32+
# where name is unsanitized
33+
ldap.search(base: "ou=people,dc=example,dc=com", filter: "cn=George", attributes: [name])
34+
35+
# BAD: user input is used as search filter
36+
# where name is unsanitized
37+
filter = Net::LDAP::Filter.eq('cn', name)
38+
ldap.search(base: "ou=people,dc=example,dc=com", filter: filter, attributes: [""])
39+
40+
# GOOD: user input is not used in the LDAP query
41+
result = ldap.search(base: "ou=people,dc=example,dc=com", filter: "cn=George", attributes: [""])
42+
end
43+
end
44+
45+
class BarController < ApplicationController
46+
def safe_paths
47+
dc = params[:dc]
48+
# GOOD: barrier guard prevents taint flow
49+
if dc == "example"
50+
base = "ou=people,dc=#{dc},dc=com"
51+
else
52+
base = "ou=people,dc=default,dc=com"
53+
end
54+
ldap.search(base: base, filter: "cn=George", attributes: [""])
55+
56+
57+
name = params[:user_name]
58+
# GOOD: barrier guard prevents taint flow
59+
name = if ["George", "Nicolas"].include? name
60+
name
61+
else
62+
name = "Guest"
63+
end
64+
result = ldap.search(base: "ou=people,dc=example,dc=com", filter: "cn=#{name}", attributes: [""])
65+
end
66+
end
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
edges
2+
| LdapInjection.rb:5:5:5:6 | dc | LdapInjection.rb:25:23:25:49 | "ou=people,dc=#{...},dc=com" |
3+
| LdapInjection.rb:5:10:5:15 | call to params | LdapInjection.rb:5:10:5:20 | ...[...] |
4+
| LdapInjection.rb:5:10:5:20 | ...[...] | LdapInjection.rb:5:5:5:6 | dc |
5+
| LdapInjection.rb:9:5:9:8 | name | LdapInjection.rb:29:62:29:73 | "cn=#{...}" |
6+
| LdapInjection.rb:9:5:9:8 | name | LdapInjection.rb:33:87:33:92 | call to [] |
7+
| LdapInjection.rb:9:5:9:8 | name | LdapInjection.rb:37:5:37:10 | filter |
8+
| LdapInjection.rb:9:12:9:17 | call to params | LdapInjection.rb:9:12:9:29 | ...[...] |
9+
| LdapInjection.rb:9:12:9:29 | ...[...] | LdapInjection.rb:9:5:9:8 | name |
10+
| LdapInjection.rb:37:5:37:10 | filter | LdapInjection.rb:38:62:38:67 | filter |
11+
nodes
12+
| LdapInjection.rb:5:5:5:6 | dc | semmle.label | dc |
13+
| LdapInjection.rb:5:10:5:15 | call to params | semmle.label | call to params |
14+
| LdapInjection.rb:5:10:5:20 | ...[...] | semmle.label | ...[...] |
15+
| LdapInjection.rb:9:5:9:8 | name | semmle.label | name |
16+
| LdapInjection.rb:9:12:9:17 | call to params | semmle.label | call to params |
17+
| LdapInjection.rb:9:12:9:29 | ...[...] | semmle.label | ...[...] |
18+
| LdapInjection.rb:25:23:25:49 | "ou=people,dc=#{...},dc=com" | semmle.label | "ou=people,dc=#{...},dc=com" |
19+
| LdapInjection.rb:29:62:29:73 | "cn=#{...}" | semmle.label | "cn=#{...}" |
20+
| LdapInjection.rb:33:87:33:92 | call to [] | semmle.label | call to [] |
21+
| LdapInjection.rb:37:5:37:10 | filter | semmle.label | filter |
22+
| LdapInjection.rb:38:62:38:67 | filter | semmle.label | filter |
23+
subpaths
24+
#select
25+
| LdapInjection.rb:25:23:25:49 | "ou=people,dc=#{...},dc=com" | LdapInjection.rb:5:10:5:15 | call to params | LdapInjection.rb:25:23:25:49 | "ou=people,dc=#{...},dc=com" | This LDAP query depends on a $@. | LdapInjection.rb:5:10:5:15 | call to params | user-provided value |
26+
| LdapInjection.rb:29:62:29:73 | "cn=#{...}" | LdapInjection.rb:9:12:9:17 | call to params | LdapInjection.rb:29:62:29:73 | "cn=#{...}" | This LDAP query depends on a $@. | LdapInjection.rb:9:12:9:17 | call to params | user-provided value |
27+
| LdapInjection.rb:33:87:33:92 | call to [] | LdapInjection.rb:9:12:9:17 | call to params | LdapInjection.rb:33:87:33:92 | call to [] | This LDAP query depends on a $@. | LdapInjection.rb:9:12:9:17 | call to params | user-provided value |
28+
| LdapInjection.rb:38:62:38:67 | filter | LdapInjection.rb:9:12:9:17 | call to params | LdapInjection.rb:38:62:38:67 | filter | This LDAP query depends on a $@. | LdapInjection.rb:9:12:9:17 | call to params | user-provided value |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
experimental/ldap-injection/LdapInjection.ql

0 commit comments

Comments
 (0)