Dotclear

source: admin/csp_report.php @ 3293:569044964a5f

Revision 3293:569044964a5f, 1.5 KB checked in by franck <carnet.franck.paul@…>, 9 years ago (diff)

Minor adjustment

Line 
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.
8header('X-Content-Type-Options: "nosniff"');
9
10// Specify log file
11define('LOGFILE',dirname(__FILE__).'/csp_report.txt');
12
13// Get the raw POST data
14$data = file_get_contents('php://input');
15
16// Only continue if it’s valid JSON that is not just `null`, `0`, `false` or an
17// empty string, i.e. if it could be a CSP violation report.
18if ($data = json_decode($data, true)) {
19
20     // get source-file and blocked-URI to perform some tests
21     $source_file   = $data['csp-report']['source-file'];
22     $blocked_uri   = $data['csp-report']['blocked-uri'];
23
24     if (
25
26     // avoid false positives notifications coming from Chrome extensions (Wappalyzer, MuteTab, etc.)
27     // bug here https://code.google.com/p/chromium/issues/detail?id=524356
28     strpos($source_file, 'chrome-extension://') === false
29
30     // avoid false positives notifications coming from Safari extensions (diigo, evernote, etc.)
31     && strpos($source_file, 'safari-extension://') === false
32
33     // search engine extensions ?
34     && strpos($source_file, 'se-extension://') === false
35
36     // added by browsers in webviews
37     && strpos($blocked_uri, 'webviewprogressproxy://') === false
38
39      ) {
40               // Prettify the JSON-formatted data
41               $data = json_encode(
42                         $data,
43                         JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES
44                         );
45
46               if (!($fp = @fopen(LOGFILE,'a'))) {
47                    return;
48               }
49               fprintf($fp,'%s',$data);
50          }
51}
Note: See TracBrowser for help on using the repository browser.

Sites map