wp-background-processing icon indicating copy to clipboard operation
wp-background-processing copied to clipboard

Improve Security by Replacing MD5 Hash Function in generate_key Method

Open kiransbsf opened this issue 1 year ago • 1 comments

The current implementation of the generate_key method in the wp-background-process.php, class uses the `md5' hash function to generate unique keys for batch processing. Snyk.io has reported a vulnerability associated with this usage, citing that 'md5' is insecure and susceptible to collision attacks.

Issue Details:

File: wp-background-process.php

Current Implementation:

protected function generate_key( $length = 64, $key = 'batch' ) {
    $unique  = md5( microtime() . wp_rand() );
    $prepend = $this->identifier . '_' . $key . '_';

    return substr( $prepend . $unique, 0, $length );
}

Vulnerability: Use of Password Hash With Insufficient Computational Effort

Suggested Improvement: To enhance the security of the codebase, it is recommended to replace the 'md5' hash function with a more secure alternative, such as SHA-256, which provides better resistance against collision attacks. The updated implementation:

protected function generate_key( $length = 64, $key = 'batch' ) {
    $unique  = hash( 'sha256', microtime() . wp_rand() );
    $prepend = $this->identifier . '_' . $key . '_';

    return substr( $prepend . $unique, 0, $length );
}

By making this change, we can ensure that the unique keys generated are more secure and less susceptible to attacks.

kiransbsf avatar Aug 02 '24 05:08 kiransbsf

The md5 string just serves as a unique identifier here, its not a security token

koen12344 avatar Dec 09 '24 12:12 koen12344

Like @koen12344 said, md5 is just used as a fast way of creating a relatively unique batch key for a database record, there's security issue here.

ianmjones avatar Nov 03 '25 14:11 ianmjones