Skip to content

Do not emit or traverse non-security-enabled groups in Negotiate LDAP claims - #69955

Open
rokonec wants to merge 3 commits into
dotnet:mainfrom
rokonec:rokonec/negotiate-ldap-security-enabled-traversal
Open

rokonec wants to merge 3 commits into
dotnet:mainfrom
rokonec:rokonec/negotiate-ldap-security-enabled-traversal

Conversation

@rokonec

@rokonec rokonec commented Oct 21, 2026

Copy link
Copy Markdown
Member
  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Do not emit or traverse non-security-enabled groups in Negotiate LDAP claims

Description

When EnableLdap is used, group memberships are resolved by following memberOf links. Active Directory computes the Windows token over security-enabled groups only, so a group that is not security-enabled (a distribution group) is not part of the expansion and nothing is reachable through it. The LDAP path did not make that distinction.

This change makes LdapAdapter consistent with that model:

  • Every group, direct or nested, is resolved through GetGroups (renamed from GetNestedGroups), including when IgnoreNestedGroups is true. In that mode only the recursion is skipped, not the group check.
  • groupType is requested in the existing base-scope read, so there is no additional LDAP round trip.
  • A group that is not security-enabled produces no role claim and its memberOf links are not followed.
  • A missing or unparsable groupType (non-Active Directory servers) fails open, so behavior there is unchanged. The bit test is done in C# rather than with the AD-specific bitwise matching rule.
  • The AppContext switch Microsoft.AspNetCore.Authentication.Negotiate.AllowNonSecurityEnabledGroupClaims restores the previous behavior (emit and traverse every group). It is read once into a static field.
  • The omission is logged at Debug.

This is the same behavior that is already in release/8.0 and release/9.0, plus the traversal change on top, so main and release/10.0 currently lack the groupType handling this PR depends on. Because of that this PR contains the forward port and the traversal change together.

One behavior to be aware of: a group whose entry no longer exists (stale memberOf reference) no longer produces a role claim, because the claim is now added after the group is read. This matches the release branches.

Tests

GetGroups is exercised through a LdapConnection subclass that overrides SendRequest. The System.DirectoryServices.Protocols response types have no public constructors, so responses are built reflectively in one helper. The new tests cover:

  • distribution group: not emitted, parents not traversed
  • security group: emitted, parents traversed
  • security group reachable only through a distribution group: not emitted
  • opt-out switch: emitted and traversed
  • missing groupType: emitted and traversed
  • IgnoreNestedGroups both values
  • IsSecurityGroup and ShouldEmitRoleClaim value matrices

Validation on this branch:

  • dotnet test src\Security\Authentication\Negotiate\test\Negotiate.Test\Microsoft.AspNetCore.Authentication.Negotiate.Test.csproj: Passed 96, Failed 0.
  • With only the traversal return; removed, exactly 2 tests fail (GetGroups_DistributionGroup_IsNotEmittedAndItsParentsAreNotTraversed and GetGroups_SecurityGroupBehindADistributionGroup_IsNotReached), with the extra role leaking, and the other tests still pass. The behavior was also checked end to end against a Samba AD domain controller.

Fixes #69953

rokonec and others added 2 commits October 21, 2026 12:04
… claims

Resolve every group through GetGroups, read its groupType in the existing
base-scope lookup, and stop both the role claim and the traversal of its
memberOf links when the group is not security-enabled. This matches how
Active Directory computes the Windows token, where such groups are not part
of the expansion graph.

Behavior is unchanged when the groupType attribute is absent (non-AD servers)
or when the AppContext switch
Microsoft.AspNetCore.Authentication.Negotiate.AllowNonSecurityEnabledGroupClaims
is set.

Co-authored-by: Copilot <[email protected]>
Drive GetGroups through a LdapConnection subclass that overrides SendRequest,
with SearchResponse objects built reflectively in one test helper, because
the System.DirectoryServices.Protocols response types have no public
constructors.

Co-authored-by: Copilot <[email protected]>
@github-actions github-actions Bot added the area-auth Includes: authentication, authorization, OAuth, OIDC, and access token validation label Oct 21, 2026
@rokonec
rokonec marked this pull request as ready for review October 21, 2026 10:58
Copilot AI balanced review requested due to automatic review settings October 21, 2026 10:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

A non-AD compatibility regression remains unresolved, and independent validation of the changed default behavior is incomplete.

1 open issue
What changed in this PR

Updates Negotiate LDAP role resolution to omit distribution groups and stop traversing their parents.

Changes:

  • Checks group type for direct and nested memberships.
  • Adds a compatibility switch and debug logging.
  • Adds LDAP traversal and group-type tests.
File Description
src/​Security/​Authentication/​Negotiate/​test/​Negotiate.Test/​Microsoft.AspNetCore.Authentication.Negotiate.Test.csproj Adds the LDAP protocol test dependency.
src/​Security/​Authentication/​Negotiate/​test/​Negotiate.Test/​LdapAdapterTests.cs Tests filtering, traversal, and compatibility behavior.
src/​Security/​Authentication/​Negotiate/​src/​Internal/​LdapAdapter.cs Filters group claims and gates parent traversal.

Review effort: Balanced

@DeagleGross
DeagleGross self-requested a review October 23, 2026 14:48
@rokonec

rokonec commented Oct 24, 2026

Copy link
Copy Markdown
Member Author

@copilot resolve the merge conflicts in this pull request

Resolve overlapping LDAP adapter and test updates while preserving the group traversal change and current main behavior.

Co-authored-by: Copilot <[email protected]>
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service Bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Nov 2, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-auth Includes: authentication, authorization, OAuth, OIDC, and access token validation pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Negotiate LDAP: do not traverse parents of groups that are not security-enabled

3 participants