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.46k stars 9.29k forks source link

Admin captcha does not load due to CSP when admin and store base_url are different. #38854

Closed damienwebdev closed 4 weeks ago

damienwebdev commented 2 months ago

Preconditions and environment

No response

Steps to reproduce

  1. Set your store's id 1' base_url to "magento2.test"
  2. Set your admin store url to "admin.magento2.test"
  3. Attempt to sign in enough to trigger captcha

Expected result

See a captcha

Actual result

See:

image

Console contains

Refused to load the image 'magento2.test' because it violates the following Content Security Policy directive: "img-src assets.adobedtm.com amcglobal.sc.omtrdc.net dpm.demdex.net cm.everesttech.net .adobe.com amasty.com www.googleadservices.com www.google-analytics.com googleads.g.doubleclick.net www.google.com bid.g.doubleclick.net analytics.google.com www.googletagmanager.com .ftcdn.net .behance.net data: t.paypal.com www.paypal.com www.paypalobjects.com fpdbs.paypal.com fpdbs.sandbox.paypal.com .vimeocdn.com i.ytimg.com .youtube.com validator.swagger.io store.paradoxlabs.com www.sandbox.paypal.com b.stats.paypal.com dub.stats.paypal.com assets.braintreegateway.com c.paypal.com checkout.paypal.com .paypal.com *.aptrinsic.com storage.googleapis.com data: 'self' 'unsafe-inline'".

Additional information

You can circumvent the issue by opening the captcha url in a new tab, but that's not great.

image

Release note

No response

Triage and priority

m2-assistant[bot] commented 2 months ago

Hi @damienwebdev. 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 2 months ago

Hi @engcom-Delta. 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-Delta commented 1 month ago

Hi @damienwebdev ,

Thanks for your reporting and collaboration. We have verified the issue in latest 2.4-develop instance and the issue is not reproducible. Kindly refer the screenshots.

Steps to reproduce

Thanks.

engcom-Delta commented 4 weeks ago

Hi @damienwebdev ,

We have noticed that this issue has not been updated since long time. Hence we assume that this issue is fixed now, so we are closing it. Please feel to raise a fresh ticket or reopen this ticket if you need more assistance on this.

Thanks.

damienwebdev commented 15 hours ago

@engcom-Delta please reopen. There's an additional configuration necessary to trigger this result.

Add the following CSP Configuration:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
    <default>
        <csp>
            <mode>
                <storefront>
                    <report_only>0</report_only>
                </storefront>
                <admin>
                    <report_only>0</report_only>
                </admin>
            </mode>
        </csp>
  </default>
</config>

If you use strict CSP, media in the admin panel do not work as they are loaded from the storefront's domain as opposed to the admin domain.

The root cause is that the https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Store/Model/StoreResolver.php#L95 returns 1 for the admin store instead of 0.