Skip to content

Cherry-pick internal commits (release/9.0) - #67805

Merged
DeagleGross merged 2 commits into
dotnet:mainfrom
DeagleGross:deaglegross/cherry-pick-pr-67795
Jul 15, 2026
Merged

DeagleGross merged 2 commits into
dotnet:mainfrom
DeagleGross:deaglegross/cherry-pick-pr-67795

Conversation

@DeagleGross

Copy link
Copy Markdown
Member

See #67795

@DeagleGross
DeagleGross requested a review from rokonec July 15, 2026 07:38
@DeagleGross DeagleGross self-assigned this Jul 15, 2026
Copilot AI review requested due to automatic review settings July 15, 2026 07:38
@DeagleGross
DeagleGross requested a review from halter73 as a code owner July 15, 2026 07:38

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.

Pull request overview

This PR cherry-picks internal changes into release/9.0 to tighten LDAP-based role/claim resolution for Negotiate authentication by ensuring the authenticated principal’s realm matches the configured LDAP domain and by making nested-group traversal more deterministic.

Changes:

  • Skip LDAP claim resolution when the user name has no realm (@...) or when the realm doesn’t match LdapSettings.Domain (case-insensitive).
  • Resolve nested groups by doing a base-scope lookup against each group’s distinguished name (DN), and handle stale memberOf references.
  • Add/adjust tests to cover realm matching behavior and cache retrieval keyed by UPN-style names.
Show a summary per file
File Description
src/Security/Authentication/Negotiate/test/Negotiate.Test/NegotiateHandlerTests.cs Updates test identities/cache keys to use [email protected] to align with new realm requirements.
src/Security/Authentication/Negotiate/test/Negotiate.Test/LdapAdapterTests.cs Adds test coverage for realm mismatch/format skipping and cached-claim retrieval with realm casing variations.
src/Security/Authentication/Negotiate/src/Internal/LdapAdapter.cs Enforces realm/domain match before LDAP lookup and switches nested-group resolution to DN base-scope queries with stale-reference handling.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 1

Comment on lines +126 to +142
private static void GetNestedGroups(LdapConnection connection, ClaimsIdentity principal, string distinguishedName, string groupDN, string groupCN, ILogger logger, IList<string> retrievedClaims, HashSet<string> processedGroups)
{
retrievedClaims.Add(groupCN);

var filter = $"(&(objectClass=group)(sAMAccountName={EscapeLdapFilterValue(groupCN)}))"; // This is using ldap search query language, it is looking on the server for someUser
var searchRequest = new SearchRequest(distinguishedName, filter, SearchScope.Subtree);
var searchResponse = (SearchResponse)connection.SendRequest(searchRequest);
// Look up the group entry by its distinguished name using base scope:
// a base-scope read against the DN is the only LDAP operation that
// returns exactly the intended group object.
var searchRequest = new SearchRequest(groupDN, "(objectClass=group)", SearchScope.Base);
SearchResponse searchResponse;
try
{
searchResponse = (SearchResponse)connection.SendRequest(searchRequest);
}
catch (DirectoryOperationException ex) when (ex.Response is SearchResponse r && r.ResultCode == ResultCode.NoSuchObject)
{
// Stale memberOf reference: group no longer exists. Stop traversal of this branch.
logger.LogDebug("Stale memberOf reference: group with distinguished name '{GroupDN}' no longer exists; stopping traversal.", groupDN);;

@rokonec rokonec left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@DeagleGross
DeagleGross merged commit 1abace7 into dotnet:main Jul 15, 2026
24 checks passed
@DeagleGross
DeagleGross deleted the deaglegross/cherry-pick-pr-67795 branch July 15, 2026 14:01
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants