Skip to content

fix(entra): MT.1063 reads every owner when $expand stops at 20 - #2837

Open
julien-ly wants to merge 1 commit into
maester365:mainfrom
julien-ly:fix/mt1063-owners-expand-cap
Open

julien-ly wants to merge 1 commit into
maester365:mainfrom
julien-ly:fix/mt1063-owners-expand-cap

Conversation

@julien-ly

@julien-ly julien-ly commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

📑 Description

MT.1063 reads app registration owners with applications?$expand=owners. On a relationship of a directory object, $expand returns at most 20 items and no @odata.nextLink (Microsoft Graph known issues). Owners past the 20th are never checked, so the test can pass while one of them has no MFA registered.

Apps whose expanded owners reach 20 are now read again from applications/{id}/owners, which pages. Apps with fewer than 20 owners keep the single call, so the cost is one extra request per app at the cap.

I hit the same cap on servicePrincipals?$expand=appRoleAssignments while building app-grant-diff: a principal holding 25 assignments came back with 20, the missing ones scattered through the list rather than at the end.

The other $expand calls in the repository are not affected. MT.1226 expands federatedIdentityCredentials, which Entra limits to 20 per application (source). The remaining ones expand Intune, Global Secure Access, entitlement management and recommendation relationships, not directory objects.

cc @marcel-ngn as the author of MT.1063.

✅ Checks

  • My pull request adheres to the code style of this project.
  • My code requires changes to the documentation.
  • I have updated the documentation as required.
  • The build and unit tests pass after running /powershell/tests/pester.ps1 locally.

ℹ️ Additional Information

Unit test. Test-MtAppRegistrationOwnersWithoutMFA.Tests.ps1 mocks an app whose expansion stops at 20 owners, all with MFA, while 25 exist and the last five have none. On main the function returns $true; with this change it returns $false and lists the five. A second case checks that an app with 19 owners is not read again.

Repository checks. FileEncoding, GraphCacheUsage, GraphEndpoint, LanguageNeutralMicrosoftUrls, NativeTestLint and RepositoryLayout pass, except the byte order mark check on Invoke-MtPackGitHubRequest.Tests.ps1, which fails on main as well and #2797 fixes.

Live tenant. In a lab tenant, one app registration with 25 owners: the request MT.1063 sends (applications?$expand=owners) returned 20 of them, and applications/{id}/owners returned all 25. The main vs PR run of MT.1063 against that tenant follows in a comment.

Summary by CodeRabbit

  • Bug Fixes
    • App registration owner MFA checks now retrieve the full owner list when an expanded list reaches its limit, so owners beyond that limit are included in the results. This helps ensure registrations with many owners are checked consistently, rather than relying only on the owners shown in the initial expanded list.

$expand on a relationship of a directory object returns at most 20 items and no @odata.nextLink. MT.1063 read owners with applications?$expand=owners, so owners past the 20th were never checked and the test could pass while one of them had no MFA registered. Apps whose expanded owners reach 20 are now read again from applications/{id}/owners, which pages.
@julien-ly
julien-ly requested review from a team as code owners November 20, 2026 08:54
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

This change updates Test-MtAppRegistrationOwnersWithoutMFA to reload app owners from the owners relationship endpoint when the expanded owner list has 20 or more entries. It also adds tests for the reload path and the non-reload path.

Changes: App registration owner threshold handling

Layer / File(s) Summary
Threshold-based owner reload
tests/maester/entra/Test.MT.1063.ps1, powershell/tests/functions/Test-MtAppRegistrationOwnersWithoutMFA.Tests.ps1
When an app has 20 or more expanded owners, the test now fetches the full owner list from the owners relationship endpoint and uses that list for the MFA check. The new tests set up 25 owners, verify one full-owner-list request and detection of Owner 25 at 20 expanded owners, and verify no full-owner-list request at 19 expanded owners.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested labels: product: entra

Suggested reviewers: merill

Merge Risk: Minimal · up to d1c4f

The change makes the owner MFA check look at all owners of apps with 20 or more owners, where it previously skipped the later ones. The added tests cover the cap and the no-reload case. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix (MT.1063 reading every owner when $expand stops at 20), which matches the changeset: MT.1063 now re-reads owners from the applications/{id}/owners endpoint when expanded owners…
Description check Passed The description follows the repository template. It has a clear Description section that explains the 20-item $expand cap, the fallback to the paginated owners endpoint, and why apps under 20 owners k…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the fix (MT.1063 reading every owner when $expand stops at 20), which matches the changeset: MT.1063 now re-reads owners from the applications/{id}/owners endpoint when expanded owners reach 20, plus unit tests for that behavior. It is specific and concise, and it uses the conventional fix(scope) prefix.

Full details: Description check

Explanation

The description follows the repository template. It has a clear Description section that explains the 20-item $expand cap, the fallback to the paginated owners endpoint, and why apps under 20 owners keep the single call. It also covers the unit tests, repository checks, and a live-tenant comparison in Additional Information. The Closes issue placeholder is left unfilled, and the documentation checkboxes are unchecked, with no note on why documentation is not needed. The full Pester run is also unchecked, though the description reports the other repository checks. These are minor gaps, and the core content is complete.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 512a076 and d1c4f17.

Files selected for processing: 2

  • powershell/tests/functions/Test-MtAppRegistrationOwnersWithoutMFA.Tests.ps1
  • tests/maester/entra/Test.MT.1063.ps1

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@julien-ly

Copy link
Copy Markdown
Contributor Author

Ran MT.1063 against my lab tenant, main against this PR, each build in its own PowerShell session (PowerShell 7.7.0, Maester 3.0.0, Microsoft.Graph.Authentication 2.41.2). One app registration has 25 owners, all disabled accounts created for the run.

Test main PR
MT.1063 Passed Passed

Both pass: the 25 accounts are not in reports/authenticationMethods/userRegistrationDetails, so the test lists them as owners it could not check. What differs is how many it read. main reports 20 owners it could not check, this PR reports all 25.

The unit test covers the other case, where owners past the 20th have no MFA: main passes, this PR fails.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant