Skip to content

Commit 458d738

Browse files
author
Vitalii Tereshchenko
committed
feat-allow-multiple-origins
* add deprecation warning
1 parent e0261d0 commit 458d738

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

lib/webauthn/authenticator_response.rb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,20 @@ def initialize(client_data_json:, relying_party: WebAuthn.configuration.relying_
2525
end
2626

2727
def verify(expected_challenge, expected_origin = nil, user_verification: nil, rp_id: nil)
28-
expected_origin ||= relying_party.origin || relying_party.allowed_origins || raise("Unspecified expected origin")
28+
expected_origin ||= relying_party.allowed_origins || [relying_party.origin] || raise("Unspecified expected origin")
2929
rp_id ||= relying_party.id
3030

3131
verify_item(:type)
3232
verify_item(:token_binding)
3333
verify_item(:challenge, expected_challenge)
3434
verify_item(:origin, expected_origin)
3535
verify_item(:authenticator_data)
36-
verify_item(:rp_id, rp_id || rp_id_from_origin(expected_origin))
36+
37+
# note: we are not trying to guess from 'expected_origin' since it is an array
38+
verify_item(
39+
:rp_id,
40+
rp_id || rp_id_from_origin(relying_party.origin)
41+
)
3742

3843
if !relying_party.silent_authentication
3944
verify_item(:user_presence)
@@ -83,17 +88,12 @@ def valid_challenge?(expected_challenge)
8388
end
8489

8590
# @return [Boolean]
86-
# @param [String, Array<String>] expected_origin
87-
# Validate if origin configured for RP is matching the one received from client
91+
# @param [Array<String>] expected_origin
92+
# Validate if one of the allowed origins configured for RP is matching the one received from client
8893
def valid_origin?(expected_origin)
8994
return false unless expected_origin
9095

91-
case expected_origin
92-
when Array
93-
expected_origin.include?(client_data.origin) # allow multiple origins as per spec
94-
else
95-
client_data.origin == expected_origin # keep the default behaviour for backwards compatibility
96-
end
96+
expected_origin.include?(client_data.origin)
9797
end
9898

9999
# @return [Boolean]
@@ -120,6 +120,7 @@ def valid_user_verified?
120120
end
121121

122122
# @return [String, nil]
123+
# @param [Array[String]] expected_origin
123124
# Extract RP ID from origin in case rp_id is not provided explicitly
124125
# Note: In case origin is an array, we can not guess anymore since any guess would end up being wrong
125126
def rp_id_from_origin(expected_origin)

lib/webauthn/relying_party.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def initialize(
3232
@algorithms = algorithms
3333
@encoding = encoding
3434
@origin = origin
35-
@allowed_origins = allowed_origins.nil? ? [origin] : allowed_origins
35+
@allowed_origins = allowed_origins
3636
@id = id
3737
@name = name
3838
@verify_attestation_statement = verify_attestation_statement
@@ -41,6 +41,13 @@ def initialize(
4141
@acceptable_attestation_types = acceptable_attestation_types
4242
@legacy_u2f_appid = legacy_u2f_appid
4343
self.attestation_root_certificates_finders = attestation_root_certificates_finders
44+
45+
if allowed_origins.nil? && !origin.nil?
46+
warn(
47+
"DEPRECATION WARNING: `WebAuthn.origin` is deprecated and will be removed in future"\
48+
" Please use `WebAuthn.allowed_origins` instead that also allows configuring multiple origins per Relying Party"
49+
)
50+
end
4451
end
4552

4653
attr_accessor :algorithms,

0 commit comments

Comments
 (0)