Problem/Motivation
State what you believe is wrong or missing from the current standards.
Proposal:
mirror into the coding standards this standard of using only Drupal's hash helper functions when a hash is needed:
https://www.drupal.org/docs/7/security/writing-secure-code-0/use-of-hash...
The older functions are not significantly faster and offer less collision resistance, which is a key element of hash function quality. If there are (atypical and uncommon) cases where code actually needs a shorter hash string, it is better to truncate a sha-2 hash instead of using one of the deprecated functions:
http://crypto.stackexchange.com/questions/9435/is-truncating-a-sha512-ha...
compared to using sha-1, "truncating one of the SHA-2 functions to 160 bits is around 2^20 times stronger when it comes to collision resistance."
Note that 160 bits means taking 27 characters of the base64 encoded output. The absolute minimum substring length used should be 21 chars (126 bits) of base 64 output. Any use of a substring should be clearly justified in code comments.
Basically - it should be a coding standards violation and flagged automatically if people are using a different method to hash values.
related current core patch: #2569119: Use Crypt::hashBase64(), not hash('crc32b') or sha1 for placeholder tokens
Prior coding standard issue for Core that's too meandering: #2268875: [Policy, no patch] Using md5()/sha1()/crc32b in Drupal code
Benefits
If we adopted this change, the Drupal Project would benefit by ...
Three supporters required
- https://www.drupal.org/u/{userid} (yyyy-mm-dd they added support)
- https://www.drupal.org/u/{userid} (yyyy-mm-dd they added support)
- https://www.drupal.org/u/{userid} (yyyy-mm-dd they added support)
Proposed changes
Provide all proposed changes to the Drupal Coding standards. Give a link to each section that will be changed, and show the current text and proposed text as in the following layout:
1. {link to the documentation heading that is to change}
Current text
Add current text in blockquotes
Proposed text
Add proposed text in blockquotes
2. Repeat the above for each page or sub-page that needs to be changed.
Remaining tasks
Create this issue in the Coding Standards queue, using the defined template- Add supporters
- Create a Change Record
- Review by the Coding Standards Committee
- Coding Standards Committee takes action as required
- Discussed by the Core Committer Committee, if it impacts Drupal Core
- Final review by Coding Standards Committee
- Documentation updates
- Edit all pages
- Publish change record
- Remove 'Needs documentation edits' tag
- If applicable, create follow-up issues for PHPCS rules/sniffs changes
For a full explanation of these steps see the Coding Standards project page
Comments
Comment #2
pwolanin commentedComment #3
greggles(just cleaning up some language, don't mind me)
Comment #4
pwolanin commentedComment #5
jthorson commentedThis was brought up at the last coding standards meeting. To help facilitate discussion, we'd like to request an update to the issue summary, with proposed wording and a suggested location for where it would be inserted into the existing coding standards documentation.
Comment #6
drunken monkeyGreat idea! I see I also have some use of SHA-1 and even MD5 in my modules, not really justified in any way.
Having this as a coding standard should help make people aware of this problem.
(And we already have a standard for always using
t()calls, so there cannot really be any discussion about whether coding standards are the right place for such a rule.)Comment #7
lokesh jamadar commentedComment #8
quietone commentedRemoving assignment since this hasn't been worked on for over 2 years.
Comment #9
quietone commentedThere has been no work here in 8 years, usually indicative of no interest in a change.
If there is interest then complete the issue summary thanks. Otherwise this issue may be closed after 3 months.
Comment #10
quietone commentedComment #11
quietone commentedComment #12
quietone commentedThere is no interest in this for 9 years. I asked 1 year ago here and two weeks ago in the coding standards Slack channel. Only Jonathan105 replied, supporting the idea of closing this.
If you disagree, this can be re-opened. Or you can create a new issue and reference this one.
Thanks.