You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit cd0cfad
Browse filesBrowse the repository at this point in the historyBrowse files
'Unexpected cross-origin authentication response top origin of "https://wrong.top.origin.com", expected one of: https://top.origin.com, https://other.origin.com',
768
+
);
769
+
}finally{
770
+
mockDecodeClientData.restore();
771
+
}
772
+
});
773
+
774
+
Deno.test('should throw when crossOrigin is true but expectedTopOrigin is not specified',async()=>{
775
+
constmockDecodeClientData=stub(
776
+
_decodeClientDataJSONInternals,
777
+
'stubThis',
778
+
returnsNext([
779
+
{
780
+
type: 'webauthn.get',
781
+
origin: assertionOrigin,
782
+
challenge: assertionChallenge,
783
+
crossOrigin: true,
784
+
topOrigin: 'https://top.origin.com',
785
+
},
786
+
]),
787
+
);
788
+
789
+
try{
790
+
awaitassertRejects(
791
+
()=>
792
+
verifyAuthenticationResponse({
793
+
response: assertionResponse,
794
+
expectedChallenge: assertionChallenge,
795
+
expectedOrigin: assertionOrigin,
796
+
expectedRPID: 'dev.dontneeda.pw',
797
+
credential,
798
+
}),
799
+
Error,
800
+
'Detected cross-origin authentication response from top origin of "https://top.origin.com", but a value for `expectedTopOrigin` was not specified when calling `verifyAuthenticationResponse()`',
801
+
);
802
+
}finally{
803
+
mockDecodeClientData.restore();
804
+
}
805
+
});
806
+
807
+
Deno.test('should throw when topOrigin is set despite crossOrigin being false',async()=>{
808
+
constmockDecodeClientData=stub(
809
+
_decodeClientDataJSONInternals,
810
+
'stubThis',
811
+
returnsNext([
812
+
{
813
+
type: 'webauthn.get',
814
+
origin: assertionOrigin,
815
+
challenge: assertionChallenge,
816
+
crossOrigin: false,
817
+
topOrigin: 'https://some.top.origin.com',
818
+
},
819
+
]),
820
+
);
821
+
822
+
try{
823
+
awaitassertRejects(
824
+
()=>
825
+
verifyAuthenticationResponse({
826
+
response: assertionResponse,
827
+
expectedChallenge: assertionChallenge,
828
+
expectedOrigin: assertionOrigin,
829
+
expectedRPID: 'dev.dontneeda.pw',
830
+
credential,
831
+
requireUserVerification: false,
832
+
}),
833
+
Error,
834
+
'Unexpected top origin of "https://some.top.origin.com" within a non-cross-origin authentication response. This error should be reported to the browser vendor as a WebAuthn specification violation with a link to https://w3c.github.io/webauthn/#dom-collectedclientdata-toporigin',
@@ -120,6 +122,50 @@ export async function verifyAuthenticationResponse(
120
122
);
121
123
}
122
124
125
+
// Check that the authentication response is within an expected iframe
126
+
if(crossOrigin){
127
+
/**
128
+
* TODO: Since Safari doesn't support `topOrigin` as of May 2026, only check this when
129
+
* `topOrigin` is available for now.
130
+
*/
131
+
if(topOrigin){
132
+
if(!expectedTopOrigin){
133
+
/**
134
+
* If `expectedTopOrigin` is not set, this should be considered an unexpected cross-origin
135
+
* request. Reject the response while helping the RP understand how they need to update this
136
+
* method call if they want to support verification of such WebAuthn authentication requests.
137
+
*/
138
+
thrownewError(
139
+
`Detected cross-origin authentication response from top origin of "${topOrigin}", but a value for \`expectedTopOrigin\` was not specified when calling \`verifyAuthenticationResponse()\``,
`Unexpected cross-origin authentication response top origin of "${topOrigin}", expected one of: ${joinedExpectedTopOrigin}`,
148
+
);
149
+
}
150
+
}else{
151
+
if(topOrigin!==expectedTopOrigin){
152
+
thrownewError(
153
+
`Unexpected cross-origin authentication response top origin of "${topOrigin}", expected: ${expectedTopOrigin}`,
154
+
);
155
+
}
156
+
}
157
+
}
158
+
}else{
159
+
if(topOrigin){
160
+
/**
161
+
* If `topOrigin` is set despite `crossOrigin` being false, this is an unexpected request.
162
+
*
163
+
* See https://w3c.github.io/webauthn/#dom-collectedclientdata-toporigin.
164
+
*/
165
+
thrownewError(`Unexpected top origin of "${topOrigin}" within a non-cross-origin authentication response. This error should be reported to the browser vendor as a WebAuthn specification violation with a link to https://w3c.github.io/webauthn/#dom-collectedclientdata-toporigin`);
0 commit comments