django Shopify嵌入式应用程序“frame-ancestors 'none'”错误

fivyi3re  于 2023-06-25  发布在  Go
关注(0)|答案(1)|浏览(185)

我的嵌入式应用程序出现了一些问题。我在隐身模式(Chrome)下检查了应用程序,发现它没有加载任何页面。
我已经在我的django后端上用django-csp和中间件配置了CSP头(添加了来自网络选项卡的XHR部分的API调用的屏幕截图)。

技术栈

前端:React
后端:Django Inspection console打印此错误:
拒绝帧“”,因为祖先违反了以下内容安全策略指令:“frame-ancestors 'none'”。
我不能够弄清楚这个问题。如果需要,我可以提供更多信息。

class CSPMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request):
        response = self.get_response(request)

        # Check if the request URL matches the desired prefix
        if request.path.startswith('/endpoint'):
            # Apply the CSP header for the desired URL prefix
            response['Content-Security-Policy'] = "frame-ancestors https://shopify-dev.myshopify.com https://admin.shopify.com;"

        return response

nimxete2

nimxete21#

我假设你正试图在你的网站中嵌入一个来自shopify-dev.myshopify.com的网页。
您收到CSP违规错误,因为shopify-dev.myshopify.com在其CSP响应标头中包含frame-ancestors 'none'。由于frame-ancestors directive用于指定哪个网页可以嵌入使用该指令的网页,因此frame-ancestors 'none'有效地防止任何网站嵌入shopify-dev.myshopify.com
因此,在您的网站上设置frame-ancestors指令不会对您的网站嵌入shopify-dev.myshopify.com页面的能力产生任何影响。
要解决这个问题,你需要重新设计你的应用,避免嵌入shopify-dev.myshopify.com

相关问题