File tree 1 file changed +26
-4
lines changed
1 file changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -47,8 +47,19 @@ def pay_activities
47
47
)
48
48
if payment . save
49
49
# Check URI for safety (supresses brakeman warning)
50
- url = ( URI . parse ( payment . payment_uri ) if payment . payment_uri =~ URI ::DEFAULT_PARSER . make_regexp )
51
- redirect_to ( url )
50
+ url = begin
51
+ URI . parse ( payment . payment_uri )
52
+ rescue StandardError
53
+ nil
54
+ end
55
+
56
+ # Check if it's a valid URI and matches your whitelist of acceptable domains (e.g., only http(s)://example.com)
57
+ if url . is_a? ( URI ::HTTP ) && [ 'mollie.com' ] . include? ( url . host )
58
+ redirect_to ( url )
59
+ else
60
+ # Fallback to a safe default redirect if the URI is invalid or not in the whitelist
61
+ redirect_to ( root_path )
62
+ end
52
63
else
53
64
flash [ :notice ] = I18n . t ( 'failed' , scope : 'activerecord.errors.models.payment' )
54
65
redirect_to ( member_payments_path )
@@ -107,8 +118,19 @@ def add_funds
107
118
108
119
if payment . save
109
120
# Check URI for safety (supresses brakeman warning)
110
- url = ( URI . parse ( payment . payment_uri ) if payment . payment_uri =~ URI ::DEFAULT_PARSER . make_regexp )
111
- redirect_to ( url )
121
+ url = begin
122
+ URI . parse ( payment . payment_uri )
123
+ rescue StandardError
124
+ nil
125
+ end
126
+
127
+ # Check if it's a valid URI and matches your whitelist of acceptable domains (e.g., only http(s)://example.com)
128
+ if url . is_a? ( URI ::HTTP ) && [ 'mollie.com' ] . include? ( url . host )
129
+ redirect_to ( url )
130
+ else
131
+ # Fallback to a safe default redirect if the URI is invalid or not in the whitelist
132
+ redirect_to ( root_path )
133
+ end
112
134
else
113
135
flash [ :warning ] = I18n . t ( 'failed' , scope : 'activerecord.errors.models.payment' )
114
136
redirect_to ( members_home_path )
You can’t perform that action at this time.
0 commit comments