目录
CSP(Content Security Policy,内容安全策略)是一种用来防止XSS攻击的手段,通过在头部Content-Security-Policy 的相关参数,来限制未知(不信任)来源的JavaScript脚本的执行,从而达到防止xss攻击的目的。一般的xss攻击,主要是通过利用函数过滤/转义输入中的特殊字符,标签,文本来应对攻击。CSP则是另外一种常用的应对XSS攻击的策略。其实质就是白名单机制,开发者明确告诉客户端,哪些外部资源可以加载和执行,等同于提供白名单。它的实现和执行全部由浏览器完成,开发者只需提供配置。
Low
源码:
<?php
$headerCSP = "Content-Security-Policy: script-src 'self' https://pastebin.com hastebin.com example.com code.jquery.com https://ssl.google-analytics.com ;"; // allows js from self, pastebin.com, hastebin.com, jquery and google analytics.
header($headerCSP);
# These might work if you can't create your own for some reason
# https://pastebin.com/raw/R570EE00
# https://hastebin.com/raw/ohulaquzex
?>
<?php
if (isset ($_POST['include'])) {
$page[ 'body' ] .= "
<script src='" . $_POST['include'] . "'></script>
";
}
$page[ 'body' ] .= '
<form