今天,我实现了Content-Security-Policy (CSP)。我还包括了,report-uri
所以它发送一个POST请求到myserver.com/csp-report.php
. 正如 MDN 在他们的网站上解释的那样,POST请求是这样的:
{
"csp-report": {
"document-uri": "http://example.com/signup.html",
"referrer": "http://evil.example.net/haxor.html",
"blocked-uri": "http://evil.example.net/injected.png",
"violated-directive": "img-src *.example.com",
"original-policy": "default-src 'self'; img-src 'self' *.example.com; report-uri /_/csp-reports",
}
}
我想通过电子邮件将此信息发送至reports@myserver.com。目前,我有这个代码,但它只是通过电子邮件发送“Array() Array()”
<?php
$tars = Array("reports@myserver.com", "webm@myserver.com");
$from = "notify@myserver.com";
$subject = "CSP Report";
$text = print_r($_POST, true);
$text = (isSet($_GET["text"]) ? $_GET["text"] : $text);
foreach($tars as $tar){
$e = mail($tar,$subject,$text,"From: $from");
}
if($e){
header("Content-type: text/javascript");
echo 'console.log("Email Sent");';
exit();
}
?>