Skip broker key lookup when ignoreBrokerKey is set (PBI 3590167)#1812
Open
kaisong1990 wants to merge 3 commits into
Open
Skip broker key lookup when ignoreBrokerKey is set (PBI 3590167)#1812kaisong1990 wants to merge 3 commits into
kaisong1990 wants to merge 3 commits into
Conversation
… (PBI 3590167) When MSIDBrokerOperationRequest is built in a runtime/non-keychain-entitled +fillRequest: was unconditionally calling [MSIDBrokerKeyProvider base64BrokerKeyWithContext:error:] before populating the clientBrokerKeyCapabilityNotSupported field on the request. The lookup falls through to SecItemAdd, which fails with OSStatus -34018 and is wrapped as MSIDErrorBrokerKeyFailedToCreate (-51808), spamming the logs at MSIDLogLevelError every time a broker request is built in this context. The downstream -jsonDictionary already tolerates a nil broker key here via -shouldIgnoreBrokerKey, so the fix is to gate the upstream lookup with the same condition: set clientBrokerKeyCapabilityNotSupported on the request first, then short-circuit the broker-key fetch when -shouldIgnoreBrokerKey returns YES, replacing the noisy error logs with a single info log. iOS, visionOS, and entitled macOS hosts are unaffected: -shouldIgnoreBrokerKey returns NO in those configurations, so the broker-key lookup runs as before. Tests: - testFillRequest_whenClientBrokerKeyCapabilityNotSupported_shouldSkipBrokerKeyLookup (macOS) - testFillRequest_whenClientBrokerKeyCapabilitySupported_shouldNotSkipBrokerKeyLookup (macOS) - testFillRequest_oniOS_whenClientBrokerKeyCapabilityNotSupported_shouldStillAttemptBrokerKeyLookup (iOS)
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reduces noisy macOS keychain error logs during broker operation request construction by skipping broker-key keychain access when the request indicates the broker key should be ignored (e.g., runtime/unentitled contexts).
Changes:
- Update
MSIDBrokerOperationRequest +fillRequest:to short-circuit broker key lookup/creation when-shouldIgnoreBrokerKeyisYES. - Add macOS/iOS unit tests covering the skip behavior and platform differences around
shouldIgnoreBrokerKey.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| IdentityCore/src/broker_operation/request/MSIDBrokerOperationRequest.m | Skips broker key provider keychain work when shouldIgnoreBrokerKey is true to avoid entitlement-related keychain errors. |
| IdentityCore/tests/MSIDBrokerOperationRequestTests.m | Adds platform-conditional tests for the new short-circuit behavior and to preserve existing behavior when a broker key is required. |
- Remove duplicative Info log in +fillRequest: (jsonDictionary already logs the skip path). - Defensively clear request.brokerKey on the skip branch. - Add changelog entry for #1812. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
kaisong1990
commented
May 8, 2026
| @@ -40,17 +40,31 @@ + (BOOL)fillRequest:(MSIDBrokerOperationRequest *)request | |||
| clientBrokerKeyCapabilityNotSupported:(BOOL)clientBrokerKeyCapabilityNotSupported | |||
Contributor
Author
There was a problem hiding this comment.
Useful — added an entry under Version 1.23.1 in changelog.txt for this fix.
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.
Problem
On macOS in runtime contexts that lack the keychain entitlement (e.g. certain broker XPC / sandboxed flows),
MSIDBrokerOperationRequest +fillRequest:unconditionally calls[MSIDBrokerKeyProvider base64BrokerKeyWithContext:], which produces noisy keychain errors in the log:-34018(errSecMissingEntitlement)-51808(no access to keychain item)These calls are pure noise when the caller has already indicated via
shouldIgnoreBrokerKey == YESthat the broker key is not needed for this request.Fix
In
MSIDBrokerOperationRequest +fillRequest:, skip thebase64BrokerKeyWithContext:call entirely when[request shouldIgnoreBrokerKey]returnsYES. Behavior is unchanged when the broker key is required.Tests
Added 3 unit tests in
MSIDBrokerOperationRequestTests.m:shouldIgnoreBrokerKey == NO(default)brokerKeyleft nil) whenshouldIgnoreBrokerKey == YESBuilds (Mac + iOS) and full test suite pass locally.
Work item
ADO PBI: https://dev.azure.com/IdentityDivision/IDDP/_workitems/edit/3590167