magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.45k stars 9.29k forks source link

CSP Subresource Integrity sri Hashes in checkout_index_index causes big loadingtimes and bytes in multistore and sriHashes vanish after Cache Flush #38964

Open stkrelax opened 1 month ago

stkrelax commented 1 month ago

Preconditions and environment

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

m2-assistant[bot] commented 1 month ago

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:

m2-assistant[bot] commented 1 week ago

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:

engcom-Hotel commented 1 week ago

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

hostep commented 1 week ago

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.

engcom-Hotel commented 1 week ago

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

Thanks

github-jira-sync-bot commented 1 week ago

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

m2-assistant[bot] commented 1 week ago

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

stkrelax commented 1 week ago

@engcom-Hotel please also consider fixing:

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