Closed (fixed)
Project:
Drupal core
Version:
main
Component:
base system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
18 Feb 2026 at 10:04 UTC
Updated:
24 Jul 2026 at 09:55 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
mondrakeComment #3
mondrakeParent was committed, this is now actionable.
Comment #6
mondrakeIs this worth doing?
Comment #7
smustgrave commentedDo we have existing instances that need replaced? How often do they appear if it warrants a rule?
Comment #8
mondrake#7 the raw output of the PHPStan job tells where the functions are used. The error could be baselined in the MR, and this would then prevent more usage once committed.
Comment #9
mondrakeReference for md5 and sha1 ban: https://www.drupal.org/docs/7/security/writing-secure-code-0/use-of-hash...
Comment #10
sivaji_ganesh_jojodae commentedThe pipeline has failed due to a PHP linting error.
Comment #11
smustgrave commentedIf you read the comments it was being discussed not for code review
Comment #12
mondrakeYes please, let’s first discuss if this is ok to do.
Comment #13
longwaveI think this is a good idea for md5 and sha1, we should point users to sha256 or xxhash instead I guess? Not sure what to do about uniqid().
Comment #14
mondrake#13 one of these maybe? #2972100-24: Remove usage of uniqid
There was some consensus on
crypt::randomBytesBase64(16)afaicsComment #15
idebr commented#3307718: Implement xxHash for non-cryptographic use-cases suggests replacing md5/sha1 with xxHash alternatives
Comment #16
mondrakeReflected latest comments in the MR - it now redirects sha1() and md5() to use sha256() or hash() with xxHash algo, and uniqid() to use Crypt:: randomBytesBase64().
Rabased and now added errors to the baseline.
Comment #17
smustgrave commentedAwesome to see this one come together. Replacements make sense and probably could spin up follow ups to do the replacements.
Comment #18
godotislateNW for merge conflict in phpstan baseline.
Comment #19
mondrakeMerged with main and resolved a conflict.
Comment #20
poker10 commentedThanks for working on this. Added a comment to the MR, as I think it is not a good idea to link to the Drupal 7 documentation. Also think we should add a CR for this (a similar from the past https://www.drupal.org/node/2833433). Moving to NW for this.
Comment #21
mondrakeAdded draft CR https://www.drupal.org/node/3581605
Comment #22
mondrakeComment #23
mondrakeAddressed @poker10 review, added a draft CR, added more disallows based on what I read. Thanks!
Comment #24
smustgrave commentedFeedback and CR look good
Comment #25
catchcrc32 shouldn't use Crypt::hashBase64(), it should be replaced with
xxHash, the other exclusions in the MR say this.The errorTip links to the change record, but then the change record links back to the errorTip.
I am not sure we should duplicate documentation on e.g. https://xxhash.com/ but I think we probably need to say at least something like:
'Use a cryptographic hashing algorithm when appropriate. Use a fast, low collision, non-cryptographic algorithm when approprate (usually one of the xxHash variants), don't use weak cryptographic algorithms.'
Also while this will stop further cases being added to core, I'm a little bit concerned about committing it with the core usages not converted yet, because when we (hopefully) set a good example in core that's an easy place to follow and refer to.
Comment #26
catchComment #27
mondrakeMaybe we can do #3581442: Replace usage of uniqid() in the Database system first, then.
Comment #28
mondrakeComment #29
mondrake#3581442: Replace usage of uniqid() in the Database system is in, unpostponing.
Comment #30
mondrakeAddressed feedback and adjusted uniqid() to be replaced by bin2hex(random_bytes()) as it was finally done in #3581442: Replace usage of uniqid() in the Database system. Rebased and updated baseline.
Comment #31
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #32
mondrakerebased
Comment #33
smustgrave commented@catch changes look good?
Comment #34
smustgrave commentedGoing on a limb and believe feedback for this one has been addressed.
Comment #35
longwaveThis is in
RecipeTestTrait, so any new recipe test will need this adding to the baseline.Wondering if we should allow uniqid (or any of these functions) in tests? Or if we should just fix this case here?
Comment #36
mondrake#35 changed the test.
IMHO if we determine to disallow, we should do it consistently in both runtime and test code.
Comment #37
smustgrave commentedhttps://git.drupalcode.org/project/drupal/-/merge_requests/15081/diffs?c... appears to have fixed #35 so going to mark it again, fingers crossed
Comment #38
catchDiscussed this with @alexpott in slack.
The various hash algorithms switching to xxHash or an actual cryptographic hash when needed seems fine.
However:
This is not a straight replacement and requires thinking about what to send to random_bytes() etc., we also use uniqid in some places where the potential for collisions is really not an issue like creating a directory name for almost one-off operations.
Alex also pointed out that https://wiki.php.net/rfc/deprecate-uniqid is stalled. If it was unstalled, we wouldn't need this at all because it'd be a PHP deprecation, but with it stalled it's hard to tell what any eventual direction might be.
So I think we should split uniqid() out to its own issue and only cover hash algorithms here.
Comment #39
mondrakeComment #40
mondrakeRemoved uniqid from disallow list.
Comment #41
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #42
mondrakerebased and updated CR
Comment #43
dcam commented@mondrake given #38 what are your thoughts on undoing the change to
RecipeTestTrait? I don't know if it matters or not.Comment #44
mondrake#43 sure, missed that in all the turns here.
Comment #45
dcam commentedUnderstandable. To be honest, I felt kind of bad asking about that after all of the changes and updates this has been through.
The changes related to
uniqid()have been removed. This can go back to RTBC.Comment #46
mondrakeNo worries!
Comment #48
catchI added this to the CR:
Hopefully no-one is still using md5() or sha1() for cryptographic purposes but just in case.
Committed/pushed to main, thanks! This doesn't cherry-pick to 11.x and not sure we need to necessarily, it'll prevent new core usages in all branches.
Tagging for follow-ups to remove the baseline entries we're adding here.
Comment #51
idebr commentedFollowup is available, see #3609780: Replace usage of md5(), sha1(), crc32() and hash() with weak algorithms
Comment #52
mondrakeAlso, #2972100: Remove usage of uniqid is now a sibling of this, and will focus exclusively on
uniqid(). Re #38: it's not just about upstream deprecation decisions IMHO - uniqid() is also performing much worse than alternatives as proven in the related issue.