1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-06-24 10:14:48 +02:00

Auth/PM-5976 - Safari Browser SSO Initialization Race Condition Attempted Fix (#7793)

* PM-5976 - Only try to initiate browser SSO when document is ready to avoid race condition between browser content script message listener being registered and the browser sso initiating message being sent.

* PM-5976 - adjust initiateBrowserSsoIfDocumentReady per PR feedback
This commit is contained in:
Jared Snider 2024-02-02 13:53:11 -05:00 committed by GitHub
parent f3beb71d6d
commit 6e96964c1a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -8,9 +8,9 @@ window.addEventListener("load", () => {
const lastpass = getQsParam("lp");
if (lastpass === "1") {
initiateBrowserSso(code, state, true);
initiateBrowserSsoIfDocumentReady(code, state, true);
} else if (state != null && state.includes(":clientId=browser")) {
initiateBrowserSso(code, state, false);
initiateBrowserSsoIfDocumentReady(code, state, false);
} else {
window.location.href = window.location.origin + "/#/sso?code=" + code + "&state=" + state;
// Match any characters between "_returnUri='" and the next "'"
@ -23,6 +23,20 @@ window.addEventListener("load", () => {
}
});
function initiateBrowserSsoIfDocumentReady(code: string, state: string, lastpass: boolean) {
if (document.readyState === "complete") {
initiateBrowserSso(code, state, lastpass);
return;
}
const interval = setInterval(() => {
if (document.readyState === "complete") {
clearInterval(interval);
initiateBrowserSso(code, state, lastpass);
}
}, 50);
}
function initiateBrowserSso(code: string, state: string, lastpass: boolean) {
window.postMessage({ command: "authResult", code: code, state: state, lastpass: lastpass }, "*");
const handOffMessage = ("; " + document.cookie)