CSP可以限制动态加载脚本的连接吗? [英] Can CSP restrict the connections of dynamically loaded script?

查看:68
本文介绍了CSP可以限制动态加载脚本的连接吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站正在加载第三方库,该第三方库加载了各种脚本以从我的网站抓取数据,并通过XHR将其发送到其自己的服务器进行分析。我想做一个限制,使我的页面只能与我的服务器和一台第三方服务器通信,而不会建立其他连接。

My site is loading a third party library that loads all kinds of scripts to scrape the data from my site and send it to its own servers via XHR for analysis. I want to make a restriction such that my page can only talk to my servers and the one third party server, and no other connections would be made.

我想知道CSP是否connect-src会这样做吗?

Im wondering if CSP connect-src would do that?

例如,假设我的网站是x.com,第三方是y.com

For example lets say my site is x.com and the third party is y.com

如果y.com加载了将数据发送到y.com的脚本,那是可以的,但如果将其发送到z.com则不是这样的。

If y.com loads a script that sends data to y.com it is okay but not if it sends it to z.com

我还没有

推荐答案

可以使用connect-src在Content-Security-Policy标头中对其进行控制

It can be controlled in Content-Security-Policy header using connect-src

connect-src 'self' http://y.com https://y.com;

这篇关于CSP可以限制动态加载脚本的连接吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆