-
Notifications
You must be signed in to change notification settings - Fork 53
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
feat: add client data origin validation #15
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
client_data_json: response[:client_data_json] | ||
) | ||
|
||
expect(response.valid?(original_challenge)).to eq(true) | ||
expect(response.valid?(original_challenge, "http:https://localhost:3000")).to eq(true) | ||
end | ||
|
||
it "returns user-friendly error if no client data received" do | ||
|
@@ -22,7 +22,50 @@ | |
) | ||
|
||
expect { | ||
response.valid?("") | ||
response.valid?("", "") | ||
}.to raise_exception(RuntimeError, "Missing client_data_json") | ||
end | ||
|
||
describe "origin validation" do | ||
let(:base_url) { "http:https://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. What about calling this 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. Sounds good 👍 |
||
let(:challenge) { Base64.urlsafe_encode64(SecureRandom.random_bytes(16)) } | ||
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. Same reasoning here, |
||
let(:client_data_json) { hash_to_encoded_json(challenge: challenge, | ||
clientExtensions: {}, | ||
hashAlgorithm: "SHA-256", | ||
origin: origin, | ||
type: "webauthn.create") } | ||
let(:auth_data) { [73, 150, 13, 229, 136, 14, 140, 104, 116, 52, 23, 15, 100, | ||
118, 96, 91, 143, 228, 174, 185, 162, 134, 50, 199, 153, | ||
92, 243, 186, 131, 29, 151, 99, 65, 0, 0, 0, 0].pack('c*') } | ||
let(:attestation_object) { hash_to_encoded_cbor(fmt: "none", | ||
attStmt: {}, | ||
authData: auth_data) } | ||
|
||
context "matches the default one" do | ||
let(:origin) { "http:https://localhost" } | ||
|
||
it "is valid" do | ||
response = WebAuthn::AuthenticatorAttestationResponse.new( | ||
attestation_object: attestation_object, | ||
client_data_json: client_data_json | ||
) | ||
|
||
expect(response.valid?(challenge, base_url)).to be_truthy | ||
end | ||
end | ||
|
||
context "doesn't match the default one" do | ||
let(:origin) { "http:https://invalid" } | ||
|
||
it "isn't valid" do | ||
response = WebAuthn::AuthenticatorAttestationResponse.new( | ||
attestation_object: attestation_object, | ||
client_data_json: client_data_json | ||
) | ||
|
||
expect(response.valid?(challenge, base_url)).to be_falsy | ||
end | ||
end | ||
end | ||
|
||
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. There's already a Do you mind checking if 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. Didn't know about it :). Will address! |
||
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.
Nice! 👏