Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 内容安全策略问题谷歌云功能_Javascript_Python_Google Cloud Platform_Google Cloud Functions_Content Security Policy - Fatal编程技术网

Javascript 内容安全策略问题谷歌云功能

Javascript 内容安全策略问题谷歌云功能,javascript,python,google-cloud-platform,google-cloud-functions,content-security-policy,Javascript,Python,Google Cloud Platform,Google Cloud Functions,Content Security Policy,我已经构建了一个google云函数,它接受一个输入并将其发送到Firestore。我需要在Firefox WebExtension中调用它,我将在Twitter上使用它。这不是我第一次做这种类型的项目,但这次我遇到了关于“内容安全策略”的问题 我尝试用GC测试工具调用我的GC函数,然后用Postman调用,然后在Python脚本中调用,最后在新打开的选项卡的控制台中调用。所有这些都奏效了! 但它在我的WebExtension中不起作用。因此,当我在twitter上时,我尝试在控制台(Firefo

我已经构建了一个google云函数,它接受一个输入并将其发送到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: 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”).
在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:
以及以下错误消息:

error TypeError: NetworkError when attempting to fetch resource. <anonymous> debugger eval code:9
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:;")
你们能帮我吗?我真的卡住了。谢谢

我能提供的另一个有趣的信息是,当打开 控制台(在Firefox中)当访问Twitter页面时,我得到 以下警告信息:

error TypeError: NetworkError when attempting to fetch resource. <anonymous> debugger eval code:9
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”).
内容安全策略:忽略脚本src或样式src中的“'safe-inline'”:指定的nonce-source或hash-source

这不是WebExtension错误,而是Twitter的CSP警告,因为它支持。忽略它,你不能影响Twitter的CSP

我还尝试添加以下行,但不起作用:
response.headers.set(“内容安全策略”和“…”)

WebExtension无法以这种方式发布CSP,您需要使用(
manifest.json
file)。请参阅中的详细信息。
扩展的默认内容安全策略是:
scriptsrc'self';对象src“self”这就是为什么
https://...cloudfunctions.net/
源被阻止。看起来您在WexExtension中也使用了某种内联脚本,因此您必须在
内容安全策略
键中的
脚本src
中添加
'hash-value'

*
内容安全策略
密钥中不能使用
'safe-inline'
令牌

请注意,由于存在重大安全问题,对于addons.mozilla.org上列出的扩展,CSP中包含
'safe-eval'
'safe-inline'
、远程脚本、
blob
、或远程源的扩展

我能提供的另一个有趣的信息是,当打开 控制台(在Firefox中)当访问Twitter页面时,我得到 以下警告信息:

error TypeError: NetworkError when attempting to fetch resource. <anonymous> debugger eval code:9
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”).
内容安全策略:忽略脚本src或样式src中的“'safe-inline'”:指定的nonce-source或hash-source

这不是WebExtension错误,而是Twitter的CSP警告,因为它支持。忽略它,你不能影响Twitter的CSP

我还尝试添加以下行,但不起作用:
response.headers.set(“内容安全策略”和“…”)

WebExtension无法以这种方式发布CSP,您需要使用(
manifest.json
file)。请参阅中的详细信息。
扩展的默认内容安全策略是:
scriptsrc'self';对象src“self”这就是为什么
https://...cloudfunctions.net/
源被阻止。看起来您在WexExtension中也使用了某种内联脚本,因此您必须在
内容安全策略
键中的
脚本src
中添加
'hash-value'

*
内容安全策略
密钥中不能使用
'safe-inline'
令牌


请注意,由于主要的安全问题,在他们的CSP中使用了
'safe-eval'
'safe-inline'
、远程脚本、
blob
、或远程源代码的扩展名,这些扩展名列在addons.mozilla.org上。

谢谢@granty我的想法已经很清楚了。因此,当我在复制/粘贴到控制台时遇到这个错误:“内容安全策略:页面的设置阻止了在(“connect src”)加载资源”,我尝试将此参数添加到manifest.json“Content_Security_Policy”:“script src'self”“hash value';object src'self'”。但我还是遇到了同样的网络错误。我做错了什么?
“内容安全策略”:“脚本src'self'”散列值“;对象src'self';连接src us-central1-twitter-fake-accounts.cloudfunctions.net”
因为主机源在
connect src
指令中被阻止。好,这意味着我不能用任何参数覆盖它吗?我不明白你想用参数覆盖什么?为什么您的源策略
“内容安全策略”:“脚本src'self'散列值'us-central1-twitter-fake-accounts.cloudfunctions.net;对象src'self';”
可以被覆盖,但
“内容安全策略”:“脚本src'self'散列值';对象src'self';连接src us-central1-twitter-fake-accounts.cloudfunctions.net”
-不能吗?只添加了一条指令,事情就发生了变化?我的意思是,即使使用
“内容安全策略”:“脚本src‘self’‘hash value’us-central1-twitter-fake-accounts.cloudfunctions.net;对象src‘self’;”
我仍然收到这个
错误类型error:NetworkError,当我试图获取资源时。
谢谢@granty我的想法已经很清楚了。因此,当我在复制/粘贴到控制台时遇到这个错误:“内容安全策略:页面的设置阻止了在(“connect src”)加载资源”,我尝试将此参数添加到manifest.json“Content_Security_Policy”:“script src'self”“hash value';object src'self'”。但我还是遇到了同样的网络错误。我做错了什么?
“内容安全策略”:“脚本src'self'”散列值“;对象src'self';连接src us-central1-twitter-fake-a