Skip to content

How can I use spatie/laravel-responsecache with spatie/laravel-csp nonce together. #440

Answered by uintaam
onurakman asked this question in Q&A
Discussion options

You must be logged in to vote

If your issue is you're concerned with the nonce being the same for all cached responses then I created a replacer class you add to your responsecache.php config file.

<?php declare(strict_types = 1);

namespace App\Csp;

use Spatie\ResponseCache\Replacers\Replacer;
use Symfony\Component\HttpFoundation\Response;

class NonceTokenReplacer implements Replacer
{
    protected string $replacementString = '<laravel-responsecache-cspnonce-token-here>';

    public function prepareResponseToCache(Response $response): void
    {
        $csp_header_name = 'content-security-policy';
        $csp_header = $response->headers->get($csp_header_name);
        if (!$csp_header) {
            $csp_header…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by onurakman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants