LDAP injection
Data read from an untrusted source is used in the construction of an LDAP query
Since R2023a
Description
This checker is deactivated in a default Polyspace® as You Code analysis. See Checkers Deactivated in Polyspace as You Code Analysis (Polyspace Access).
This defect occurs when data read from an untrusted source such as standard input is used in the construction of an LDAP query.
This defect checker detects the flow of data from an untrusted source to a function that constructs an LDAP query. The checker recognizes OpenLDAP search functions such as ldap_search()
, ldap_search_ext()
, and so on. In all search functions, the checker considers the second parameter (base) and the fourth parameter (search filter) as sensitive to untrusted inputs. Untrusted sources can include strings read from the standard input
stdin
using the fread()
or fgets()
function. Note that unlike other Bug Finder checkers, this checker skips functions not called directly or indirectly from the main
function (if there is a main
).
Note that the defect checker is not available in the Polyspace user interface and is disabled even if you select the value all
for the option Find defects (-checkers)
. For the issue to be detected, the checker must be enabled explicitly using the option -checkers LDAP_INJECTION
.
Risk
If you construct the search base or search filters in an LDAP query from user inputs but use the inputs directly in the LDAP query without any validation or sanitization, they are vulnerable to LDAP injection. A malicious user can inject unintended LDAP queries masquerading as input, which can compromise secure user information.
For instance, in this LDAP search filter, the variable
is obtained from user inputs. The search filter is vulnerable to LDAP injection.username
(&(name=username)(pass=password))
*)(name=*))(|(name=*
for username
, the search filter
becomes:(&(name=*)(name=*))(|(name=*)(pass=password))
password
.Fix
Validate user inputs if you use them in the construction of the search base or search filters in an LDAP query. For more information on how to make the checker aware of your validation functions, see the next section.
Extend Checker
If you validate user inputs using dedicated functions, you can make the LDAP injection checker aware of your validation functions. Suppose that the function ldap_validate_inputs
checks user inputs for malicious entries.
int ldap_validate_inputs( char *, /* String to check */ int); /* Length of string */
n
-th parameter of this function is the user input to validate. For instance, the first argument in the above signature could be the string to validate.To make the LDAP injection checker aware of this function:
In a file with extension
.dl
, add:If.include "models/interfaces/ldap.dl" Ldap.Basic.sanitizing("ldap_validate_inputs", $OutParameterDeref(n-1)).
is 1 (that is, the first parameters of the function is the parameter of interest), then the statement becomes:n
.include "models/interfaces/ldap.dl" Ldap.Basic.sanitizing("ldap_validate_inputs", $OutParameterDeref(0)).
Specify this file using the option
-code-behavior-specifications
. For instance, if the file is namedldapAdditionalFunctions.dl
, use the analysis option:-code-behavior-specifications ldapAdditionalFunctions.dl
Examples
Result Information
Group: Security |
Language: C | C++ |
Default: Off |
Command-Line Syntax:
LDAP_INJECTION |
Impact: High |
Version History
Introduced in R2023a
See Also
Topics
- Interpret Bug Finder Results in Polyspace Desktop User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Results in Polyspace User Interface Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)