-
Couldn't load subscription status.
- Fork 66
fix: update origin handling to support wildcard origins #472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -91,7 +91,7 @@ | |||||
| def valid_origin?(expected_origin) | ||||||
| return false unless expected_origin | ||||||
|
|
||||||
| expected_origin.include?(client_data.origin) | ||||||
| Array(expected_origin).any? { |allowed_origin| allowed_origin === client_data.origin } | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. chore: although it's not implied by the name of the variable,
Suggested change
|
||||||
| end | ||||||
|
|
||||||
| def valid_rp_id?(rp_id) | ||||||
|
|
@@ -115,7 +115,9 @@ | |||||
| end | ||||||
|
|
||||||
| def rp_id_from_origin(expected_origin) | ||||||
| URI.parse(expected_origin.first).host if expected_origin.size == 1 | ||||||
| return unless valid_origin?(expected_origin) | ||||||
|
|
||||||
| URI.parse(client_data.origin).host if expected_origin.size == 1 | ||||||
|
Comment on lines
+118
to
+120
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue: I see why we have to do this, but I don't think we should be changing the If that's desired, I think users of this gem should instead use our instance based configuration for handling this. However, I think we have other options similar to what we did when we added the support for declaring multiple allowed origins: we could assume we won't be able to infer the What do you think? |
||||||
| end | ||||||
|
|
||||||
| def type | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -160,6 +160,10 @@ def fake_origin | |
| "http://localhost#{rand(1000)}.test" | ||
| end | ||
|
|
||
| def fake_wildcard_origin | ||
| /http:\/\/localhost.*/ | ||
| end | ||
|
Comment on lines
+163
to
+165
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. chore: this is not used, right? Should we remove it or was it added for a particular reason? |
||
|
|
||
| def type_for(method) | ||
| TYPES[method] | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,10 @@ def fake_origin | |
| "http://localhost" | ||
| end | ||
|
|
||
| def fake_wildcard_origin | ||
| /http:\/\/localhost.*/ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thought: perhaps we should document in some way that, in order for wildcard domains to work, a regexp should be provided. From the Rails' guides I found that they do it for
What do you think? |
||
| end | ||
|
|
||
| def fake_challenge | ||
| SecureRandom.random_bytes(32) | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,8 +12,8 @@ | |
| let!(:credential) { create_credential(client: client) } | ||
| let(:credential_public_key) { credential[1] } | ||
|
|
||
| let(:origin) { fake_origin } | ||
| let(:actual_origin) { origin } | ||
| let(:origin) { fake_wildcard_origin } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: I would keep the "normal" origin declaration here and just add an additional context under the "origin validation" section. What do you think? |
||
| let(:actual_origin) { fake_origin } | ||
| let(:original_challenge) { fake_challenge } | ||
| let(:assertion) { client.get(challenge: original_challenge) } | ||
| let(:authenticator_data) { assertion["response"]["authenticatorData"] } | ||
|
|
@@ -429,7 +429,7 @@ | |
| original_challenge, | ||
| public_key: credential_public_key, | ||
| sign_count: 0, | ||
| rp_id: URI.parse(origin).host | ||
| rp_id: URI.parse(actual_origin).host | ||
| ) | ||
| ).to be_truthy | ||
| end | ||
|
|
@@ -440,7 +440,7 @@ | |
| original_challenge, | ||
| public_key: credential_public_key, | ||
| sign_count: 0, | ||
| rp_id: URI.parse(origin).host | ||
| rp_id: URI.parse(actual_origin).host | ||
| ) | ||
| ).to be_truthy | ||
| end | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This follows how the wildcard origin matching handled in ActionCable: https://github.com/rails/rails/blob/cfc9b90f70d64a83b0aadec72bd858b197e2d733/actioncable/lib/action_cable/connection/base.rb#L234