dotnet / dotnet/runtime

System.DirectoryServices.Protocols.SearchRequest Filter does not allow redundant parentheses unlike on Windows

Open
#127,168 4 comments 0 reactions 0 assignees View on GitHub
area-System.DirectoryServices help wanted
Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Description

### Description

On windows, the `System.DirectoryServices.Protocols.SearchRequest` `Filter` property allows the filter to have redundant parens.

For example,

```
((((samaccountname=example))))
```

is a legal LDAP filter on Windows, but not on Linux. Exactly one outermost parenthetical is required. This also carries to nested parentheticals.

```
&(objectclass=user)((((samaccountname=example))))
```

is also legal in Windows but not on Linux.

### Reproduction Steps

using the following `docker-compose.yml` to create an LDAP server on localhost:

```yml
services:
smblds:
environment:
- INSECURE_LDAP=true
image: 'smblds/smblds:latest'
ports:
- 389:389
- 636:636
```

Invoke the following (using `pwsh` to demonstrate).

```pwsh
$assemblyPath = "[YourPathGoesHere]/System.DirectoryServices.Protocols.dll"
Add-Type -path $assemblyPath

# default credentials for `smblds` for testing purposes.
$credential = [Management.Automation.PSCredential]::new('SAMDOM\Administrator', (ConvertTo-SecureString 'Passw0rd' -AsPlainText -Force))
$identifier = [System.DirectoryServices.Protocols.LdapDirectoryIdentifier]::new('localhost', 389)
$conn = [System.DirectoryServices.Protocols.LDAPConnection]::new($identifier, $credential, 'Basic')
# fetch RootDSE
$conn.SendRequest([System.DirectoryServices.Protocols.SearchRequest]::new($null, "((objectClass=*))", "base", "*"))
```

Works fine in pwsh (which uses netcore) and PS5.1 (which uses framework) but fails on linux.

### Expected behavior

Return RootDSE searchresponse.

### Actual behavior

> MethodInvocationException: Exception calling "SendRequest" with "1" argument(s): "The search filter is invalid."

### Regression?

_No response_

### Known Workarounds

_No response_

### Configuration

Ubuntu 22.04, .NET 8.0, x64

### Other information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.