-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
What's the proper way to redirect from external payment Gateway with POST redirect and still use SameSite: Lax? #38889
Comments
Hi @ioweb-gr. Thank you for your report.
Join Magento Community Engineering Slack and ask your questions in #github channel. |
Hi @engcom-Hotel. Thank you for working on this issue.
|
Hello @ioweb-gr, Thanks for the report and collaboration! We have gone through with your issue, in your case, you're trying to make it work with "Lax" mode. However, the issue is that the session cookie is not sent when the user is redirected back to your site from the payment gateway. This is because the browser sees this as a cross-site request and, due to the "Lax" setting, does not include the session cookie in the request. As a result, Magento can't associate the request with a session and creates a new, empty session. The PayPal module gets around this by using an intermediate page that submits a form to the final destination. This form submission is seen as a same-site request by the browser, so the session cookie is included in the request. But it seems to us an expected behavior and like PayPal handles the situation, Cardlink also handles similarly. Can you please raise the same issue with them? Please let us know if we missed anything here. Thanks |
first of all let me clarify that this module is the attempt I made to handle it like PayPal. So it's a modified version of the original. The original can be found here https://github.com/Cardlink-SA/cardlink-payment-gateway-magento2x and as you said is suffering from SameSite issue. Basically: In the original caseUser is redirected to the payment gateway and pays In my modified versionI tried to replicate what Paypal does, by using the transparent redirect you mention that creates an internal page, a form with the orignal post data, which is automatically submitted to the processor. I'm not sure if I've misinterpreted something from the Paypal module, but it seemed to me that's the way it handles it as you also mention
However in my module as you can see even if the process looks identical to paypal, again I'm facing the issue that on the actual ResponseProcessor controller which gets triggered after the second submission (from the same site) triggered by the ResponseController, still I don't have the proper session. Basically the checkout session inside ResponseProcessor which is invoked after the automatic submission of the form rendered by the Response controller which processes the original request from Cardlink is still empty. However after ResponseProcessor is done and redirects to the success page, the session is there properly. To visualize this According to my understanding during the internal redirect from one magento controller to the other, the session should have been recovered but it isn't until the final GET request is done. |
Thanks @ioweb-gr for the clarification! We are confirming this issue for further processing. Thanks |
✅ Jira issue https://jira.corp.adobe.com/browse/AC-12330 is successfully created for this GitHub issue. |
✅ Confirmed by @engcom-Hotel. Thank you for verifying the issue. |
Hi @engcom-Hotel thank you for confirming the issue. Do you think you can ask the core developers who created the paypal module to provide some insight as to what extra does the PayPal module do to retain the session? This is a very important issue since we are prevented from integrating with payment gateways. |
Any update on this issue and what paypal does different to handle this use case?> |
I've done some further digging by adding a log in each step on a similar integration suffering from the same issue. It seems that the session_id exists in
So basically even though the cookie exists, and the PHPSESSID is set, the magento session is empty when it reaches the final processing URL But at the same time php's session_id function returns nothing after the redirect. So the session is indeed lost right after the redirect from the payment gateway to the magento url |
Summary
I've read many of the SameSite issues and possible solutions / workarounds on the repo issues, however so far the only real way of making this work is setting SameSite to None.
My question is about how to make it work with Lax mode and how Paypal integration works.
I've been checking the paypal module and it seems to preserve the session for the logged in user, it uses this plugin
This effectively makes the session not be destroyed and the user stays logged in.
However on the initial controller which handles the response in my case
cardlink_checkout/payment/response
When fetching the CheckoutSession via Factory or via Proxy or Plain with the class through DI, it's an empty session.
I've read further into the paypal integration and saw that it uses an intermediate redirect by intercepting the initial POST request
Which effectively renders a form which submits again the same data but from the same domain
the URL is declared in di.xml
However when reaching the response controller equivalent in the module I'm trying to patch, I still can't get the CheckoutSession properly and it's entirely empty.
Furthermore, when setting the data to it for the LastSuccessQuoteId and redirecting to
checkout/onepage/success
controller, I notice that there, the checkoutSession is restored entirely to the previous state, before my modification. Thus because the LastSuccessQuoteId is not there in that state, I'm redirected to cart instead.So I'm assuming here that something extra is being done in the paypal gateway to retain the actual CheckoutSession and modify that one instead of creating a new empty one.
However I'm unable to find any type of documentation regarding this. In the official docs, there's no mention of how to tackle SameSite and also it is left in the responsibility of each payment gateway to fix it. However this is a problem for Magento itself and us developers trying to fix the gateway modules without nuking the settings to make the cookies set Samesite to "None"
As far as I can see in the network tab, the PHPSESSID is there in all requests, but the cookie isn't.
On redirecting to payment provider
On redirecting to the response handler which creates the "proxy" form as expected nothing is there
On the actual processor everything is there except the PHPSESSID cookie for some reason in the response and in the request the PHPSESS ID is actually there
And on the
checkout/onepage/success
controller which can also see the original CheckoutSession I can see everything there as well.So my question is what's the missing step to actually fetch the proper CheckoutSession after the "proxy" form redirects to the actual processor.
Assuming of course what paypal module shows in
transparent/redirect
classes / phtml files is the correct approach.If not, what's the correct approach to achieve this while still using
SameSite = Lax
.Examples
cardlink.zip
here's an example module provided by Cardlink a major payment gateway in Greece.
Their proposal was to change SameSite to "None" as well.
I'm particularly curious as to why the information for the session is transferred properly when redirecting from the
responseProcessor
tocheckout/onepage/success
controller on redirect 2 while not transferred properly when redirecting from theresponse
controller to theresponseProcessor
on redirect 1 because if the information is there in redirect 2, why wouldn't it be available in redirect 1?Any help is appreciated
Proposed solution
No response
Release note
No response
Triage and priority
The text was updated successfully, but these errors were encountered: