Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion routes/reporting-api.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

use audunru\ReportingApi\Controllers\ReportingApiController;
use Illuminate\Foundation\Http\Middleware\PreventRequestForgery;
use Illuminate\Foundation\Http\Middleware\ValidateCsrfToken;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
use Illuminate\Support\Facades\Route;

Route::post(config('reporting-api.path', '/reports'), [ReportingApiController::class, 'report'])
->middleware(['throttle:'.config('reporting-api.throttle', '60,1')])
->withoutMiddleware([VerifyCsrfToken::class]);
->withoutMiddleware([VerifyCsrfToken::class, ValidateCsrfToken::class, PreventRequestForgery::class]);
4 changes: 1 addition & 3 deletions src/Listeners/LogCspViolation.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ public function handle(CspViolationReceived $event): void
return;
}

Log::channel($this->channel)->warning('CSP violation: {directive} blocked {url}', [
'directive' => $report->body->effectiveDirective,
'url' => $report->body->blockedURL,
Log::channel($this->channel)->warning("CSP violation: {$report->body->effectiveDirective} blocked {$report->body->blockedURL}", [
'page' => $report->url,
]);
}
Expand Down
4 changes: 1 addition & 3 deletions src/Listeners/LogReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ public function handle(ReportEvent $event): void
return;
}

Log::channel($this->channel)->info('{type} report received at {url}', [
'type' => $report->type,
'url' => $report->url,
Log::channel($this->channel)->info("{$report->type} report received at {$report->url}", [
'report' => $event->getRawReport(),
]);
}
Expand Down
4 changes: 3 additions & 1 deletion tests/Unit/Listeners/LogCspViolationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public function test_logs_warning_for_csp_violation(): void

(new LogCspViolation)->handle($event);

$spy->shouldHaveReceived('warning')->once();
$spy->shouldHaveReceived('warning')
->once()
->with('CSP violation: script-src blocked https://evil.example/script.js', ['page' => 'https://example.test/page']);
}

public function test_skips_logging_when_excluded(): void
Expand Down
4 changes: 3 additions & 1 deletion tests/Unit/Listeners/LogReportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public function test_logs_info_for_any_report(): void

(new LogReport)->handle($event);

$spy->shouldHaveReceived('info')->once();
$spy->shouldHaveReceived('info')
->once()
->with('deprecation report received at https://example.test/page', \Mockery::type('array'));
}

public function test_skips_logging_when_excluded(): void
Expand Down