Skip to content

Commit 75ceb1f

Browse files
feat: add verify_top_origin flag to enable/disable topOrigin validation
1 parent 687d6cf commit 75ceb1f

File tree

6 files changed

+883
-301
lines changed

6 files changed

+883
-301
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ WebAuthn.configure do |config|
107107
# When operating within iframes or embedded contexts, you may need to restrict
108108
# which top-level origins are permitted to host WebAuthn ceremonies.
109109
#
110+
# To enable this check, set the following configuration (disabled by default):
111+
# config.verify_top_origin = false
112+
#
110113
# Each entry in this list must match the `topOrigin` reported by the browser
111114
# during registration and authentication.
112115
#

lib/webauthn/authenticator_response.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def type
131131
end
132132

133133
def needs_top_origin_verification?
134-
client_data.cross_origin || client_data.top_origin
134+
relying_party.verify_top_origin && (client_data.cross_origin || client_data.top_origin)
135135
end
136136
end
137137
end

lib/webauthn/configuration.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class Configuration
2828
:allowed_top_origins=,
2929
:verify_attestation_statement,
3030
:verify_attestation_statement=,
31+
:verify_top_origin,
32+
:verify_top_origin=,
3133
:credential_options_timeout,
3234
:credential_options_timeout=,
3335
:silent_authentication,

lib/webauthn/relying_party.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def initialize(
2424
id: nil,
2525
name: nil,
2626
verify_attestation_statement: true,
27+
verify_top_origin: false,
2728
credential_options_timeout: 120000,
2829
silent_authentication: false,
2930
acceptable_attestation_types: ['None', 'Self', 'Basic', 'AttCA', 'Basic_or_AttCA', 'AnonCA'],
@@ -37,6 +38,7 @@ def initialize(
3738
@id = id
3839
@name = name
3940
@verify_attestation_statement = verify_attestation_statement
41+
@verify_top_origin = verify_top_origin
4042
@credential_options_timeout = credential_options_timeout
4143
@silent_authentication = silent_authentication
4244
@acceptable_attestation_types = acceptable_attestation_types
@@ -52,6 +54,7 @@ def initialize(
5254
:id,
5355
:name,
5456
:verify_attestation_statement,
57+
:verify_top_origin,
5558
:credential_options_timeout,
5659
:silent_authentication,
5760
:acceptable_attestation_types,

0 commit comments

Comments
 (0)