magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

CORS Errors Prevent Page Builder Content Updates in Magento 2.4.6-p7 (Production Mode)

Open anasshl opened this issue 1 year ago • 4 comments

Preconditions and environment

Environment:

  • Magento Version: 2.4.6-p7
  • Web Server: Nginx
  • PHP Version: 8.2
  • Page Builder extension enabled.
  • Store Mode: Production (issue occurs only in this mode).

Quality Patches:

  • The issue persists even after applying quality patches ACSD-49628 and ACSD-59514.

Steps to reproduce

  • Log in to the Magento 2 Admin panel.
  • Navigate to Content > Pages.
  • Click on Add New Page or select an existing CMS page and click Edit.
  • Use the Page Builder to add a new content block or edit an existing block.
  • Make any changes to the content (e.g., adding text, images, or other elements).
  • Click the Save button to update the page.

Expected result

  • The page content should be saved successfully without any errors.

Actual result

  • The Page Builder changes fail to save.
  • The browser console logs CORS-related errors, specifically showing:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://domain.com/static/adminhtml/Magento/backend/en_US/requirejs/require.js. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 200.

Additional information

Note: This problem occurs only in production mode, the Page Builder works fine in developer mode.

We have attempted the following workarounds without success:

  • We have applied quality patches ACSD-49628 and ACSD-59514, and we deployed the production environment .but the issue persists.
  • Adding CORS headers to Nginx configuration.
  • Clearing caches (both browser and Magento).

Release note

No response

Triage and priority

  • [ ] Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • [ ] 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”.

anasshl avatar Oct 10 '24 07:10 anasshl

Hi @anasshl. 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.


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 Oct 10 '24 07:10 m2-assistant[bot]

Hi @engcom-Bravo. 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- 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 Oct 10 '24 07:10 m2-assistant[bot]

It sounds like the Nginx configuration isn't right or is being ignored.

Have you tried the wide open configuration to test?

devchris79 avatar Oct 10 '24 13:10 devchris79

Same for me, seems no config error. I use apache.

Adding this into apache vhost config fixed it: Header set Access-Control-Allow-Origin "*"

But as it worked fine before this is not a good solution

The reason for this behavior can be found in this file:

vendor/magento/module-csp/Plugin/AddDefaultPropertiesToGroupPlugin.php

        if ($integrity && $integrity->getHash()) {
            $properties['attributes']['integrity'] = $integrity->getHash();
            $properties['attributes']['crossorigin'] = 'anonymous';
        }

After setting the integrity, CORS will block the requested file.

So when integrity with crossorigin is set, the Access-Control-Allow-Origin header also have to be set.

lcw-media avatar Oct 15 '24 06:10 lcw-media

Hi @anasshl,

Thanks for your reporting and collaboration.

We have verified the issue in Latest 2.4-develop instance and the issue is reproducible.Kindly refer the screenshots.

Steps to reproduce

  • Log in to the Magento 2 Admin panel.
  • Navigate to Content > Pages.
  • Click on Add New Page or select an existing CMS page and click Edit.
  • Use the Page Builder to add a new content block or edit an existing block.
  • Make any changes to the content (e.g., adding text, images, or other elements).
  • Click the Save button to update the page.
Screenshot 2024-10-29 at 11 12 23 Screenshot 2024-10-29 at 10 03 45

The Page Builder changes fail to save.

Hence Confirming the isuue.

Thanks.

engcom-Bravo avatar Oct 29 '24 05:10 engcom-Bravo

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

github-jira-sync-bot avatar Oct 29 '24 05:10 github-jira-sync-bot

:white_check_mark: Confirmed by @engcom-Bravo. Thank you for verifying the issue.
Issue Available: @engcom-Bravo, 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 Oct 29 '24 05:10 m2-assistant[bot]

Facing the same issue. Only solution is to add the Access-Control-Allow-Origin "*" header to NGINX which I'd rather not

JonSau avatar Oct 29 '24 23:10 JonSau

You can also circumvent the problem by running bin/magento cache:flush at some point after bin/magento setup:static-content:deploy ... was executed.

The issue seems to be caused by the SRI feature of Magento's CSP module which adds an integrity and crossorigin attribute on each <script> tag in your html (code over here), like @lcw-media mentioned before and that causes issues with page builder somehow.

However, due to the way SRI hashes are stored in cache when running the SCD command (which is considered a bug), the issue can - at the moment - be very easily circumvented by flushing the cache, this also means you loose the SRI protection on scripts though, so you'll have to decide which one you like better.

hostep avatar Oct 30 '24 20:10 hostep

I commented on the issue linked by hostep not long ago, but might as well here too.

I created a small module to fix the issue only on the pagebuilder_stage_render page. https://github.com/smartexcan/magento2-page-builder-require-js-fix

Tested with open source 2.4.6-p6

smartexcan avatar Oct 31 '24 13:10 smartexcan

The same issue occurs on product save from admin in Magento version 2.4.7-p3

rutvik-dolphin avatar Nov 06 '24 12:11 rutvik-dolphin

Please advise if there is a patch available for this yet? I do not see any information on such inside this discussion.

daniel-zaretsky1 avatar Dec 03 '24 18:12 daniel-zaretsky1

The issue won't have occurred for you if you either didn't run the static content deploy command or flushed the cache after running it, as mentioned above (https://github.com/magento/magento2/issues/39250#issuecomment-2448340875)

smartexcan avatar Dec 04 '24 14:12 smartexcan

@smartexcan In production mode, static content deployment is mandatory after the setup upgrade, so suggesting otherwise may not be ideal. I encountered persistent CORS errors despite clearing the cache. Ultimately, I resolved the issue by removing the vendor directory, reinstalling the vendor folder using Composer(composer install), and then running the following commands in sequence:

  • php bin/magento setup:upgrade
  • php bin/magento setup:static-content:deploy
  • php bin/magento setup:di:compile
  • php bin/magento cache:flush

After these steps, the CORS errors in Magento version 2.4.7-p3 were resolved.

rutvik-dolphin avatar Dec 05 '24 05:12 rutvik-dolphin

@engcom-Bravo What's the current status? The "Progress: done" label was added two weeks ago, but there has been virtually no real communication since December 2024.

Morgy93 avatar Mar 19 '25 15:03 Morgy93

Hello,

As I can see this issue got fixed in the scope of the internal Jira ticket AC-13547 by the internal team Related commits:https://github.com/search?q=repo%3Amagento%2Fmagento2+AC-13547&type=commits

Based on the Jira ticket, the target version is 2.4.8.

Thanks

engcom-Bravo avatar Apr 03 '25 08:04 engcom-Bravo