Skip to content

Commit 5d6283a

Browse files
committed
Fix XSS vulnerability on Stripe payment page
1 parent a1f60d1 commit 5d6283a

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
### Unreleased
44

5+
* [SECURITY] Fix XSS vulnerability in back parameter on Stripe payment page
6+
Previously, an attacker could inject Javascript or redirect the user to any URL by changing the `back` parameter in the URL.
7+
The `back` parameter is now sanitized and restricted to relative paths.
58
* Remove unused attributes for `plan` and `quantity` in `app/models/pay/customer.rb`.
69
* Add explicit requires for `active_support` and `action_mailer` in `lib/pay.rb`. This should provide better errors for anyone not requiring all of Rails.
710

app/controllers/pay/payments_controller.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@ module Pay
22
class PaymentsController < ApplicationController
33
layout "pay/application"
44

5+
before_action :set_redirect_to
6+
57
def show
6-
@redirect_to = params[:back].presence || root_path
78
@payment = Payment.from_id(params[:id])
89
end
10+
11+
private
12+
13+
# Ensure the back parameter is a valid path
14+
# This safely handles XSS or external redirects
15+
def set_redirect_to
16+
@redirect_to = URI.parse(params[:back].to_s).path || root_path
17+
end
918
end
1019
end

app/views/pay/payments/show.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
</div>
5555
<% end %>
5656

57-
<%= link_to t("pay.back"), @redirect_to, class: "inline-block w-full px-4 py-3 bg-gray-100 hover:bg-gray-200 text-center text-gray-600 rounded-lg" %>
57+
<%= sanitize link_to(t("pay.back"), @redirect_to, class: "inline-block w-full px-4 py-3 bg-gray-100 hover:bg-gray-200 text-center text-gray-600 rounded-lg") %>
5858
</div>
5959

6060
<p class="text-center text-gray-500 text-sm">

0 commit comments

Comments
 (0)