-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check for Password Manager extensions when adding new devices (#2842)
- Loading branch information
Showing
6 changed files
with
80 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { userSupportsWebauthRoR } from "./rorSupport"; | ||
|
||
describe("rorSupport", () => { | ||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
describe("userSupportsWebauthRoR", () => { | ||
it("should return true if the user agent supports Webauthn with Related Origin Requests and the credential.get function is not monkey patched", () => { | ||
vi.stubGlobal("navigator", { | ||
userAgent: | ||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Safari/605.1.15", | ||
credentials: { | ||
get: { | ||
toString: () => "function get() { [native code] }", | ||
}, | ||
}, | ||
}); | ||
expect(userSupportsWebauthRoR()).toBe(true); | ||
}); | ||
|
||
it("should return false if the user agent does not support Webauthn with Related Origin Requests", () => { | ||
vi.stubGlobal("navigator", { | ||
userAgent: | ||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15", | ||
credentials: { | ||
get: { | ||
toString: () => "function get() { [native code] }", | ||
}, | ||
}, | ||
}); | ||
expect(userSupportsWebauthRoR()).toBe(false); | ||
}); | ||
|
||
it("should return false if the credential.get function is monkey patched", () => { | ||
vi.stubGlobal("navigator", { | ||
userAgent: | ||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Safari/605.1.15", | ||
credentials: { | ||
get: { | ||
toString: () => "function get() { [non-native code] }", | ||
}, | ||
}, | ||
}); | ||
expect(userSupportsWebauthRoR()).toBe(false); | ||
}); | ||
}); | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { supportsWebauthRoR } from "./userAgent"; | ||
|
||
const isNative = (fn: () => unknown) => /\[native code\]/.test(fn.toString()); | ||
|
||
/** | ||
* Util to find out whether the current user's browser supports Related Origin Requests. | ||
* | ||
* There are two things to consider: | ||
* - Does the browser and version support RoR? | ||
* - Does the user have an installed password manager extension? | ||
* - Some extensions monkey patch the `navigator.credentials.get` function, e.g. 1Password. | ||
* - We can check for this with `toString` method. | ||
* - Others proxy `navigator.credentials.get` to their own implementation, e.g. NordPass. | ||
* - We can't check this. | ||
* | ||
* @returns {boolean} | ||
*/ | ||
export const userSupportsWebauthRoR = (): boolean => { | ||
const userAgentSuportsRoR = supportsWebauthRoR(navigator.userAgent); | ||
const hasMonkeyPatchedCredentialGet = !isNative( | ||
window.navigator.credentials.get | ||
); | ||
return userAgentSuportsRoR && !hasMonkeyPatchedCredentialGet; | ||
}; |