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

Redsys: Properly escape special characters in 3DS requests #3537

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
== HEAD
* PayJunctionV2: Send billing address in `auth` and `purchase` transactions [naashton] #3538
* Adyen: Fix some remote tests [curiousepic] #3541
* Redsys: Properly escape cardholder name and description fields in 3DS requests [britth] #3537

== Version 1.105.0 (Feb 20, 2020)
* Credorax: Fix `3ds_transtype` setting in post [chinhle23] #3531
Expand Down
12 changes: 10 additions & 2 deletions lib/active_merchant/billing/gateways/redsys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -426,15 +426,23 @@ def build_merchant_data(xml, data, options = {})
xml.DS_MERCHANT_AMOUNT data[:amount]
xml.DS_MERCHANT_ORDER data[:order_id]
xml.DS_MERCHANT_TRANSACTIONTYPE data[:action]
xml.DS_MERCHANT_PRODUCTDESCRIPTION data[:description]
if data[:description] && data[:threeds]
xml.DS_MERCHANT_PRODUCTDESCRIPTION CGI.escape(data[:description])
else
xml.DS_MERCHANT_PRODUCTDESCRIPTION data[:description]
end
xml.DS_MERCHANT_TERMINAL options[:terminal] || @options[:terminal]
xml.DS_MERCHANT_MERCHANTCODE @options[:login]
xml.DS_MERCHANT_MERCHANTSIGNATURE build_signature(data) unless sha256_authentication?
xml.DS_MERCHANT_EXCEP_SCA data[:sca_exemption] if data[:sca_exemption]

# Only when card is present
if data[:card]
xml.DS_MERCHANT_TITULAR data[:card][:name]
if data[:card][:name] && data[:threeds]
xml.DS_MERCHANT_TITULAR CGI.escape(data[:card][:name])
else
xml.DS_MERCHANT_TITULAR data[:card][:name]
end
xml.DS_MERCHANT_PAN data[:card][:pan]
xml.DS_MERCHANT_EXPIRYDATE data[:card][:date]
xml.DS_MERCHANT_CVV2 data[:card][:cvv]
Expand Down
14 changes: 14 additions & 0 deletions test/unit/gateways/redsys_sha256_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,20 @@ def test_3ds_data_passed
end.respond_with(successful_authorize_with_3ds_response)
end

def test_3ds_data_with_special_characters_properly_escaped
@credit_card.first_name = 'Julián'
stub_comms(@gateway, :ssl_request) do
@gateway.authorize(100, @credit_card, { execute_threed: true, order_id: '156270437866', terminal: 12, sca_exemption: 'LWV', description: 'esta es la descripción' })
end.check_request do |method, endpoint, data, headers|
assert_match(/iniciaPeticion/, data)
assert_match(/<DS_MERCHANT_TERMINAL>12<\/DS_MERCHANT_TERMINAL>/, data)
assert_match(/\"threeDSInfo\":\"CardData\"/, data)
assert_match(/<DS_MERCHANT_EXCEP_SCA>LWV<\/DS_MERCHANT_EXCEP_SCA>/, data)
assert_match(/Juli%C3%A1n/, data)
assert_match(/descripci%C3%B3n/, data)
end.respond_with(successful_authorize_with_3ds_response)
end

def test_moto_flag_passed
stub_comms(@gateway, :ssl_request) do
@gateway.authorize(100, credit_card, { order_id: '156270437866', moto: true, metadata: { manual_entry: true } })
Expand Down