← Back to Pull requests

fix(exchange_server): page through Active Directory users #5081

Closed
unknown closed this pull request without merging on Dec 03, 2026 09:48 UTC
View on GitHub
unknown unknown commented on Dec 02, 2026 06:48 UTC
Author

Relates to: no issue

This is a bug I found while reading the Exchange Server connector (it is also used by the Outlook connector for Outlook Server).

ExchangeUsers._ldap_search looks up the mailboxes to sync with one LDAP search:

has_value, _, response, _ = connection.search(
    search_query,
    search_filter,
    attributes=["mail"],
)

The search does not send the paged results control. Active Directory answers a search like this with at most MaxPageSize entries (1000 by default) and the result code sizeLimitExceeded. ldap3 does not raise on that result code by default, and has_value is True because the response is not empty, so the connector takes the first 1000 entries as the full list:

  • in a domain with more than 1000 matching users, mailboxes past the first 1000 are never synced, with no error or warning;

  • get_access_control uses the same lookup, so those users get no access control documents either.
  • The fix sends the search with paged_size=1000 and follows the paged results cookie (1.2.840.113556.1.4.319) until the server returns an empty cookie, collecting all pages. The first page still raises UsersFetchFailed when it has no entries, as before. A later page that comes back empty with a non-success result also raises UsersFetchFailed, so a failure midway does not return a partial list. Each page is a separate request on the same connection, and the connection is still unbound once at the end.

    Checklists

    Pre-Review Checklist


  • this PR does NOT contain credentials of any kind, such as API keys or username/passwords (double check config.yml.example)

  • this PR has a meaningful title

  • this PR links to all relevant github issues that it fixes or partially addresses

  • this PR has a thorough description

  • Covered the changes with automated tests

  • Tested the changes locally

  • Added a label for each target release version (example: v7.13.2, v7.14.0, v8.0.0)

  • Considered corresponding documentation changes

  • Contributed any configuration settings changes to the configuration reference

  • if you added or changed Rich Configurable Fields for a Native Connector, you made a corresponding PR in Kibana
  • Tests

    In tests/sources/test_exchange_server.py:

  • test_ldap_search_follows_paged_results_cookie: the first page returns one user and a cookie, the second page returns another user and an empty cookie; checks that both users are returned, that the second search sends the cookie from the first, and that the connection is unbound once.

  • test_ldap_search_raises_when_a_later_page_fails: the second page fails; checks that UsersFetchFailed is raised.
  • Both tests fail on main and pass with the fix. The existing tests, which return a single page without paging controls, pass unchanged. test_exchange_server.py and test_outlook.py pass, apart from test_outlook.py::test_get_content[attachment0-expected_content0], which also fails on main on my Windows machine (it calls the system base64 command). ruff check, ruff format --check and pyright on the changed files are clean, apart from the repo-wide CPY001 notice.

    🤖 Generated with Claude Code

    Diff: 418 lines (+313 / -105) across 5 files Reviewer: ShivamSharma43 Review duration: 1620m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 418 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.361
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #5081"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.0% (MEDIUM) · Higher = larger blast radius
    45.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.8% · Safe to merge
    17.8%