php-debugbar icon indicating copy to clipboard operation
php-debugbar copied to clipboard

debugbar 3.15.1 conflicts with CSP policy

Open fdelvals opened this issue 9 months ago • 4 comments

hello,

We have enabled a strict CSP policy which has been working fine with debugbar 3.14.x

Suddenly we have updated debugbar to 3.15.1 and this fails:

Image

We have pinned 3.14 until a quickfix pops out.

fdelvals avatar Feb 24 '25 12:02 fdelvals

Hmm, which CSP package are you using? Or how do you set your policy and CSP tag?

barryvdh avatar Feb 24 '25 14:02 barryvdh

maybe the new paths: https://github.com/php-debugbar/php-debugbar/pull/730/files

parallels999 avatar Feb 24 '25 15:02 parallels999

This is for laravel debugbar I think, looking at the version. That uses its own routes

barryvdh avatar Feb 24 '25 15:02 barryvdh

@barryvdh Same issue here, expect that when I enable the middleware, debugbar will no longer be injected in the Inertia application, but the functionality (log files, etc) are still working. Might it be an idea to include a SCP check to at least give a warning in the Laravel log files?

AddContentSecurityPolicyHeaders.php

class AddContentSecurityPolicyHeaders {
    /**
     * Handle an incoming request.
     *
     * @param Request $request
     * @param Closure $next
     *
     * @return Response
     */
    public function handle(Request $request, Closure $next): Response {
        Vite::useCspNonce();

        if ($next($request) instanceof Response) {
            return $next($request)->withHeaders([
                'Content-Security-Policy' => "script-src 'nonce-".Vite::cspNonce()."'",
            ]);
        }

        throw new RuntimeException('Expected instance of Illuminate\Http\Request in handle AddContentSecurityPolicyHeaders middleware');
    }
}

Packages:

"inertiajs/inertia-laravel": "^2.0",
"laravel/framework": "^12.0",
"barryvdh/laravel-debugbar": "^3.15",

JeffreyTheTukkr avatar Apr 18 '25 08:04 JeffreyTheTukkr