Security

What is Improper Neutralization of Special (CWE-90)?

Improper Neutralization of Special Elements used in an LDAP Query ('LDAP Injection') (CWE-90) is a type of A05:2025 - Injection vulnerability that occurs...

SP
Shreya Pillai July 27, 2026 5 min read Security
AI-friendly summary

What it is: Improper Neutralization of Special Elements used in an LDAP Query ('LDAP Injection') (CWE-90) is a type of A05:2025 - Injection vulnerability that occurs when the product constructs all or part of an LDAP query using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements.

Why it matters: Improper Neutralization of Special Elements used in an LDAP Query ('LDAP Injection') can lead to Execute Unauthorized Code or Commands, Read Application Data, and Modify Application Data.

How to fix it: To fix Improper Neutralization of Special Elements used in an LDAP Query ('LDAP Injection'), assume all input is malicious, use an "accept known good" input validation strategy, and reject any input that does not strictly conform to specifications.

TL;DR: Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) (CWE-90) occurs when a product constructs all or part of an LDAP query using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements.

Field Value
CWE ID CWE-90
OWASP Category A05:2025 - Injection
CAPEC CAPEC-136
Typical Severity Critical
Affected Technologies LDAP, Active Directory, Lightweight Directory Access Protocol
Detection Difficulty Moderate
Last Updated 2026-07-27

What is Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’)?

Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) (CWE-90) is a type of A05:2025 - Injection vulnerability that occurs when the product constructs all or part of an LDAP query using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements. As defined by the MITRE Corporation under CWE-90, and classified by the OWASP Foundation under A05:2025 - Injection.

Quick Summary

Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) (CWE-90) is a critical vulnerability that can lead to Execute Unauthorized Code or Commands, Read Application Data, and Modify Application Data. It occurs when a product constructs all or part of an LDAP query using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements.

Jump to: Quick Summary · Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) Overview · How Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) Works · Business Impact of Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) · Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) Attack Scenario · How to Detect Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) · How to Fix Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) · Framework-Specific Fixes for Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) · How to Ask AI to Check Your Code for Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) · Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) Best Practices Checklist · Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) FAQ · Vulnerabilities Related to Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) · References · Scan Your Own Site

Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) Overview

What: Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) (CWE-90) is a type of A05:2025 - Injection vulnerability that occurs when the product constructs all or part of an LDAP query using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements.

Why it matters: Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) can lead to Execute Unauthorized Code or Commands, Read Application Data, and Modify Application Data.

Where it occurs: Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) typically occurs when a product constructs all or part of an LDAP query using externally-influenced input from an upstream component.

Who is affected: Any system that uses LDAP queries and does not properly neutralize special elements can be affected by this vulnerability.

Who is NOT affected: Systems that never construct paths/queries/commands from external input, such as those already using secure coding practices, are not affected by this vulnerability.

How Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) Works

Root Cause

Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) occurs when a product constructs all or part of an LDAP query using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements.

Attack Flow

  1. An attacker injects malicious code into the LDAP query.
  2. The product constructs the LDAP query using the injected malicious code.
  3. The product sends the constructed LDAP query to a downstream component.
  4. The downstream component executes the LDAP query, which leads to Execute Unauthorized Code or Commands, Read Application Data, and Modify Application Data.

Prerequisites to Exploit

  • An attacker must be able to inject malicious code into the LDAP query.
  • The product must construct all or part of the LDAP query using externally-influenced input from an upstream component.
  • The downstream component must execute the LDAP query without proper neutralization of special elements.

Vulnerable Code

import ldap3

# Create a connection to the LDAP server
conn = ldap3.Connection('ldap://example.com', auto_bind=True)

# Inject malicious code into the LDAP query
query = '(objectClass=*) AND (cn=*)'

# Send the constructed LDAP query to the downstream component
conn.search(search_filter=query, search_base='dc=example,dc=com')

Secure Code

import ldap3

# Create a connection to the LDAP server
conn = ldap3.Connection('ldap://example.com', auto_bind=True)

# Sanitize user input and construct a secure LDAP query
query = '(objectClass=*)'

# Send the constructed LDAP query to the downstream component
conn.search(search_filter=query, search_base='dc=example,dc=com')

Secure Code Explanation

The secure code sanitizes user input and constructs a secure LDAP query by removing special elements. This prevents an attacker from injecting malicious code into the LDAP query.

Business Impact of Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’)

  • Confidentiality: An attacker can read sensitive data, such as passwords or credit card numbers.
  • Integrity: An attacker can modify application data, such as user accounts or database records.
  • Availability: An attacker can disrupt the availability of the system by causing it to crash or become unresponsive.

Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) Attack Scenario

  1. An attacker injects malicious code into the LDAP query.
  2. The product constructs the LDAP query using the injected malicious code.
  3. The product sends the constructed LDAP query to a downstream component.
  4. The downstream component executes the LDAP query, which leads to Execute Unauthorized Code or Commands, Read Application Data, and Modify Application Data.

How to Detect Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’)

Manual Testing

  • Review the code for any signs of insecure coding practices.
  • Test the system by injecting malicious code into the LDAP query.
  • Verify that the system properly neutralizes special elements.

Automated Scanners (SAST / DAST)

  • Use a static analysis tool to identify potential vulnerabilities in the code.
  • Use a dynamic testing tool to simulate an attack on the system and verify its security.

PenScan Detection

PenScan’s scanner engines actively test for this issue.

False Positive Guidance

When reviewing the results of automated scanners, be aware that some false positives may occur. For example, if the pattern looks risky but is actually safe due to context a scanner can’t see.

How to Fix Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’)

  • Assume all input is malicious.
  • Use an “accept known good” input validation strategy.
  • Reject any input that does not strictly conform to specifications.

Framework-Specific Fixes for Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’)

Java

import javax.naming.directory.DirContext;

// Create a connection to the LDAP server
DirContext ctx = new InitialDirContext(env);

// Sanitize user input and construct a secure LDAP query
String query = "(objectClass=*)";

// Send the constructed LDAP query to the downstream component
ctx.search(searchFilter=query, searchBase="dc=example,dc=com");

Node.js

const ldap = require('ldapjs');

// Create a connection to the LDAP server
const client = ldap.createClient({
  url: 'ldap://example.com',
});

// Sanitize user input and construct a secure LDAP query
const query = '(objectClass=*)';

// Send the constructed LDAP query to the downstream component
client.search(searchFilter=query, searchBase='dc=example,dc=com', callback(err, res) {
  // Handle the result of the search operation
});

Python/Django

import ldap3

# Create a connection to the LDAP server
conn = ldap3.Connection('ldap://example.com', auto_bind=True)

# Sanitize user input and construct a secure LDAP query
query = '(objectClass=*)'

# Send the constructed LDAP query to the downstream component
conn.search(search_filter=query, search_base='dc=example,dc=com')

PHP

<?php

// Create a connection to the LDAP server
$ldap_conn = ldap_connect('ldap://example.com');

// Sanitize user input and construct a secure LDAP query
$query = '(objectClass=*)';

// Send the constructed LDAP query to the downstream component
ldap_search($ldap_conn, 'dc=example,dc=com', $query);

How to Ask AI to Check Your Code for Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’)

You can use AI to check your code for Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) by reviewing the code with a tool that identifies potential vulnerabilities and rewriting it using secure coding practices.

Copy-paste prompt

Review the following [language] code block for potential CWE-90 Improper Neutralization of Special Elements used in an LDAP Query ('LDAP Injection') vulnerabilities and rewrite it using secure coding practices: [paste code here]

Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) Best Practices Checklist

✅ Always sanitize user input before constructing an LDAP query. ✅ Use an “accept known good” input validation strategy to ensure that only expected input is processed. ✅ Reject any input that does not strictly conform to specifications.

Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) FAQ

How does Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) occur?

Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) occurs when the product constructs all or part of an LDAP query using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements.

What are the consequences of Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’)?

The consequences of Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) include Execute Unauthorized Code or Commands, Read Application Data, and Modify Application Data.

How can I detect Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’)?

You can detect Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) through manual testing, automated scanners (SAST / DAST), and PenScan detection.

How can I fix Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’)?

You can fix Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) by assuming all input is malicious, using an “accept known good” input validation strategy, and rejecting any input that does not strictly conform to specifications.

What are the business impacts of Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’)?

The business impacts of Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) include financial losses, compliance issues, and reputational damage.

Can you provide a real-world example of Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’)?

Yes, a real-world example of Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) is when an attacker injects malicious code into an LDAP query to gain unauthorized access to sensitive data.

How can I use AI to check my code for Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’)?

You can use AI to check your code for Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) by reviewing the code with a tool that identifies potential vulnerabilities and rewriting it using secure coding practices.

What are some best practices for preventing Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’)?

Some best practices for preventing Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) include validating all input, sanitizing user input, and using secure coding practices.

CWE Name Relationship
CWE-943 Improper Neutralization of Special Elements in Data Query Logic (ChildOf)  

References

Scan Your Own Site

Manual code review catches what you know to look for. An automated scan catches what you didn’t. Scan your own website using PenScan to find Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’) and other risks before an attacker does.