Skip to content

Commit 7a74994

Browse files
Thomas Schofieldthomas-schofield-fr
authored andcommitted
fix: webauthn script parsing for AME-34349
1 parent ebaaff7 commit 7a74994

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

  • packages/javascript-sdk/src/fr-webauthn

packages/javascript-sdk/src/fr-webauthn/index.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,15 @@ abstract class FRWebAuthn {
178178
credential = await this.getAuthenticationCredential({ publicKey, mediation });
179179
outcome = this.getAuthenticationOutcome(credential);
180180
} else if (textOutputCallback) {
181-
publicKey = parseWebAuthnAuthenticateText(textOutputCallback.getMessage());
181+
const metadata = this.extractMetadata(textOutputCallback.getMessage());
182+
183+
if (metadata) {
184+
publicKey = this.createAuthenticationPublicKey(
185+
metadata as WebAuthnAuthenticationMetadata,
186+
);
187+
} else {
188+
publicKey = parseWebAuthnAuthenticateText(textOutputCallback.getMessage());
189+
}
182190

183191
credential = await this.getAuthenticationCredential({ publicKey });
184192
outcome = this.getAuthenticationOutcome(credential);
@@ -245,7 +253,13 @@ abstract class FRWebAuthn {
245253
);
246254
outcome = this.getRegistrationOutcome(credential);
247255
} else if (textOutputCallback) {
248-
publicKey = parseWebAuthnRegisterText(textOutputCallback.getMessage());
256+
const metadata = this.extractMetadata(textOutputCallback.getMessage());
257+
258+
if (metadata) {
259+
publicKey = this.createRegistrationPublicKey(metadata as WebAuthnRegistrationMetadata);
260+
} else {
261+
publicKey = parseWebAuthnRegisterText(textOutputCallback.getMessage());
262+
}
249263
credential = await this.getRegistrationCredential(
250264
publicKey as PublicKeyCredentialCreationOptions,
251265
);
@@ -602,6 +616,17 @@ abstract class FRWebAuthn {
602616
window.PingWebAuthnAbortController = abortController;
603617
return abortController;
604618
}
619+
620+
private static extractMetadata(message: string): object | null {
621+
const contextMatch = message.match(/^var scriptContext = (.*)$/);
622+
const jsonString = contextMatch?.[1];
623+
624+
if (jsonString) {
625+
return JSON.parse(jsonString);
626+
}
627+
628+
return null;
629+
}
605630
}
606631

607632
export default FRWebAuthn;

0 commit comments

Comments
 (0)