Skip to content

Commit

Permalink
Update CSP Reporting to log to Rollbar
Browse files Browse the repository at this point in the history
  • Loading branch information
devowhippit committed Dec 3, 2019
1 parent 0d66daf commit 2e32d3c
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 17 deletions.
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -1370,27 +1370,27 @@
},
{
"name": "psr/log",
"version": "1.1.0",
"version_normalized": "1.1.0.0",
"version": "1.1.2",
"version_normalized": "1.1.2.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/log.git",
"reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd"
"reference": "446d54b4cb6bf489fc9d75f55843658e6f25d801"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/log/zipball/6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd",
"reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd",
"url": "https://api.github.com/repos/php-fig/log/zipball/446d54b4cb6bf489fc9d75f55843658e6f25d801",
"reference": "446d54b4cb6bf489fc9d75f55843658e6f25d801",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"time": "2018-11-20T15:27:04+00:00",
"time": "2019-11-01T11:05:21+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
"dev-master": "1.1.x-dev"
}
},
"installation-source": "dist",
Expand Down
2 changes: 2 additions & 0 deletions vendor/psr/log/Psr/Log/LoggerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ public function debug($message, array $context = array());
* @param array $context
*
* @return void
*
* @throws \Psr\Log\InvalidArgumentException
*/
public function log($level, $message, array $context = array());
}
2 changes: 2 additions & 0 deletions vendor/psr/log/Psr/Log/LoggerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ public function debug($message, array $context = array())
* @param array $context
*
* @return void
*
* @throws \Psr\Log\InvalidArgumentException
*/
abstract public function log($level, $message, array $context = array());
}
2 changes: 2 additions & 0 deletions vendor/psr/log/Psr/Log/NullLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class NullLogger extends AbstractLogger
* @param array $context
*
* @return void
*
* @throws \Psr\Log\InvalidArgumentException
*/
public function log($level, $message, array $context = array())
{
Expand Down
4 changes: 3 additions & 1 deletion vendor/psr/log/Psr/Log/Test/LoggerInterfaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use PHPUnit\Framework\TestCase;

/**
* Provides a base test class for ensuring compliance with the LoggerInterface.
*
* Implementors can extend the class and implement abstract methods to run this
* as part of their test suite.
*/
abstract class LoggerInterfaceTest extends \PHPUnit_Framework_TestCase
abstract class LoggerInterfaceTest extends TestCase
{
/**
* @return LoggerInterface
Expand Down Expand Up @@ -140,5 +141,6 @@ class DummyTest
{
public function __toString()
{
return 'DummyTest';
}
}
1 change: 1 addition & 0 deletions vendor/psr/log/Psr/Log/Test/TestLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,6 @@ public function __call($method, $args)
public function reset()
{
$this->records = [];
$this->recordsByLevel = [];
}
}
6 changes: 6 additions & 0 deletions vendor/psr/log/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ class Foo
if ($this->logger) {
$this->logger->info('Doing work');
}

try {
$this->doSomethingElse();
} catch (Exception $exception) {
$this->logger->error('Oh no!', array('exception' => $exception));
}

// do something useful
}
Expand Down
2 changes: 1 addition & 1 deletion vendor/psr/log/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
"dev-master": "1.1.x-dev"
}
}
}
2 changes: 2 additions & 0 deletions wp-content/mu-plugins/config/development.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@

/**
* Disable Rollbar because it is only required for remote error monitoring.
* Uncomment the activate line if you need to test it.
*/

deactivate_plugins('rollbar/rollbar-php-wordpress.php');
// activate_plugin(WP_PLUGIN_DIR . 'rollbar/rollbar-php-wordpress.php');

/**
* A WordPress plugin for the Whoops Error Framework.
Expand Down
19 changes: 17 additions & 2 deletions wp-content/mu-plugins/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,34 @@
* Author: NYC Opportunity
*/

use \Rollbar\Rollbar;
use \Rollbar\Payload\Level;

/**
* Add Filter after all plugins are loaded to make sure we have our dependencies.
*/

add_filter('plugins_loaded', function() {
if (!class_exists('Routes')) {
return;
}

/**
* Create an endpoint for CSP Reporting.
* Create an endpoint for CSP Reporting to post to Rollbar or the default
* error log. Rollbar requires the Rollbar WordPress plugin or the Rollbar
* PHP library. The default log requires DEBUG_MODE to be set to true and
* DISPLAY_ERRORS to be set to false.
*/

if (defined('WP_HEADERS_CSP_REPORTING') && WP_HEADERS_CSP_REPORTING) {
Routes::map(WP_HEADERS_CSP_REPORTING, function() {
http_response_code(204);

error_log(file_get_contents('php://input'));
if (class_exists('Rollbar\Rollbar')) {
Rollbar::log(Level::INFO, 'CSP Reporting', json_decode(file_get_contents('php://input')));
} else {
error_log(file_get_contents('php://input')); // Default error log
}

exit();
});
Expand Down

0 comments on commit 2e32d3c

Please sign in to comment.