JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.
If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.
If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.
| CodeSonar® 9.2p0 | CONFIDENTIAL | CodeSecure Inc |
Potentially-tainted data is used to construct an LDAP statement.
| Class Name | LDAP Injection | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Significance | security | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Mnemonic | IO.INJ.LDAP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Categories |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Availability | Available for C and C++. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Enabling | Checks for this warning class are enabled by
default. To disable them, add the following WARNING_FILTER rule to the
project configuration file.
WARNING_FILTER += discard class="LDAP Injection" |
In the following example, the code constructs an LDAP query based on user input. In normal usage the user provides an ID number, then the code displays the DN fields of any LDAP records with that ID number. However, an attacker could use a malicious input such as "*" to reveal far more of the directory than the code author intended.
#include <stdlib.h> #include <stdio.h> #include "math.h" #ifdef HAVE_LDAP_H #include "ldap.h" #else /* Provide minimal declarations so this can compile even if openldap * headers are not available. */ typedef struct ldap LDAP; typedef struct ldapmsg LDAPMessage; typedef struct berelement BerElement; typedef struct ldapmsg LDAPMessage; #define LBER_INT_T int #define LBER_LEN_T long typedef unsigned LBER_LEN_T ber_len_t; typedef LBER_INT_T ber_int_t; #define LDAP_SCOPE_SUBTREE ((ber_int_t) 0x0002) #define LDAP_SUCCESS 0x00 #define LDAP_NO_LIMIT 0 typedef struct berval { ber_len_t bv_len; char *bv_val; } BerValue; typedef struct ldapcontrol { char * ldctl_oid; /* numericoid of control */ struct berval ldctl_value; /* encoded value of control */ char ldctl_iscritical; /* criticality */ } LDAPControl; #define LDAP_CONST const int ldap_search_ext_s( LDAP *ld, LDAP_CONST char *base, int scope, LDAP_CONST char *filter, char **attrs, int attrsonly, LDAPControl **serverctrls, LDAPControl **clientctrls, struct timeval *timeout, int sizelimit, LDAPMessage **res ); LDAPMessage * ldap_first_message ( LDAP *ld, LDAPMessage *chain ); LDAPMessage * ldap_next_message ( LDAP *ld, LDAPMessage *msg ); char * ldap_get_dn ( LDAP *ld, LDAPMessage *entry ); void ldap_memfree ( void* p ); char * ldap_first_attribute ( LDAP *ld, LDAPMessage *entry, BerElement **ber ); char * ldap_next_attribute ( LDAP *ld, LDAPMessage *entry, BerElement *ber ); struct berval ** ldap_get_values_len ( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target ); #endif void lookup_by_idnum(LDAP *ld ){ char filter[256]; char idnum[128]; LDAPMessage *res_msg, *msg; BerElement *berel; int retval, i; char *att, *dn; struct berval **attvals; printf("what is the ID number?\n"); if (!fgets(idnum, 128, stdin)) return ; sprintf(filter, "(IDnum=%s)", idnum); retval=ldap_search_ext_s(ld, "dc=myserver,dc=example,dc=com", LDAP_SCOPE_SUBTREE, filter, NULL, 0, NULL, NULL, NULL, LDAP_NO_LIMIT, &res_msg ); // LDAP Injection Warning Here if (retval != LDAP_SUCCESS) { for ( msg = ldap_first_message( ld, res_msg ); msg != NULL; msg = ldap_next_message( ld, msg ) ) { if (( dn = ldap_get_dn( ld, msg )) != NULL ) { printf( "dn: %s\n", dn ); ldap_memfree( dn ); } for ( att = ldap_first_attribute( ld, msg, &berel ); att != NULL; att = ldap_next_attribute( ld, msg, berel ) ) { if ((attvals = ldap_get_values_len( ld, msg, att ))!= NULL ) { for ( i = 0; attvals[ i ] != NULL; i++ ) { printf( "%s: %s\n", att, attvals[ i ]->bv_val ); } } } } } exit(0); }
CodeSonar ships with library models that allow it to recognize functions such as LDAP ldap_search_ext() that use one or more of their parameters to construct an LDAP statement. If one of these functions is called with a tainted value in one of those parameter positions, a warning will be issued.
If you have created a custom library model for some function f() in terms of one of these existing models, calls to f() will also be capable of triggering LDAP Injection warnings.
The following configuration file parameters affect checks for this warning class.
To report problems with this documentation, please visit https://support.codesecure.com/.