magento2 icon indicating copy to clipboard operation
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

Open stkrelax opened this issue 1 year ago • 8 comments

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

grafik

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

stkrelax avatar Jul 23 '24 14:07 stkrelax

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:


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.

m2-assistant[bot] avatar Jul 23 '24 14:07 m2-assistant[bot]

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: XXXXX label to the ticket, indicating the functional areas it may be related to.
  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch
    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced 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: Confirmed once verification is complete.
  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

m2-assistant[bot] avatar Aug 28 '24 07:08 m2-assistant[bot]

Hello @stkrelax,

Thanks for the report and collaboration!

We have referred to the Dev Docs related to Subresource Integrity and found the below:

image

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

engcom-Hotel avatar Aug 28 '24 07:08 engcom-Hotel

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.

hostep avatar Aug 28 '24 08:08 hostep

Thanks @hostep for the detailed explanations. We are confirming this issue for further processing.

Thanks

engcom-Hotel avatar Aug 29 '24 13:08 engcom-Hotel

:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-12858 is successfully created for this GitHub issue.

github-jira-sync-bot avatar Aug 29 '24 13:08 github-jira-sync-bot

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

m2-assistant[bot] avatar Aug 29 '24 13:08 m2-assistant[bot]

@engcom-Hotel please also consider fixing:

Problem 1 all files for all stores are loaded and cause a 6,7 mb big hashmap

stkrelax avatar Aug 29 '24 13:08 stkrelax

Any update on this issue? When the code fix is going to be released?

qlhu avatar Oct 25 '24 00:10 qlhu

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

engcom-Hotel avatar Oct 25 '24 06:10 engcom-Hotel

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

dphilipps avatar Jan 22 '25 11:01 dphilipps

Possibly fixed by: https://github.com/magento/magento2/commit/38501f017f24c4c4deb9bbbcfe2563fd51cf4341 ? At least the second problem from the report. Not sure about the first problem.

hostep avatar Mar 06 '25 07:03 hostep