Skip to content

Commit bc6ddfc

Browse files
Mihaela KorteCopilot
andcommitted
Poison bridge on teardown instead of deleting
After disableNestedAppAuth(), replace window.nestedAppAuthBridge with a stub whose postMessage/addEventListener throw a clear error instead of deleting the property. This prevents MSAL from silently falling back to the broken popup redirect flow when the bridge is disabled. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 60968ec commit bc6ddfc

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

src/NestedAppAuthBridge.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,25 @@ export async function initializeNestedAppAuthBridge(parentChannel: IXDMChannel):
107107
}
108108

109109
/**
110-
* Tears down the NAA bridge by removing `window.nestedAppAuthBridge`.
111-
* Call this when the extension no longer needs NAA, or during cleanup in tests.
110+
* Tears down the NAA bridge by replacing `window.nestedAppAuthBridge` with a
111+
* poisoned stub whose methods throw clear errors. This ensures that:
112+
* - Existing MSAL PCA instances get an explicit error on their next token call
113+
* (MSAL reads `window.nestedAppAuthBridge.postMessage` on every request).
114+
* - New `createNestablePublicClientApplication` calls fail during bridge init
115+
* instead of silently falling back to the standard (broken) popup flow.
112116
*/
113117
export function teardownNestedAppAuthBridge(): void {
114-
delete (window as any).nestedAppAuthBridge;
118+
const disabledError = "Nested App Authentication bridge has been disabled. Call enableNestedAppAuth() to re-enable.";
119+
120+
(window as any).nestedAppAuthBridge = {
121+
postMessage(): void {
122+
throw new Error(disabledError);
123+
},
124+
addEventListener(): void {
125+
throw new Error(disabledError);
126+
},
127+
removeEventListener(): void {
128+
// Allow silent removal — no harm in cleaning up listeners on a disabled bridge
129+
}
130+
};
115131
}

0 commit comments

Comments
 (0)