-
Notifications
You must be signed in to change notification settings - Fork 166
LG-9885: Restrict platform authenticator setup based on device support #8615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b96b2c3
LG-9885: Restrict platform authenticator setup based on device support
aduth b053288
Add coverage for Android Firefox exclusion
aduth 6584130
Fix feature specs for WebAuthn
aduth 15cd5ff
Filter by passkey support for initial setup
aduth 5580deb
Remove iPad checks
aduth 6eab933
Fix lint error
aduth 12a3966
Add spec coverage for passkey_supported_only
aduth f5a51b1
Move initialized setter to connectedCallback
aduth 444e9a2
Try to fix specs
aduth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
104 changes: 104 additions & 0 deletions
104
app/javascript/packages/webauthn/is-webauthn-passkey-supported.spec.ts
This file contains hidden or 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,104 @@ | ||
| import { useDefineProperty } from '@18f/identity-test-helpers'; | ||
| import isWebauthnPasskeySupported from './is-webauthn-passkey-supported'; | ||
|
|
||
| // Source (Adapted): https://www.chromium.org/updates/ua-reduction/#sample-ua-strings-final-reduced-state | ||
| const UNSUPPORTED_ANDROID_VERSION_UA = | ||
| 'Mozilla/5.0 (Linux; Android 8; SM-A205U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.1234.56 Mobile Safari/537.36'; | ||
|
|
||
| // Source: https://www.chromium.org/updates/ua-reduction/#sample-ua-strings-final-reduced-state | ||
| const REDUCED_UNSUPPORTED_ANDROID_VERSION_UA = | ||
| 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.0.0 Mobile Safari/537.36'; | ||
|
|
||
| // Source: https://www.chromium.org/updates/ua-reduction/#sample-ua-strings-final-reduced-state | ||
| const SUPPORTED_ANDROID_VERSION_CHROME_UA = | ||
| 'Mozilla/5.0 (Linux; Android 9; SM-A205U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.1234.56 Mobile Safari/537.36'; | ||
|
|
||
| // Source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent/Firefox#mobile_and_tablet_indicators | ||
| const SUPPORTED_ANDROID_VERSION_FIREFOX_UA = | ||
| 'Mozilla/5.0 (Android 9; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0'; | ||
|
|
||
| // Source: https://chromium.googlesource.com/chromium/src/+/master/docs/ios/user_agent.md | ||
| const UNSUPPORTED_IOS_VERSION_CHROME_UA = | ||
| 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1'; | ||
|
|
||
| // Source: https://chromium.googlesource.com/chromium/src/+/master/docs/ios/user_agent.md | ||
| const UNSUPPORTED_IOS_VERSION_SAFARI_UA = | ||
| 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/603.1.23 (KHTML, like Gecko) Version/10.0 Mobile/14E5239e Safari/602.1'; | ||
|
|
||
| // Source (Adapted): https://chromium.googlesource.com/chromium/src/+/master/docs/ios/user_agent.md | ||
| const SUPPORTED_IOS_CHROME_VERSION_UA = | ||
| 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_5 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1'; | ||
|
|
||
| // Source (Adapted): https://chromium.googlesource.com/chromium/src/+/master/docs/ios/user_agent.md | ||
| const SUPPORTED_IOS_SAFARI_VERSION_UA = | ||
| 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_5 like Mac OS X) AppleWebKit/603.1.23 (KHTML, like Gecko) Version/10.0 Mobile/14E5239e Safari/602.1'; | ||
|
|
||
| // Source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent#firefox_ua_string | ||
| const FIREFOX_UA = | ||
| 'Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0'; | ||
|
|
||
| // Source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent#chrome_ua_string | ||
| const DESKTOP_CHROME_UA = | ||
| 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36'; | ||
|
|
||
| // Source: Me | ||
| const DESKTOP_SAFARI_UA = | ||
| 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Safari/605.1.15'; | ||
|
|
||
| const SUPPORTED_USER_AGENTS = [ | ||
| REDUCED_UNSUPPORTED_ANDROID_VERSION_UA, | ||
| SUPPORTED_ANDROID_VERSION_CHROME_UA, | ||
| SUPPORTED_IOS_CHROME_VERSION_UA, | ||
| SUPPORTED_IOS_SAFARI_VERSION_UA, | ||
| ]; | ||
|
|
||
| const UNSUPPORTED_USER_AGENTS = [ | ||
| UNSUPPORTED_ANDROID_VERSION_UA, | ||
| SUPPORTED_ANDROID_VERSION_FIREFOX_UA, | ||
| UNSUPPORTED_IOS_VERSION_CHROME_UA, | ||
| UNSUPPORTED_IOS_VERSION_SAFARI_UA, | ||
| FIREFOX_UA, | ||
| DESKTOP_CHROME_UA, | ||
| DESKTOP_SAFARI_UA, | ||
| ]; | ||
|
|
||
| describe('isWebauthnPasskeySupported', () => { | ||
| const defineProperty = useDefineProperty(); | ||
|
|
||
| beforeEach(() => { | ||
| defineProperty(window, 'PublicKeyCredential', { | ||
| configurable: true, | ||
| value: { isUserVerifyingPlatformAuthenticatorAvailable: () => Promise.resolve(true) }, | ||
| }); | ||
| }); | ||
|
|
||
| UNSUPPORTED_USER_AGENTS.forEach((userAgent) => { | ||
| context(userAgent, () => { | ||
| beforeEach(() => { | ||
| defineProperty(navigator, 'userAgent', { | ||
| configurable: true, | ||
| value: userAgent, | ||
| }); | ||
| }); | ||
|
|
||
| it('resolves to false', () => { | ||
| expect(isWebauthnPasskeySupported()).to.equal(false); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| SUPPORTED_USER_AGENTS.forEach((userAgent) => { | ||
| context(userAgent, () => { | ||
| beforeEach(() => { | ||
| defineProperty(navigator, 'userAgent', { | ||
| configurable: true, | ||
| value: userAgent, | ||
| }); | ||
| }); | ||
|
|
||
| it('resolves to true', () => { | ||
| expect(isWebauthnPasskeySupported()).to.equal(true); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
30 changes: 30 additions & 0 deletions
30
app/javascript/packages/webauthn/is-webauthn-passkey-supported.ts
This file contains hidden or 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,30 @@ | ||
| export type IsWebauthnPasskeySupported = () => boolean; | ||
|
|
||
| const MINIMUM_IOS_VERSION = 16; | ||
|
|
||
| const MINIMUM_ANDROID_VERSION = 9; | ||
|
|
||
| function isQualifyingIOSDevice(): boolean { | ||
| const match = navigator.userAgent.match(/iPhone; CPU iPhone OS (\d+)_/); | ||
| const iOSVersion: null | number = match && Number(match[1]); | ||
| return !!iOSVersion && iOSVersion >= MINIMUM_IOS_VERSION; | ||
| } | ||
|
|
||
| function isQualifyingAndroidDevice(): boolean { | ||
| // Note: Chrome versions applying the "reduced" user agent string will always report a version of | ||
| // Android as 10.0.0. | ||
| // | ||
| // See: https://www.chromium.org/updates/ua-reduction/ | ||
| const match = navigator.userAgent.match(/; Android (\d+)/); | ||
| const androidVersion: null | number = match && Number(match[1]); | ||
| return ( | ||
| !!androidVersion && | ||
| androidVersion >= MINIMUM_ANDROID_VERSION && | ||
| navigator.userAgent.includes(' Chrome/') | ||
| ); | ||
| } | ||
|
|
||
| const isWebauthnPasskeySupported: IsWebauthnPasskeySupported = () => | ||
| isQualifyingIOSDevice() || isQualifyingAndroidDevice(); | ||
|
|
||
| export default isWebauthnPasskeySupported; |
This file contains hidden or 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 hidden or 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
30 changes: 27 additions & 3 deletions
30
app/javascript/packages/webauthn/webauthn-input-element.ts
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.