Today, I implemented the Content-Security-Policy (CSP). I also included the report-uri
so it sends a POST request to myserver.com/csp-report.php
. As MDN explains in their website, the POST request is like this:
{
"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",
}
}
I want to email this info, to reports@myserver.com. Currently, I have this code but it just emails "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();
}
?>