Skip to content

Skip broker key lookup when ignoreBrokerKey is set (PBI 3590167)#1812

Open
kaisong1990 wants to merge 3 commits into
devfrom
forge/3590167-skip-broker-key-when-ignored
Open

Skip broker key lookup when ignoreBrokerKey is set (PBI 3590167)#1812
kaisong1990 wants to merge 3 commits into
devfrom
forge/3590167-skip-broker-key-when-ignored

Conversation

@kaisong1990

Copy link
Copy Markdown
Contributor

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 == YES that the broker key is not needed for this request.

Fix

In MSIDBrokerOperationRequest +fillRequest:, skip the base64BrokerKeyWithContext: call entirely when [request shouldIgnoreBrokerKey] returns YES. Behavior is unchanged when the broker key is required.

Tests

Added 3 unit tests in MSIDBrokerOperationRequestTests.m:

  • broker key is fetched and populated when shouldIgnoreBrokerKey == NO (default)
  • broker key fetch is skipped (and brokerKey left nil) when shouldIgnoreBrokerKey == YES
  • error path is unaffected when broker key fetch is skipped

Builds (Mac + iOS) and full test suite pass locally.

Work item

ADO PBI: https://dev.azure.com/IdentityDivision/IDDP/_workitems/edit/3590167

… (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)

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.

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 -shouldIgnoreBrokerKey is YES.
  • 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.

Comment thread IdentityCore/tests/MSIDBrokerOperationRequestTests.m
Comment thread IdentityCore/tests/MSIDBrokerOperationRequestTests.m
Comment thread IdentityCore/src/broker_operation/request/MSIDBrokerOperationRequest.m Outdated
- 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>
@@ -40,17 +40,31 @@ + (BOOL)fillRequest:(MSIDBrokerOperationRequest *)request
clientBrokerKeyCapabilityNotSupported:(BOOL)clientBrokerKeyCapabilityNotSupported

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useful — added an entry under Version 1.23.1 in changelog.txt for this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants