Skip to content

Commit 84ca9b7

Browse files
ashok672Copilot
andcommitted
Make the macOS broker gate an arm64 allowlist
Previously the gate denied a fixed list of Intel architectures. Invert it so the broker is enabled only on a recognized Apple Silicon (arm64) machine, and any unexpected darwin architecture errs on the side of not using the broker. Mirror the same rule in the manual smoke test. Also restore the 'installed' qualifier on the macOS opt-in table row, widening the column so the row stays consistent with the others. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent a79cb99 commit 84ca9b7

3 files changed

Lines changed: 31 additions & 17 deletions

File tree

‎msal/application.py‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -819,11 +819,14 @@ def _decide_broker(self, allow_broker, enable_pii_log):
819819
if (
820820
self._enable_broker
821821
and sys.platform == "darwin"
822-
and platform.machine() in ("x86_64", "i386")
822+
and platform.machine() != "arm64"
823823
):
824824
# Broker on macOS is supported only on Apple Silicon (arm64).
825-
# Intel Macs are excluded by product policy, regardless of whether
826-
# a broker is actually installed on the device.
825+
# Anything else on darwin -- Intel Macs, and an x86_64 Python
826+
# running under Rosetta -- is excluded by product policy,
827+
# regardless of whether a broker is installed on the device.
828+
# This is an allowlist so that an unrecognized architecture
829+
# errs on the side of not using the broker.
827830
self._enable_broker = False
828831
logger.warning(
829832
"Broker is not supported on Intel-based Macs. "
@@ -2180,17 +2183,17 @@ def __init__(
21802183
21812184
1. You can set any combination of the following opt-in parameters to true:
21822185
2183-
+--------------------------+-----------------------------------+------------------------------------------------------------------------------------+
2184-
| Opt-in flag | If app will run on | App has registered this as a Desktop platform redirect URI in Azure Portal |
2185-
+==========================+===================================+====================================================================================+
2186-
| enable_broker_on_windows | Windows 10+ | ms-appx-web://Microsoft.AAD.BrokerPlugin/your_client_id |
2187-
+--------------------------+-----------------------------------+------------------------------------------------------------------------------------+
2188-
| enable_broker_on_wsl | WSL | ms-appx-web://Microsoft.AAD.BrokerPlugin/your_client_id |
2189-
+--------------------------+-----------------------------------+------------------------------------------------------------------------------------+
2190-
| enable_broker_on_mac | Apple Silicon Mac, Company Portal | msauth.com.msauth.unsignedapp://auth |
2191-
+--------------------------+-----------------------------------+------------------------------------------------------------------------------------+
2192-
| enable_broker_on_linux | Linux with Intune installed | ``https://login.microsoftonline.com/common/oauth2/nativeclient`` (MUST be enabled) |
2193-
+--------------------------+-----------------------------------+------------------------------------------------------------------------------------+
2186+
+--------------------------+-------------------------------------------------+------------------------------------------------------------------------------------+
2187+
| Opt-in flag | If app will run on | App has registered this as a Desktop platform redirect URI in Azure Portal |
2188+
+==========================+=================================================+====================================================================================+
2189+
| enable_broker_on_windows | Windows 10+ | ms-appx-web://Microsoft.AAD.BrokerPlugin/your_client_id |
2190+
+--------------------------+-------------------------------------------------+------------------------------------------------------------------------------------+
2191+
| enable_broker_on_wsl | WSL | ms-appx-web://Microsoft.AAD.BrokerPlugin/your_client_id |
2192+
+--------------------------+-------------------------------------------------+------------------------------------------------------------------------------------+
2193+
| enable_broker_on_mac | Apple Silicon Mac with Company Portal installed | msauth.com.msauth.unsignedapp://auth |
2194+
+--------------------------+-------------------------------------------------+------------------------------------------------------------------------------------+
2195+
| enable_broker_on_linux | Linux with Intune installed | ``https://login.microsoftonline.com/common/oauth2/nativeclient`` (MUST be enabled) |
2196+
+--------------------------+-------------------------------------------------+------------------------------------------------------------------------------------+
21942197
21952198
2. Install broker dependency,
21962199
e.g. ``pip install msal[broker]>=1.33,<2``.

‎tests/intel_mac_broker_smoke_test.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
1616
* Apple Silicon Mac (``arm64``) with ``pymsalruntime`` installed:
1717
``_enable_broker`` is ``True``.
18-
* Intel Mac (``x86_64`` / ``i386``):
18+
* Intel Mac (``x86_64`` / ``i386``), or any other non-``arm64`` machine
19+
(including an ``x86_64`` Python running under Rosetta):
1920
``_enable_broker`` is ``False`` even though the opt-in was passed and even
2021
if a broker is installed on the device.
2122
* Non-Mac (Windows, Linux):
@@ -37,8 +38,8 @@
3738
def _expected_broker_state():
3839
if sys.platform != "darwin":
3940
return False, "non-Mac platform — enable_broker_on_mac is a no-op"
40-
if platform.machine() in ("x86_64", "i386"):
41-
return False, "Intel Mac — broker disabled by product policy"
41+
if platform.machine() != "arm64":
42+
return False, "not Apple Silicon — broker disabled by product policy"
4243
return True, "Apple Silicon Mac — broker should be enabled"
4344

4445

‎tests/test_application.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,16 @@ def test_broker_should_be_disabled_on_i386_mac(self):
17871787
)
17881788
self.assertFalse(app._enable_broker)
17891789

1790+
@patch("msal.application.platform.machine", new=Mock(return_value="unexpected"))
1791+
def test_broker_should_be_disabled_on_unrecognized_machine(self):
1792+
"""The gate is an allowlist, so an unknown architecture stays broker-free."""
1793+
app = msal.PublicClientApplication(
1794+
"client_id",
1795+
authority="https://login.microsoftonline.com/common",
1796+
enable_broker_on_mac=True,
1797+
)
1798+
self.assertFalse(app._enable_broker)
1799+
17901800

17911801
class MismatchingScopeTestCase(unittest.TestCase):
17921802
"""Test cache behavior when HTTP response scope differs from requested scope"""

0 commit comments

Comments
 (0)