magento2
magento2 copied to clipboard
CORS Errors Prevent Page Builder Content Updates in Magento 2.4.6-p7 (Production Mode)
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”.
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.
- 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-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: XXXXXlabel to the ticket, indicating the functional areas it may be related to. - [ ] 4. Verify that the issue is reproducible on
2.4-developbranchDetails
- 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.
It sounds like the Nginx configuration isn't right or is being ignored.
Have you tried the wide open configuration to test?
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.
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.
The Page Builder changes fail to save.
Hence Confirming the isuue.
Thanks.
:white_check_mark: Jira issue https://jira.corp.adobe.com/browse/AC-13294 is successfully created for this GitHub issue.
: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.
Facing the same issue. Only solution is to add the Access-Control-Allow-Origin "*" header to NGINX which I'd rather not
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.
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
The same issue occurs on product save from admin in Magento version 2.4.7-p3
Please advise if there is a patch available for this yet? I do not see any information on such inside this discussion.
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 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.
@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.
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