Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixed

- Update `RelyingParty#origin` and `WebAuthn.configuration.origin` to return the allowed origin if allowed origins has only one element.

## [v3.4.2] - 2025-09-22

### Added
Expand Down
13 changes: 12 additions & 1 deletion lib/webauthn/relying_party.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def initialize(
:acceptable_attestation_types,
:legacy_u2f_appid

attr_reader :attestation_root_certificates_finders, :origin
attr_reader :attestation_root_certificates_finders

# This is the user-data encoder.
# Used to decode user input and to encode data provided to the user.
Expand Down Expand Up @@ -121,6 +121,17 @@ def verify_authentication(
end
end

# DEPRECATED: This method will be removed in future.
def origin
warn(
"DEPRECATION WARNING: `WebAuthn.origin` is deprecated and will be removed in future. "\
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this say WebAuthn.configuration.origin instead? 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's a good call! I actually made it so that it display message as the one we currently have.

Either way, this is confusing because the method is in RelyingParty, not in WebAuth::Configuration... perhaps we could make it so that it throws a different validation depending if you are calling RelyingParty#origin or WebAuth::Configuration#origin, but I'd leave it for a separate PR.

What do you think?

"Please use `WebAuthn.allowed_origins` instead "\
"that also allows configuring multiple origins per Relying Party"
)

allowed_origins.first if allowed_origins&.size == 1
end

# DEPRECATED: This method will be removed in future.
def origin=(new_origin)
return if new_origin.nil?
Expand Down
36 changes: 36 additions & 0 deletions spec/webauthn/relying_party_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,42 @@
end
end

describe '#origin' do
subject do
old_verbose, $VERBOSE = $VERBOSE, nil # Silence warnings to avoid deprecation warnings

rp.origin
ensure
$VERBOSE = old_verbose
end

context 'when relying party has only one allowed origin' do
let(:rp) do
WebAuthn::RelyingParty.new(allowed_origins: ["https://admin.example.test"])
end

it 'returns that allowed origin' do
is_expected.to eq("https://admin.example.test")
end
end

context 'when relying party has multiple allowed origins' do
let(:rp) do
WebAuthn::RelyingParty.new(allowed_origins: ["https://admin.example.test", "https://newadmin.example.test"])
end

it { is_expected.to be_nil }
end

context 'when relying party has not set its allowed origins' do
let(:rp) do
WebAuthn::RelyingParty.new(allowed_origins: nil)
end

it { is_expected.to be_nil }
end
end

context "without having any global configuration" do
let(:consumer_rp) do
WebAuthn::RelyingParty.new(
Expand Down
Loading