[3276] | 1 | <?php |
---|
| 2 | // From: https://github.com/nico3333fr/CSP-useful |
---|
| 3 | // |
---|
| 4 | // Note: this script requires PHP ≥ 5.4. |
---|
| 5 | // Inspired from https://mathiasbynens.be/notes/csp-reports |
---|
| 6 | |
---|
| 7 | // Dareboost wants it? Not a problem. |
---|
| 8 | header('X-Content-Type-Options: "nosniff"'); |
---|
| 9 | |
---|
[3324] | 10 | require dirname(__FILE__).'/../inc/admin/prepend.php'; |
---|
| 11 | |
---|
[3276] | 12 | // Specify log file |
---|
[3324] | 13 | define('LOGFILE',path::real(DC_TPL_CACHE).'/csp_report.txt'); |
---|
[3276] | 14 | |
---|
| 15 | // Get the raw POST data |
---|
| 16 | $data = file_get_contents('php://input'); |
---|
| 17 | |
---|
| 18 | // Only continue if it’s valid JSON that is not just `null`, `0`, `false` or an |
---|
| 19 | // empty string, i.e. if it could be a CSP violation report. |
---|
| 20 | if ($data = json_decode($data, true)) { |
---|
| 21 | |
---|
| 22 | // get source-file and blocked-URI to perform some tests |
---|
| 23 | $source_file = $data['csp-report']['source-file']; |
---|
| 24 | $blocked_uri = $data['csp-report']['blocked-uri']; |
---|
| 25 | |
---|
| 26 | if ( |
---|
| 27 | |
---|
| 28 | // avoid false positives notifications coming from Chrome extensions (Wappalyzer, MuteTab, etc.) |
---|
| 29 | // bug here https://code.google.com/p/chromium/issues/detail?id=524356 |
---|
| 30 | strpos($source_file, 'chrome-extension://') === false |
---|
| 31 | |
---|
| 32 | // avoid false positives notifications coming from Safari extensions (diigo, evernote, etc.) |
---|
| 33 | && strpos($source_file, 'safari-extension://') === false |
---|
| 34 | |
---|
| 35 | // search engine extensions ? |
---|
| 36 | && strpos($source_file, 'se-extension://') === false |
---|
| 37 | |
---|
| 38 | // added by browsers in webviews |
---|
| 39 | && strpos($blocked_uri, 'webviewprogressproxy://') === false |
---|
| 40 | |
---|
| 41 | ) { |
---|
| 42 | // Prettify the JSON-formatted data |
---|
| 43 | $data = json_encode( |
---|
| 44 | $data, |
---|
| 45 | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES |
---|
| 46 | ); |
---|
| 47 | |
---|
[3293] | 48 | if (!($fp = @fopen(LOGFILE,'a'))) { |
---|
[3276] | 49 | return; |
---|
| 50 | } |
---|
| 51 | fprintf($fp,'%s',$data); |
---|
| 52 | } |
---|
| 53 | } |
---|