FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codeql/java/ql/src/Security/CWE/CWE-090/LdapInjectionJndi.java at main · github/codeql · GitHub
github
codeql
Repository navigation
Code
Issues
1k
(1k)
Pull requests
485
(485)
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
codeql
/
java
/
ql
/
src
/
Security
/
CWE
/
CWE-090
/
LdapInjectionJndi.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
34 lines (25 loc) · 1.31 KB
Breadcrumbs
codeql
/
java
/
ql
/
src
/
Security
/
CWE
/
CWE-090
/
LdapInjectionJndi.java
Copy path
File metadata and controls
34 lines (25 loc) · 1.31 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import
javax
.
naming
.
directory
.
DirContext
;
import
org
.
owasp
.
esapi
.
Encoder
;
import
org
.
owasp
.
esapi
.
reference
.
DefaultEncoder
;
public
void
ldapQueryBad
(
HttpServletRequest
request
,
DirContext
ctx
)
throws
NamingException
{
String
organizationName
=
request
.
getParameter
(
"organization_name"
);
String
username
=
request
.
getParameter
(
"username"
);
// BAD: User input used in DN (Distinguished Name) without encoding
String
dn
=
"OU=People,O="
+
organizationName
;
// BAD: User input used in search filter without encoding
String
filter
=
"username="
+
userName
;
ctx
.
search
(
dn
,
filter
,
new
SearchControls
());
}
public
void
ldapQueryGood
(
HttpServletRequest
request
,
DirContext
ctx
)
throws
NamingException
{
String
organizationName
=
request
.
getParameter
(
"organization_name"
);
String
username
=
request
.
getParameter
(
"username"
);
// ESAPI encoder
Encoder
encoder
=
DefaultEncoder
.
getInstance
();
// GOOD: Organization name is encoded before being used in DN
String
safeOrganizationName
=
encoder
.
encodeForDN
(
organizationName
);
String
safeDn
=
"OU=People,O="
+
safeOrganizationName
;
// GOOD: User input is encoded before being used in search filter
String
safeUsername
=
encoder
.
encodeForLDAP
(
username
);
String
safeFilter
=
"username="
+
safeUsername
;
ctx
.
search
(
safeDn
,
safeFilter
,
new
SearchControls
());
}
Back
|
FazBrowse Home
|
New Git URL