-
Notifications
You must be signed in to change notification settings - Fork 12
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
VendorTxCode not guaranteed to be unique or unpredictable #32
Comments
Thanks Mark. It looks like that function has lost some code anyway - it should have the time mS appended to the end. Not how or when that disappeared.
If openssl_random_pseudo_bytes() is optional in a PHP installation (and it isn't PECL, so far as I can see, so should more-than-not likely be available) then it should have a fallback. If it is something that will always be available in PHP >5.3, then let's just go for it :-) The makeVendorTxCode() in this package is just an example, and I would hope it would always be overridden. Context may be important to some merchant sites, and not to others. It's often easier when testing, but not so important in production. I'll give the PR a go over the weekend, but it looks good to me (better than the blatant error that I put in there first, without any random element). |
I must have been having a brainstorm at the time. Of course a random element was added to the transaction ID - that is what uniqid() does. Anyway, the change looks good to me, and hopefully will be more secure. This takes to the ID up to its max length, which has always been defined as 40 in the metadata, so this should not break any sites that have been assuming that max length could be used. I'll release this on a point release just in case. https://github.com/academe/SagePay/blob/master/src/Academe/SagePay/Metadata/Transaction.php#L127 |
Thank you for the fix. |
The current implementation of \Academe\SagePay\Model\TransactionAbstract::makeVendorTxCode is not guaranteed to be unique or unpredictable according to the PHP documentation for uniqid.
I would suggest the following function as (a) the transaction will fail if the VendorTxCode is accidentally repeated; (b) this function will not create predictable strings that a malicious user could brute force, if the VendorTxCode is used in any user input.
However, if context is important then you could use the following function. It returns something quite similar to the existing function, but uses the full length allowed by Sagepay:
I have created a pull request with the latter function. Whether you merge it or not is down to your feelings on introducing OpenSSL as a dependency.
The text was updated successfully, but these errors were encountered: