Problem/Motivation

#3573259: Prevent new expects($this->any()) in tests introduced spaze/phpstan-disallowed-calls as a dev dependency.

We can now leverage on the extension to disallow usage of uniqid(), md5(), sha1().

Proposed resolution

do it

Remaining tasks

decide if we want to do this

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3574204

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mondrake created an issue. See original summary.

mondrake’s picture

mondrake’s picture

Status: Postponed » Active

Parent was committed, this is now actionable.

mondrake changed the visibility of the branch 3574204-disallow-usage-of to hidden.

mondrake’s picture

Status: Active » Needs review

Is this worth doing?

smustgrave’s picture

Do we have existing instances that need replaced? How often do they appear if it warrants a rule?

mondrake’s picture

Component: phpunit » base system

#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.

mondrake’s picture

sivaji_ganesh_jojodae’s picture

Status: Needs review » Needs work

The pipeline has failed due to a PHP linting error.

smustgrave’s picture

If you read the comments it was being discussed not for code review

mondrake’s picture

Issue summary: View changes
Status: Needs work » Needs review

Yes please, let’s first discuss if this is ok to do.

longwave’s picture

I 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().

mondrake’s picture

#13 one of these maybe? #2972100-24: Remove usage of uniqid

There was some consensus on crypt::randomBytesBase64(16) afaics

idebr’s picture

#3307718: Implement xxHash for non-cryptographic use-cases suggests replacing md5/sha1 with xxHash alternatives

mondrake’s picture

Reflected 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.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Awesome to see this one come together. Replacements make sense and probably could spin up follow ups to do the replacements.

godotislate’s picture

Status: Reviewed & tested by the community » Needs work

NW for merge conflict in phpstan baseline.

mondrake’s picture

Status: Needs work » Reviewed & tested by the community

Merged with main and resolved a conflict.

poker10’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record

Thanks 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.

mondrake’s picture

mondrake’s picture

Title: Disallow usage of uniqid(), md5(), sha1() » Disallow usage of uniqid(), md5(), sha1(), crc32() and hash() with weak algorithms
Issue tags: -Needs change record
mondrake’s picture

Status: Needs work » Needs review

Addressed @poker10 review, added a draft CR, added more disallows based on what I read. Thanks!

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Feedback and CR look good

catch’s picture

crc32 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.

catch’s picture

Status: Reviewed & tested by the community » Needs work
mondrake’s picture

Status: Needs work » Postponed
Related issues: +#3581442: Replace usage of uniqid() in the Database system