我用的是酒瓶-Talisman。我的CSP目前配置为所有路由,如:
SELF = '\'self\''
csp = {
'default-src': [SELF, '*.gstatic.com'],
'connect-src': [SELF, 'https://fonts.googleapis.com', 'https://cdnjs.cloudflare.com'],
'frame-src': [SELF, 'https://js.stripe.com'],
'script-src': [SELF, 'https://cdnjs.cloudflare.com', 'https://js.stripe.com', 'https://www.googletagmanager.com'],
'style-src': [SELF, 'https://cdnjs.cloudflare.com', 'https://fonts.googleapis.com', '\'unsafe-inline\''],
'img-src': [SELF, '*', 'blob:', 'data:']
}
talisman.init_app(app, content_security_policy=csp, content_security_policy_nonce_in=['script-src'])每当外部站点试图通过iframe加载我的页面时,他们都会收到错误X-Frame-Options is SAMEORIGIN,这通常是可以的。
,但是,我希望通过加载的外部iframes访问的单一路由。为了达到这一目的,我采纳了以下建议:
@talisman(frame_options=ALLOW_FROM, frame_options_allow_from='*')在我的具体路线之前。
然而,Chrome不允许这样做,并报告了一个错误。相反,我认为应该设置CSP。我应该如何重写或重新配置我的路由,以便允许所有浏览器中的外部iframes访问它?
发布于 2019-09-15 13:09:20
在烧瓶-护身符路线上的例子:
# Example of a route-specific talisman configuration
@app.route('/embeddable')
@talisman(
frame_options='ALLOW-FROM',
frame_options_allow_from='https://example.com/',
)
def embeddable():
return "<html>I can be embedded.</html>"发布于 2019-09-16 10:41:20
解决方案是在路由上直接使用frame-ancestors头来增强csp,而不是在某些浏览器(inc )中优先使用。
# assume a csp dict exists
@talisman(frame_options=ALLOW_FROM,
frame_options_allow_from='*',
content_security_policy={**csp, 'frame-ancestors': ['*']})
def flask_route():
# individualised routehttps://stackoverflow.com/questions/57943958
复制相似问题