Skip to content

Support cross-origin authentication verification#759

Open
agektmr wants to merge 2 commits intoMasterKale:masterfrom
agektmr:cross-origin
Open

Support cross-origin authentication verification#759
agektmr wants to merge 2 commits intoMasterKale:masterfrom
agektmr:cross-origin

Conversation

@agektmr
Copy link
Copy Markdown
Contributor

@agektmr agektmr commented May 6, 2026

To support cross-origin authentication on SimpleWebAuthn, this pull request adds the following to the verifyAuthenticationResponse.ts:

  • Add a new expectedTopOrigin property to the options
  • Check if crossOrigin is true or false
  • Check if topOrigin meets the expectation

if (!expectedTopOrigin.includes(topOrigin)) {
const joinedExpectedTopOrigin = expectedTopOrigin.join(', ');
throw new Error(
`Unexpected cross-origin authentication within "${topOrigin}", expected one of: ${joinedExpectedTopOrigin}`,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit of a nitpick:

Suggested change
`Unexpected cross-origin authentication within "${topOrigin}", expected one of: ${joinedExpectedTopOrigin}`,
`Unexpected cross-origin authentication response origin "${topOrigin}", expected one of: ${joinedExpectedTopOrigin}`,

} else if (!expectedTopOrigin) {
// If `expectedTopOrigin` is not set, this is an unexpected cross-origin request.
throw new Error(
'Unexpected cross-origin request',
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to stay consistent on "authentication response" in error messages:

Suggested change
'Unexpected cross-origin request',
'Unexpected cross-origin authentication response',

}
});

Deno.test('should NOT check topOrigin when crossOrigin is false', async () => {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is an interesting one. According to the spec, topOrigin should only be set if crossOrigin is true:

It is set only if the call was made from context that is not same-origin with its ancestors, i.e. if crossOrigin is true.

https://w3c.github.io/webauthn/#dom-collectedclientdata-toporigin

Based on this I'd actually make the new code error out if crossOrigin is false but there's a topOrigin defined in clientDataJSON 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants