FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Java: Insecure LDAP authentication by luchua-bc · Pull Request #4854 · github/codeql · GitHub

/ codeql Public

Java: Insecure LDAP authentication - #4854

Merged
aschackmull merged 9 commits into
github:mainfrom
luchua-bc:java/insecure-ldap-auth
Feb 4, 2021
Merged

Java: Insecure LDAP authentication#4854
aschackmull merged 9 commits into
github:mainfrom
luchua-bc:java/insecure-ldap-auth

Conversation

Copy link
Copy Markdown
Contributor

When using the Java LDAP API to perform LDAPv3-style extended operations and controls like user profile retrieval, a context with connection properties including user credentials is started. Transmission of LDAP credentials in cleartext allows remote attackers to obtain sensitive information by sniffing the network.

This query detects transmission of cleartext credentials in LDAP authentication, which meets the following two criteria:

  1. Use the protocol "ldap" instead of "ldaps"
  2. Use "simple" authentication instead of SASL authentication using encrypted/hashed credentials

Please consider to merge the PR. Thanks.

smowton commented Dec 21, 2020

Copy link
Copy Markdown
Contributor

Acknowledged; will look at this on January 4th or later

Copy link
Copy Markdown
Contributor Author

Thanks @smowton. This is also my last planned PR before the holidays. Merry Christmas and Happy New Year!

@luchua-bc

smowton self-assigned this Jan 4, 2021

smowton commented Jan 4, 2021

Copy link
Copy Markdown
Contributor

Looks good, waiting on security-lab to look at the results now.

JarLob commented Jan 12, 2021

Copy link
Copy Markdown
Contributor

Hi @luchua-bc,
It looks like it is still possible to use an encrypted connection by setting Context.SECURITY_PROTOCOL to ssl even if the schema is ldap://. Could you please improve the query to take it into account?

Copy link
Copy Markdown
Contributor Author

Thanks @JarLob for reviewing this PR. I thought about this one when submitting the first version but finally decided not to include it since it's not that a common configuration. There is no GitHub repository found with this configuration during a quick search when I drafted the query.

However, it's nice to have it so that the query can be more comprehensive and can help to reduce possible false positives. I've made requested changes. Please review.

Cheers,
@luchua-bc

JarLob commented Jan 13, 2021
edited
Loading

Copy link
Copy Markdown
Contributor

The results are much better now! But it bugs me that the sink is .put(Context.PROVIDER_URL instead of the InitialDirContext constructor call. Could you please remove the side-conditions on the sink and additional taint step regarding SECURITY_PROTOCOL and SECURITY_AUTHENTICATION; instead, use a separate Configuration for each of them, and look for a sink which IS also a sink for SECURITY_AUTHENTICATION = simple AND PROVIDER_URL = ldap:// AND NOT SECURITY_PROTOCOL = ssl. It wouldn't warn in a case like:

Hashtable<String, String> env = new Hashtable<>();
setSSL(env);
env.put(Context.PROVIDER_URL, "ldap://blabla");
setBasicAuth(env);
userContext = new InitialLdapContext(env, null);

Copy link
Copy Markdown
Contributor Author

Sorry I don't quite get what you mean. Do you want to make the Hashtable env the sink? How can three configurations be made with the same sink? And what will be their source? Please provide more details. Thanks.

smowton commented Jan 14, 2021

Copy link
Copy Markdown
Contributor

The new InitialLdapContext(env, ...) call would be the sink, and env.put calls with an appropriate key would be an additional taint step. Look for "ldap://..." flowing to the sink, AND basic-authentication flowing to the sink, AND NOT SSL flowing to the sink. That means three configurations, differing by the env.put key they're sensitive to.

Copy link
Copy Markdown
Contributor Author

Thanks @smowton for the detailed explanation.

As the approach is quite different from my original thoughts, it took me some time to revamp the query. Although I'm still not entirely sure whether it's what we want, the new query does render desired results.

Please review. Thanks.

smowton commented Jan 27, 2021

Copy link
Copy Markdown
Contributor

I don't have any further comments; pinged a Java code-owner to take a look.

aschackmull merged commit 35e620a into github:main Feb 4, 2021
luchua-bc deleted the java/insecure-ldap-auth branch February 4, 2021 14:17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL