【发布时间】:2021-04-20 09:52:17
【问题描述】:
我已经构建了一个谷歌云函数,它接受输入并将其发送到 Firestore。我需要在 Firefox WebExtension 中调用它,我将在 Twitter 上使用它。我不是第一次做这种类型的项目,但这次我遇到了关于“内容安全策略”的问题。
我尝试使用 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 函数中,我已按以下方式设置标题:
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:;")
你们能帮我吗?我真的被困住了。谢谢!!
【问题讨论】:
标签: javascript python google-cloud-platform google-cloud-functions content-security-policy