Skip to content
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

Allow valid_origin? to accept subdomains #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 5 additions & 1 deletion lib/wax.ex
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,11 @@ defmodule Wax do
end

defp valid_origin?(client_data, challenge) do
if client_data.origin == challenge.origin do
client_origin = URI.parse(client_data.origin)
challenge_origin = URI.parse(challenge.origin)

if client_origin.scheme == challenge_origin.scheme &&
Copy link
Owner

Choose a reason for hiding this comment

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

Better use the boolean and operator here. Ensure to run Dialyzer even though I think there are some errors.

String.ends_with?(client_origin.host, challenge.rp_id) do
Copy link
Owner

Choose a reason for hiding this comment

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

Looks like one of my comments didn't get through.

I think we would accept a challenge for example.com signed by evil-site-example.com. This is a serious security vulnerability.

Treating origin must be done carefully. Please feel free to get inspiration from Phoenix https://github.com/phoenixframework/phoenix/blob/48ee8cc407f060eee1152f2c8f64bff49a6b4f15/lib/phoenix/socket/transport.ex#L583-L609

When accepting PRs for security libraries, I'd prefer the author to be a public identifiable person. It's an additional protection against introduction of vulnerabilities. Please consider creating a PR with such a profile.

:ok
else
{:error, %Wax.InvalidClientDataError{reason: :origin_mismatch}}
Expand Down