Skip to content

Commit

Permalink
fix: second attempt at securing mollie redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
SilasPeters committed Dec 20, 2024
1 parent 1207191 commit b697f7b
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions app/controllers/members/payments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,19 @@ def pay_activities
)
if payment.save
# Check URI for safety (supresses brakeman warning)
url = (URI.parse(payment.payment_uri) if payment.payment_uri =~ URI::DEFAULT_PARSER.make_regexp)
redirect_to(url)
url = begin
URI.parse(payment.payment_uri)
rescue StandardError
nil
end

# Check if it's a valid URI and matches your whitelist of acceptable domains (e.g., only http(s)://example.com)
if url.is_a?(URI::HTTP) && ['mollie.com'].include?(url.host)
redirect_to(url)
else
# Fallback to a safe default redirect if the URI is invalid or not in the whitelist
redirect_to(root_path)
end
else
flash[:notice] = I18n.t('failed', scope: 'activerecord.errors.models.payment')
redirect_to(member_payments_path)
Expand Down Expand Up @@ -107,8 +118,19 @@ def add_funds

if payment.save
# Check URI for safety (supresses brakeman warning)
url = (URI.parse(payment.payment_uri) if payment.payment_uri =~ URI::DEFAULT_PARSER.make_regexp)
redirect_to(url)
url = begin
URI.parse(payment.payment_uri)
rescue StandardError
nil
end

# Check if it's a valid URI and matches your whitelist of acceptable domains (e.g., only http(s)://example.com)
if url.is_a?(URI::HTTP) && ['mollie.com'].include?(url.host)
redirect_to(url)
else
# Fallback to a safe default redirect if the URI is invalid or not in the whitelist
redirect_to(root_path)
end
else
flash[:warning] = I18n.t('failed', scope: 'activerecord.errors.models.payment')
redirect_to(members_home_path)
Expand Down

0 comments on commit b697f7b

Please sign in to comment.