Problem/Motivation
catch/dawehner pointed out that SHA1 is overkill for placeholder tokens, since they don't need to be cryptographically secure.
Proposed resolution
Use CRC32 instead of SHA1.
Remaining tasks
None.
User interface changes
None.
API changes
None.
Data model changes
None.
Beta phase evaluation
| Issue category | Task because just an improvement. |
|---|---|
| Issue priority | Normal because we can easily ship without this. |
| Prioritized changes | The main goal of this issue is consistency/DX: SHA1 is overkill for this use case, and core should set the right example. |
| Disruption | Zero disruption. |
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | change_placeholder-2542830-23.patch | 2.39 KB | borisson_ |
| #23 | interdiff.txt | 2.39 KB | borisson_ |
Comments
Comment #1
dawehnerThere are also quite a lot of Crypt:: placeholders floating around.
Comment #3
RavindraSingh commentedUpdated with Crypt::hashBase64(serialize($placeholder_render_array));
Needs tests also.
Comment #4
dawehnerIMHO we better want to switch to a different way than crypt in order to make it clear, that we don't deal about something security related here.
Comment #6
borisson_Fixes the failures introduced in the initial patch.
Comment #7
RavindraSingh commented#6 Looks good. manually reviewed the patch.
Verified - Crc32 is being used correctly. making it RTBC.
Comment #8
dawehnerAlright, we we don't want to convert Crypt::hashBase64 over here, does someone mind opening up a follow up for that?
Comment #9
wim leersComment #12
borisson_Back to rtbc, the failure is unrelated to this patch.
Comment #13
wim leersWe should use
hash('crc32b')instead, see #2546680: Use hash('crc32b') not crc32().Comment #14
pieterjanput commentedComment #15
wim leersOops — these re-introduce SHA1. :)
Comment #16
pieterjanput commentedComment #17
wim leersComment #18
catchThis is a case where we might want to be concerned about hash collisions. I'm not sure if that's a real issue, but compared to any other usage it's more likely to be a problem.
Comment #19
catchComment #20
olli commentedIssue title says to switch from sha1 to crc32b, not crc32.
#18: Would md5 or another algorithm be better here?
Comment #21
borisson_Comment #22
wim leersAwesome point!
I think that if the placeholders were using solely the CRC32 check, that we could indeed have a problem. There are 2^32 (>4 billion) possible hashes. But, more importantly, the hash here is only a subset of the placeholder. We always also list the callback and arguments. This was originally done not to avoid collisions, but to improve debuggability. But now, it effectively helps to avoid collisions.
#20: indeed. I missed that.
Comment #23
borisson_Resolved #20 by using crc32b.
@Wim Leers explained why crc32b is enough in #22 so #18 shouldn't be a problem anymore.
Comment #24
wim leersThis is going to conflict with #2543334: Auto-placeholdering for #lazy_builder with bubbling of contexts and tags, but that's easy enough to resolve.
Comment #25
alexpottSo do we need to force a cache clear or something because placeholders are changing - is there an upgrade path implication here?
Comment #26
wim leersNo, because:
foobarcan be used as a placeholder.#markuphave the associated#attached[placeholders]already, so there is always guaranteed to be a 1:1 mappingComment #27
wim leersIn other words: any cached render array is fully internally consistent. It doesn't matter if the outside world changes.
Comment #28
catchI don't think so since update.php does a drupal_flush_all_caches() whether or not there are updates to run:
https://api.drupal.org/api/drupal/core%21modules%21system%21src%21Contro...
https://api.drupal.org/api/drupal/core%21modules%21system%21src%21Contro...
Comment #29
wim leersRewrote IS and added beta evaluation.
Comment #30
dawehnerCatch is certainly right here, I ran into that, while working on #2540416: Move update.php back to a front controller
Comment #31
alexpottCommitted 9f12768 and pushed to 8.0.x. Thanks!
Thanks for adding the beta evaluation to the issue summary.