magento2
magento2 copied to clipboard
CSP Subresource Integrity sri Hashes in checkout_index_index causes big loadingtimes and bytes in multistore and sriHashes vanish after Cache Flush
Preconditions and environment
- Magento version 2.4.5-p8
- loadingtimes increased from 400ms to 800ms
- bytes increased from 50kb to 500kb transmitted
- 27 Stores
Steps to reproduce
Since p8 sri hashes generation is active
Problem 1 all files for all stores are loaded and cause a 6,7 mb big hashmap Problem 2 after cache flush , hashmaps are not generated again and getting lost because save of hashmaps only happens after static deploy
Expected result
only hashmaps for the current store are expected to be generated only hashmaps for used theme are extecpted to be generated cache flush does not remove hashmap or generates them new
Actual result
all stores and themes are hashmapped causing it to be massivly big cache flush leads to empty hashes
Additional information
Vanish after Flush SubresourceIntegrityRepository
/**
* Loads integrity data from a storage.
*
* @return array
*/
private function getData(): array
{
if ($this->data === null) {
$cache = $this->cache->load($this->getCacheKey());
$this->data = $cache ? $this->serializer->unserialize($cache) : []; <-- HERE
}
return $this->data;
}
Release note
CSP Subresource Integrity Hashes generated storewise CSP Subresource Integrity Hashes wont vanish after cache flush
Triage and priority
- [ ] Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- [x] Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- [ ] Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- [ ] Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- [ ] Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
Hi @stkrelax. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:
@magento give me 2.4-develop instance- upcoming 2.4.x release- For more details, review the Magento Contributor Assistant documentation.
- Add a comment to assign the issue:
@magento I am working on this - To learn more about issue processing workflow, refer to the Code Contributions.
Join Magento Community Engineering Slack and ask your questions in #github channel. :warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting. :clock10: You can find the schedule on the Magento Community Calendar page. :telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.
Hi @engcom-Hotel. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
- [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
- [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
- [ ] 3. Add
Area: XXXXXlabel to the ticket, indicating the functional areas it may be related to. - [ ] 4. Verify that the issue is reproducible on
2.4-developbranchDetails
- Add the comment@magento give me 2.4-develop instanceto deploy test instance on Magento infrastructure.
- If the issue is reproducible on2.4-developbranch, please, add the labelReproduced on 2.4.x.
- If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here! - [ ] 5. Add label
Issue: Confirmedonce verification is complete. - [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.
Hello @stkrelax,
Thanks for the report and collaboration!
We have referred to the Dev Docs related to Subresource Integrity and found the below:
So it seems this is an expected behavior, we need to run the bin/magento setup:static-content:deploy command to regenerate the hashes.
Let us know if we missed anything.
Thanks
It's not expected behavior, I'm sure this was not implemented with this in mind. People won't generate static assets after every cache flush, that's just ridiculous.
This needs to be refactored, so SRI hashes are generated once and keep being used even after multiple cache flushes. Storing those in cache, makes no sense whatsoever.
This was already discussed on Slack some months ago, it would surprise me if Adobe isn't already fixing this for one of the next releases.
Thanks @hostep for the detailed explanations. We are confirming this issue for further processing.
Thanks
:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-12858 is successfully created for this GitHub issue.
:white_check_mark: Confirmed by @engcom-Hotel. Thank you for verifying the issue.
Issue Available: @engcom-Hotel, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.
@engcom-Hotel please also consider fixing:
Problem 1 all files for all stores are loaded and cause a 6,7 mb big hashmap
Any update on this issue? When the code fix is going to be released?
Hello @qlhu,
The priority for the issue was raised to P2. The JIRA status of this shows as Implementation but it is not assigned to any developer yet. It means that the issue still waiting for the developer(s) from Community Contributors or Adobe teams who start progress and propose PR with a fix.
Thanks
It's not expected behavior, I'm sure this was not implemented with this in mind. People won't generate static assets after every cache flush, that's just ridiculous.
This needs to be refactored, so SRI hashes are generated once and keep being used even after multiple cache flushes. Storing those in cache, makes no sense whatsoever.
This was already discussed on Slack some months ago, it would surprise me if Adobe isn't already fixing this for one of the next releases.
One workaround to prevent the hashes being flushed from cache, is to clear all the individual caches as follows (or do the same via admin). This leaves the cache entries with the INTEGRITY cache prefix intact. Just don't click the big orange button!
bin/magento cache:clean config layout block_html collections reflection db_ddl compiled_config eav customer_notification config_integration config_integration_api full_page config_webservice translate
Possibly fixed by: https://github.com/magento/magento2/commit/38501f017f24c4c4deb9bbbcfe2563fd51cf4341 ? At least the second problem from the report. Not sure about the first problem.