spring-projects / spring-projects/spring-security

Explicitly Construct DirContextAdapter

Open
#4,157 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

in: ldap type: enhancement
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.