spring-projects / spring-projects/spring-security
Explicitly Construct DirContextAdapter
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.6k
- Forks
- 6.3k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 52
Description
SpringSecurityLdapTemplate explicitly includes the RETURN_OBJECT flag in the SearchControls in order to allow DefaultDirObjectFactory to instantiate an instance of DirContextAdapter when iterating over the SearchResults.
This is convenient and works as intended with the JNDI mechanisms. However, JNDI has some flaws in security. If a malicious user is able to write arbitrary attributes to the LDAP User and the Java Schema is added tot he LDAP instance, then the malicious user leverage built in JDK Deserialization to execute arbitrary code.
Rather than relying on Java Internals to instantiate DirContextAdapter we can instantiate it directly . This works because we know the type of Object that should be initialized. It allows us to remove the RETURN_OBJECT flag which prevents the exploit.
NOTE The risk of this exploit is rather low, because for it to work the user needs to have gained write access to a user in the LDAP instance used to authenticate applications. It also requires the Java LDAP Schema to be installed. However, because the steps to mitigate this are relatively straightforward, we are making these changes to be defensive.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in ldap/src/main/java/org/springframework/security/ldap/SpringSecurityLdapTemplate.java, especially the SearchControls setup and SearchResults iteration linked in the issue. Trace how DirContextAdapter is obtained, then verify the LDAP search no longer relies on JNDI object instantiation or the RETURN_OBJECT flag while still producing the expected adapter.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend, security
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100