Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ExportCustomerData::customerIsAuthenticated()hashed the customer's secure key before checking whether the customer is logged in at all. A guest has no secure key, so every guest request to that controller went throughsha1(null)- deprecated since PHP 8.1 - before being rejected by the check that follows. The login check now comes first, so the hash is only computed for a request that can actually be authenticated.ExportCustomerDatafront controller without being logged in. Before:sha1(): Passing null to parameter #1 ($string) of type string is deprecated. After: no entry, and the request is still rejected. A logged-in customer with the correct token still exports, and with a wrong token is still refused.What was already fixed, and what was not
The line both issues quote -
psgdpr.php:701- is v1.4.3'ssha1(Context::getContext()->customer->secure_key). Ondevthat block initialises$secureKey = ''and only fills it for a logged-in customer, so it can no longer receive null. That was commit
5a0915f"Fix sha1 deprecation", 2023-09-26.Two things follow from that, and they are worth stating on the issues rather than closing them:
mastercarries module 2.0.2 and still has the unguarded call at line 764.deprecation is live for them whatever
devsays.This PR is about the instance the 2023 fix did not cover.
The remaining instance
The hash is computed before the
isLogged()check that rejects the visitor. Reordering removes thedeprecation and also avoids hashing for a request that cannot be authenticated.
The comparison moves to
hash_equalsat the same time, so the check does not leak the token throughits timing.
FrontAjaxGdpralready compares the same token with===; this brings the two intoline rather than introducing a new convention.
FrontAjaxGdpr.phpneeds no change - itssha1($customer->secure_key)is already inside anisLogged() === truebranch - andcontrollers/front/gdpr.phpredirects an empty customer id beforereaching its own call. So this is the whole class, not one of several.
Verification
Measured on PHP 8.1.33.
sha1(null)raises exactly the reported deprecation;sha1((string) null)does not.Customerhassecure_key === nullandisLogged() === false, so the guest path isthe one that reaches it.
correct token, logged in with a wrong token. Old: 1 deprecation. New: 0. Results identical
in all three cases, so the authentication outcome is unchanged.