Repository navigation
Harden Negotiate LDAP role and identity validation - #10226
Merged
Merged
Conversation
…role claims to security-enabled groups
## Summary
`LdapAdapter` emitted every group in the user's `memberOf` as a role claim, including Active Directory **distribution groups**. The Windows Kerberos token carries only security-group SIDs, so a distribution group never becomes a role on Windows. On Linux the LDAP path granted it.
This breaks the documented contract in Role-based authorization ("Windows Authentication **security groups** as app roles"), which applies to `AddNegotiate()` regardless of platform.
## Fix
`GetNestedGroups` now requests `groupType` alongside `memberof` in the **existing** base-scope read, so there is **no extra LDAP round trip** (verified: `groupType` was already on the wire and being discarded). Groups without `GROUP_TYPE_SECURITY_ENABLED` (`0x80000000`) no longer produce a role claim.
Design notes:
- Bit test is done in C#, **not** via the AD-proprietary matching-rule OID `1.2.840.113556.1.4.803`, which non-AD directories do not implement.
- **Fails open** when `groupType` is absent or unparseable, so non-AD directories and foreign security principals are unaffected.
- Traversal still recurses **through** non-security groups (only the claim is skipped), so a security group nested inside a distribution group still grants its role.
- Suppressed groups are logged at `Debug` with the group DN, so the resulting 403 is diagnosable.
## Breaking change / opt-out
Apps that relied on distribution groups for authorization will start receiving 403. Opt-out:
`Microsoft.AspNetCore.Authentication.Negotiate.AllowNonSecurityEnabledGroupClaims=true`
## Validation
- Unit tests added for the `groupType` bit matrix, covering all security/distribution scopes plus unparseable and missing values (fail-open).
- Reproduced end-to-end against a Samba AD DC rig: a user in a distribution group whose CN matches the role gets **200 before / 403 after**, with the legitimate `Readers` role retained. Removing the membership restores 403, confirming causality.
- Local repo build not run: the internal branch pins an unreleased servicing runtime unavailable on public feeds. Final binaries will be validated end-to-end before release.
## Scope
Does **not** address role-name (CN) collisions across OUs, which is tracked separately. Fix messaging should stay scoped to distribution groups.
----
#### AI description (iteration 1)
#### PR Classification
Bug fix to restrict LDAP role claims to security-enabled groups only, with an opt-out switch to restore previous behavior.
#### PR Summary
This PR modifies the LDAP authentication adapter to filter out distribution groups (non-security-enabled groups) from role claims by default, addressing a security concern where all group types were previously included. An AppContext switch allows restoring the previous behavior if needed.
- `LdapAdapter.cs`: Added `IsSecurityGroup()` and `ShouldEmitRoleClaim()` methods to evaluate the `groupType` LDAP attribute (checking for 0x80000000 flag) and determine whether to emit role claims based on securi...
Co-authored-by: Copilot <[email protected]>
… Kerberos Principal Bug fix to prevent potential account confusion by validating that LDAP search results match the Kerberos-authenticated principal's SID. ---- #### AI description (iteration 1) #### PR Classification Security bug fix to prevent potential account confusion by validating that the LDAP-retrieved account matches the Kerberos-authenticated principal's SID. #### PR Summary Adds SID (Security Identifier) validation in the LDAP adapter to ensure the LDAP search result corresponds to the same user account as the Kerberos-authenticated principal, preventing potential security issues from name-based mismatches. - `LdapAdapter.cs`: Implements `VerifyLdapSidMatchesKerberosPrincipal()` to validate LDAP objectSid matches the Kerberos principal's PrimarySid claim before resolving claims - `LdapAdapter.cs`: Adds `ParseSidBytesToString()` cross-platform helper to convert binary SID bytes to canonical string format (e.g., "S-1-5-21-...") - `LdapAdapter.cs`: Updates cache key to include both username and SID for unique user identification - `LdapAdapter.cs`: Introduces `RequirePrimarySidClaim` AppContext switch to optionally enforce PrimarySid claim presence - `LdapAdapterTests.cs`: Adds comprehensive unit tests covering SID matching scenarios, edge cases, and the SID parsing implementation <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot --> Co-authored-by: Copilot <[email protected]>
wtgodbe
requested review from
DeagleGross and
rokonec
and
a balanced review from Copilot
October 14, 2026 16:10
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
SID validation remains opt-in for SID-less identities, unverifiable groups fail open, and integration-path coverage is missing.
3 open findings
What changed in this PR
Hardens Negotiate LDAP claim resolution by validating account SIDs and filtering group roles.
Changes:
- Adds LDAP/Kerberos SID comparison.
- Filters distribution groups from role claims.
- Adds SID and group-type unit tests.
| File | Description |
|---|---|
LdapAdapter.cs |
Implements SID validation, cache-key changes, and group filtering. |
LdapAdapterTests.cs |
Tests SID parsing, matching, and group classification. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
DeagleGross
approved these changes
Oct 14, 2026
This was referenced Oct 19, 2026
This was referenced Oct 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Restrict Negotiate LDAP role claims to security-enabled groups and validate that LDAP search results match the Kerberos-authenticated principal's SID. This prevents distribution groups from being treated as roles and avoids potential account confusion.