简体   繁体   English

内容安全政策

[英]Content Security Policy

I am currently implementing CSP(Content Security Policy) for my project and i have chosen to implement nonce for all the inline scripts that cannot be moved away from the web page. 我目前正在为我的项目实施CSP(内容安全策略),并且我选择为所有无法从网页移开的内联脚本实施随机数 While trying to implement nonce for classic aspx pages, there are few places where the script manager is being included to use the ajaxcontrol toolkit and they are generating a tag in the html. 在尝试为经典aspx页面实现随机数时,很少有包含脚本管理器的地方可以使用ajaxcontrol工具包,并且它们在html中生成标记。

Since i have nonce implementation i need to add the nonce attribute to the script tag in order to prevent the from getting blocked by the CSP. 由于我具有随机数实现,因此我需要将随机数属性添加到脚本标签中,以防止CSP阻止该随机数。 I have been looking into this for 2 days and i don't find any suggestion/solution for this. 我已经研究了2天,但没有找到任何建议/解决方案。

EDIT: 编辑:

I am generating the nonce using OWIN middleware. 我正在使用OWIN中间件生成随机数。 The meta tag is being generated dynamically and appended to the meta tag during the master page load. meta标签是动态生成的,并在主页面加载期间附加到meta标签。

Any help would be appreciated. 任何帮助,将不胜感激。

Thanks 谢谢

On IIS 7 and above, you can leverage the URL Rewrite Module to define outbound rules which allow you to modify the markup on the fly: 在IIS 7及更高版本上,您可以利用URL重写模块来定义出站规则,这些规则允许您即时修改标记:

https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/using-outbound-rules-to-add-web-analytics-tracking-code https://docs.microsoft.com/zh-cn/iis/extensions/url-rewrite-module/using-outbound-rules-to-add-web-analytics-tracking-code

Here is an example of rewriting image tags: 这是重写图像标签的示例:

http://marisks.net/2017/05/14/changing-static-resource-urls-to-cdn-urls-with-url-rewrite/ http://marisks.net/2017/05/14/changing-static-resource-urls-to-cdn-urls-with-url-rewrite/

After a discussion with the microsoft community it has been identified that there is no way to interpret the script tag generated dynamically. 与Microsoft社区讨论之后,已经确定没有办法解释动态生成的脚本标记。 So as of now this is kind of not possible. 因此,到目前为止,这还不可能。 will keep you guys updated if i find any solution or if you guys have a suggestion or workaround then feel free to post it here. 如果我找到任何解决方案,或者如果您有建议或解决方法,将使您保持最新状态,然后随时在此处发布。 Thanks for all your help 感谢你的帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM