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

Deprecated: preg_match() Passing null in getClientIp() #177

Closed
jamieburchell opened this issue Mar 8, 2022 · 8 comments · Fixed by #179
Closed

Deprecated: preg_match() Passing null in getClientIp() #177

jamieburchell opened this issue Mar 8, 2022 · 8 comments · Fixed by #179

Comments

@jamieburchell
Copy link
Contributor

jamieburchell commented Mar 8, 2022

I'm seeing this on PHP 8.1 using v4:

Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated

Coming from here (omnipay/sagepay/src/Message/DirectAuthorizeRequest.php in Omnipay\SagePay\Message\DirectAuthorizeRequest::getClientIp at line 138)

I'm not sure why the IP can be null at that point, but here we are.

@judgej
Copy link
Member

judgej commented Mar 8, 2022

Thank you. It looks like parent::getClientIp() is returning null, which is understandable if running tests and the tests don't explicitly set the IP address.

It needs to skip the regex check if the IP address is already null, or is not a string.

@jamieburchell
Copy link
Contributor Author

Strange thing is, this wasn't the result of running tests. This happened in production.

@judgej
Copy link
Member

judgej commented Mar 8, 2022

Just checked the core and I completely forgot that it is the application that supplies the IP address. I'm guessing your application isn't providing the client IP. A quick workaround would be to pass in anything that is not a valid IPv4 and not a null. An empty string would work.

$request->setClientIp('');

Just for some background, what the regex does, is to make sure the IP address is IPv4, and blanks it out if it isn't. Sage Pay would error (last I checked) if the IP was not in the a.b.c.d format. So it is not essential the IP address is sent (though for 3DS v2 maybe it is, but not at this point?)

The error is a PHP 8.1 deprecation warning being converted into an exception in your application (or maybe these are just beig displayed as warnings?). Another workaround would be to catch and log those, but not convert them into an exception (or not display the warnings). Laravel can do this with the deprecation log (very handy) and your framework may do something similar.

@jamieburchell
Copy link
Contributor Author

jamieburchell commented Mar 8, 2022

Not sure if relevant, but I'm using the server integration and ClientIPAddress isn't a thing so I would have no need to set this. I think my PR still stands.

@judgej
Copy link
Member

judgej commented Mar 8, 2022

Yeah, PR looks good. It was PHP 8.1 that has brought this deprecation notice - what you are [not] setting is good too. I was just trying to think of a quick workaround that would fix the problem for you.

@judgej
Copy link
Member

judgej commented Mar 8, 2022

Also if clientIp is not even used in the server integration, then I think changes are needed so that it does not try to fetch it in the first place. Sage Pay Direct accepts the client IP address, since it does not directly see the client, The Server integration has a visit from the client browser, so it can see the client IP address for itself.

@jamieburchell
Copy link
Contributor Author

jamieburchell commented Mar 8, 2022

I don't think I can assist with refactoring that. I believe a lot of the Server code extends the Direct code? There is a lot that's set in DirectAuthorizeRequest::getBaseAuthorizeData that isn't relevant for Server.

@judgej
Copy link
Member

judgej commented Mar 8, 2022

np - thanks again - I've merged and made a patch release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants