You are here

public function ReportUri::log in Content-Security-Policy 8

Handle a report submission.

Parameters

string $type: The report type.

Return value

\Symfony\Component\HttpFoundation\Response An empty response.

1 string reference to 'ReportUri::log'
csp.routing.yml in ./csp.routing.yml
csp.routing.yml

File

src/Controller/ReportUri.php, line 64

Class

ReportUri
Report URI Controller.

Namespace

Drupal\csp\Controller

Code

public function log($type) {
  $validTypes = [
    'enforce',
    'reportOnly',
  ];
  if (!in_array($type, $validTypes)) {
    return new Response('', 404);
  }
  $reportJson = $this->requestStack
    ->getCurrentRequest()
    ->getContent();
  $report = json_decode($reportJson);

  // Return 400: Bad Request if content cannot be parsed.
  if (empty($report) || json_last_error() != JSON_ERROR_NONE) {
    return new Response('', 400);
  }
  $this->logger
    ->info("@type <br/>\n<pre>@data</pre>", [
    '@type' => $type,
    '@data' => json_encode($report, JSON_PRETTY_PRINT),
  ]);

  // 202: Accepted.
  return new Response('', 202);
}