gpt4 book ai didi

javascript - 为什么禁止内联脚本(内容安全策略)?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:26:08 27 4
gpt4 key购买 nike

我想知道规范中的引述:( https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html )

To reap the greatest benefit, authors will need to move all inline script and style out-of-line, for example into external scripts, because the user agent cannot determine whether an inline script was injected by an attacker.

采购所有内联脚本是一项耗时的任务。

我的问题是从安全的 Angular 出发。通过将所有内联脚本(例如 JavaScript)提取到外部源,您真的可以获得任何安全优势吗?

谢谢

最佳答案

关键部分是

the user agent cannot determine whether an inline script was injected by an attacker.

为了提供保护,CSP 必须防止攻击者控制的子字符串导致代码运行。由于用户代理不知道 HTML 的哪些部分是由不受信任的输入指定的,哪些来自受信任的开发人员编写的模板,因此它必须假设最坏的情况——任何属性或元素都可能被攻击者控制。

Do you really get any security benefit by extracting all inline-script (e.g. JavaScript) to external sources?

没有。提取您想要运行的脚本不会提供任何安全优势,它只是让您在仍然使用 CSP 的同时运行您想要的脚本。

安全优势来自于能够调用浏览器的 HTML 解析器,而不会无意中执行滥用域权限或窃取 secret 的脚本。

关于javascript - 为什么禁止内联脚本(内容安全策略)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15780918/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com