-
Notifications
You must be signed in to change notification settings - Fork 714
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef1c80f
commit 3d72953
Showing
1 changed file
with
14 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,17 @@ | ||
<?php | ||
// Send `204 No Content` status code. | ||
http_response_code(204); | ||
// collect data from post request | ||
$data = file_get_contents('php://input'); | ||
if ($data = json_decode($data)) { | ||
// Remove slashes from the JSON-formatted data. | ||
$data = json_encode( | ||
$data, | ||
JSON_UNESCAPED_SLASHES | ||
); | ||
# set options for syslog daemon | ||
openlog('report-uri', LOG_NDELAY, LOG_USER); | ||
|
||
// Start configure | ||
$log_file = dirname(__FILE__) . '/csp-violations.log'; | ||
$log_file_size_limit = 1000000; // bytes - once exceeded no further entries are added | ||
// End configuration | ||
|
||
|
||
http_response_code(204); // HTTP 204 No Content | ||
|
||
$json_data = file_get_contents('php://input'); | ||
|
||
// We pretty print the JSON before adding it to the log file | ||
if ($json_data = json_decode($json_data)) { | ||
$json_data = json_encode($json_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); | ||
|
||
if (filesize($log_file) > $log_file_size_limit) { | ||
exit(0); | ||
} | ||
|
||
file_put_contents($log_file, $json_data, FILE_APPEND | LOCK_EX); | ||
# send warning about csp report | ||
syslog(LOG_WARNING, $data); | ||
} |