spring-projects / spring-projects/spring-security

SEC-2679: Unable to start embedded LDAP server if root contains only a single DC component

Open
#2,899 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

in: ldap type: bug type: jira
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

Keith Gregory (Migrated from SEC-2679) said:

When attempting to create an embedded LDAP server using the following specification:

<security:ldap-server id="embeddedLDAP" root="dc=example" />

You receive the following exception:

java.lang.StringIndexOutOfBoundsException: String index out of range: -4
    at java.lang.String.substring(String.java:1937)
    at org.springframework.security.ldap.server.ApacheDSContainer.start(ApacheDSContainer.java:190)
    at org.springframework.security.ldap.server.ApacheDSContainer.afterPropertiesSet(ApacheDSContainer.java:130)
...

If you look at the relevant line in ApacheDSContainer, you'll see the following:

                LdapDN dn = new LdapDN(root);
                Assert.isTrue(root.startsWith("dc="));
                String dc = root.substring(3,root.indexOf(','));

In other words, this code always assumes that the root entry will contain at least two dc elements, separated by a comma. While "real" domains will always have at least two components (eg: com.example), local directory servers may not.

I would guess that you can fix simply by looking for first occurrence of a comma or end of string, but have not tried this. The ApacheDS server does not appear to have any limitation on number of root dc components.

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 ApacheDSContainer.java at the parsing in start(), where the issue identifies the failing substring call for a root such as dc=example. Verify the embedded LDAP startup path with a single-DC root and consider the change complete when that server starts without the StringIndexOutOfBoundsException.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.