Skip to content

Bound nested-group recursion depth in Negotiate LdapAdapter - #70041

Open
GrantTotinov wants to merge 1 commit into
dotnet:mainfrom
GrantTotinov:bound-ldap-nested-groups-69611
Open

GrantTotinov wants to merge 1 commit into
dotnet:mainfrom
GrantTotinov:bound-ldap-nested-groups-69611

Conversation

@GrantTotinov

Copy link
Copy Markdown
Contributor
  • 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.

Bound nested-group recursion depth in Negotiate LdapAdapter

Description

Hi! This follows the approach suggested in #69611. Thanks for writing it up in so much detail, that made it easy to pick up.

GetGroups now gets the current depth and stops going further up once it reaches MaxNestedGroupDepth, which is an internal constant set to 32. The direct group counts as depth 0. Whatever was collected up to that point is kept. No public API changes.

When the limit is hit, one warning is logged for the whole resolution, not one per group. It only includes the user name and the limit, no group names. To make that testable, I moved the loop over the user's direct groups into a small GetGroupClaims helper.

The visited-set check still runs before the depth check, so cycles are skipped like before and aren't reported as truncation.

I left the existing return for already processed groups alone on purpose. Switching it to continue would change which claims some directories get back, so it felt better as its own change. Happy to send a follow-up if you'd like.

I also added a short remark to the LdapSettings.IgnoreNestedGroups docs about the limit.

Tests

I used the same LdapConnection subclass plus the reflection helper for building responses that #69955 uses. Whichever of the two gets merged second can just reuse the helper from the other one, and I'm happy to handle the merge on my side.

New tests:

  • no nesting, one level below the limit, and exactly at the limit: the whole chain is resolved and nothing is logged
  • above the limit: claims up to the limit are returned, the next group is never read, and one warning is logged
  • two direct groups, both over the limit: still just one warning
  • a circular reference: it terminates without extra reads and without a warning

All 105 tests in Negotiate.Test pass locally. When I disabled only the depth check, just the two over-the-limit tests failed.

Fixes #69611

GetGroups followed memberOf links with no upper bound, so the length of
an acyclic chain of distinct groups returned by the directory decided how
deep the managed stack grew. A stack overflow cannot be caught and takes
down the whole host.

Traversal now stops descending at MaxNestedGroupDepth (32) levels below
each directly held group, keeps the claims already collected, and logs a
single warning per resolution. The visited-set check is kept so cycles are
still skipped cheaply, and the existing behaviour of returning on an
already processed group is unchanged.

Fixes dotnet#69611
Copilot AI balanced review requested due to automatic review settings October 26, 2026 02:00

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@github-actions github-actions Bot added the area-auth Includes: authentication, authorization, OAuth, OIDC, and access token validation label Oct 26, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Oct 26, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @GrantTotinov. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@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 was previously deployed

1 inactive deployment
copilot-pat-pool — a3645fee Deployed Oct 26, 2026 by dotnet-policy-service[bot] via pat_pool #1972
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 community-contribution Indicates that the PR has been added by a community member 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: bound nested-group recursion depth in LdapAdapter.GetNestedGroups

2 participants