Content-Security-Policy 个问题 Google 云函数
Content-Security-Policy problems Google Cloud Function
我构建了一个 google 云函数,它接收输入并将其发送到 Firestore。我需要在我将在 Twitter 上使用的 Firefox WebExtension 中调用它。我不是第一次做这种类型的项目,但这次我遇到了关于“Content-Security-Policy”的问题。
我尝试使用 GC 测试工具调用我的 GC 函数,然后使用 Postman,然后在 Python 脚本中,最后在新打开的选项卡的控制台中。所有这一切都奏效了!
但它在我的 WebExtension 中不起作用。因此,我尝试在使用 Twitter 时在控制台 (Firefox) 中调用我的函数。它也不起作用。我收到以下错误消息:
error TypeError: NetworkError when attempting to fetch resource. <anonymous> debugger eval code:9
接下来是:
Content Security Policy: The page’s settings blocked the loading of a resource at
https://...cloudfunctions.net/...?...=... (“connect-src”).
尝试 Chrome 时,我收到此错误消息:
error TypeError: Failed to fetch
at <anonymous>:9:1
Refused to connect to 'https://....cloudfunctions.net/...?...=...'
because it violates the following Content Security Policy directive: "connect-src 'self' blob:
我可以提供的另一个有趣的信息是,在访问 Twitter 页面时打开控制台(在 Firefox 中)时,我收到以下警告消息:
Content Security Policy: Ignoring “'unsafe-inline'” within script-src or style-src: nonce-source or hash-source specified
以及以下错误消息:
Content Security Policy: The page’s settings blocked the loading of a resource at inline (“script-src”).
仅供参考:在 GC 函数中,我设置了 headers 以下方式:
response.headers.set("Access-Control-Allow-Origin", "*")
headers.set("Access-Control-Allow-Methods", "GET, POST")
我也尝试添加以下行,但它不起作用:
response.headers.set("Content-Security-Policy", "default-src * self blob: data: gap:; style-src * self 'unsafe-inline' blob: data: gap:; script-src * 'self' 'unsafe-eval' 'unsafe-inline' blob: data: gap:; object-src * 'self' blob: data: gap:; img-src * self 'unsafe-inline' blob: data: gap:; connect-src self * 'unsafe-inline' blob: data: gap:; frame-src * self blob: data: gap:;")
你们能帮我吗?我真的卡住了。谢谢!!
Another interesting information I could give is that, when opening the
console (in Firefox) when visiting a Twitter page, I'm getting the
following warning message :
Content Security Policy: Ignoring “'unsafe-inline'” within script-src or style-src: nonce-source or hash-source specified
这不是 WebExtension 错误,而是 Twitter 的 CSP 警告,因为它支持 backward browsers compatibility mode。无视它,你无法影响Twitter的CSP。
I've also try to add the following line, but it doesn't work:
response.headers.set("Content-Security-Policy", "...")
WebExtension 无法通过这种方式发布CSP,需要使用content_security_policy key in the app's manifest (manifest.json
file). See details in CSP in WebExtension.
扩展的默认内容安全策略是:script-src 'self'; object-src 'self';
这就是 https://...cloudfunctions.net/
源被阻止的原因。看起来您在 WexExtension 中使用了某种内联脚本,因此您必须将 'hash-value'
添加到 content_security_policy
键中的 script-src
。
*
'unsafe-inline'
令牌不能用于 content_security_policy
密钥。
请注意,在 addons.mozilla.org 由于重大安全问题。
我构建了一个 google 云函数,它接收输入并将其发送到 Firestore。我需要在我将在 Twitter 上使用的 Firefox WebExtension 中调用它。我不是第一次做这种类型的项目,但这次我遇到了关于“Content-Security-Policy”的问题。
我尝试使用 GC 测试工具调用我的 GC 函数,然后使用 Postman,然后在 Python 脚本中,最后在新打开的选项卡的控制台中。所有这一切都奏效了! 但它在我的 WebExtension 中不起作用。因此,我尝试在使用 Twitter 时在控制台 (Firefox) 中调用我的函数。它也不起作用。我收到以下错误消息:
error TypeError: NetworkError when attempting to fetch resource. <anonymous> debugger eval code:9
接下来是:
Content Security Policy: The page’s settings blocked the loading of a resource at
https://...cloudfunctions.net/...?...=... (“connect-src”).
尝试 Chrome 时,我收到此错误消息:
error TypeError: Failed to fetch
at <anonymous>:9:1
Refused to connect to 'https://....cloudfunctions.net/...?...=...'
because it violates the following Content Security Policy directive: "connect-src 'self' blob:
我可以提供的另一个有趣的信息是,在访问 Twitter 页面时打开控制台(在 Firefox 中)时,我收到以下警告消息:
Content Security Policy: Ignoring “'unsafe-inline'” within script-src or style-src: nonce-source or hash-source specified
以及以下错误消息:
Content Security Policy: The page’s settings blocked the loading of a resource at inline (“script-src”).
仅供参考:在 GC 函数中,我设置了 headers 以下方式:
response.headers.set("Access-Control-Allow-Origin", "*")
headers.set("Access-Control-Allow-Methods", "GET, POST")
我也尝试添加以下行,但它不起作用:
response.headers.set("Content-Security-Policy", "default-src * self blob: data: gap:; style-src * self 'unsafe-inline' blob: data: gap:; script-src * 'self' 'unsafe-eval' 'unsafe-inline' blob: data: gap:; object-src * 'self' blob: data: gap:; img-src * self 'unsafe-inline' blob: data: gap:; connect-src self * 'unsafe-inline' blob: data: gap:; frame-src * self blob: data: gap:;")
你们能帮我吗?我真的卡住了。谢谢!!
Another interesting information I could give is that, when opening the console (in Firefox) when visiting a Twitter page, I'm getting the following warning message :
Content Security Policy: Ignoring “'unsafe-inline'” within script-src or style-src: nonce-source or hash-source specified
这不是 WebExtension 错误,而是 Twitter 的 CSP 警告,因为它支持 backward browsers compatibility mode。无视它,你无法影响Twitter的CSP。
I've also try to add the following line, but it doesn't work:
response.headers.set("Content-Security-Policy", "...")
WebExtension 无法通过这种方式发布CSP,需要使用content_security_policy key in the app's manifest (manifest.json
file). See details in CSP in WebExtension.
扩展的默认内容安全策略是:script-src 'self'; object-src 'self';
这就是 https://...cloudfunctions.net/
源被阻止的原因。看起来您在 WexExtension 中使用了某种内联脚本,因此您必须将 'hash-value'
添加到 content_security_policy
键中的 script-src
。
*
'unsafe-inline'
令牌不能用于 content_security_policy
密钥。
请注意,在 addons.mozilla.org 由于重大安全问题。