-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Debugbar Not Showing Due To CSP #1317
Comments
This is probably a problem with a missing nounce |
The bot marked the old ticket as stale: #1016 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
. |
I mean I could just use hashes to allow just the stuff it writes. The problem is Which I could work around by adding this in a middleware: $content = $response->content();
$debugBarVar = 'phpdebugbar'; // this was coming from some config, but I forgot from where.
preg_match('/(?P<openScriptTagStart><script )(?P<openScriptTagEnd>.*?>)(?P<scriptContentBefore>\n.*?)\n'.$debugBarVar.'\.addDataSet\((?P<data>.+), "(?P<param>\w+)"\);(?P<scriptContentAfter>\n.*?)(?P<closeScriptTag><\/script>)/s', $response->content(), $matches);
$openScriptTagStart = $matches['openScriptTagStart'];
$data = $matches['data'];
$param = $matches['param'];
$openScriptTagEnd = $matches['openScriptTagEnd'];
$scriptContentBefore = $matches['scriptContentBefore'];
$scriptContentAfter = $matches['scriptContentAfter'];
$closeScriptTag = $matches['closeScriptTag'];
$dataEncoded = htmlspecialchars($data);
$paramEncoded = htmlspecialchars($param);
$old = $matches[0];
$new = "$openScriptTagStart data-$debugBarVar-data=\"$dataEncoded\" data-$debugBarVar-param=\"$paramEncoded\" $openScriptTagEnd{$scriptContentBefore}\n";
$new .= "var {$debugBarVar}Data = document.querySelector('script[data-$debugBarVar-data][data-$debugBarVar-param]').attributes;\n";
$new .= "$debugBarVar.addDataSet(JSON.parse({$debugBarVar}Data['data-$debugBarVar-data'].value), {$debugBarVar}Data['data-$debugBarVar-param'].value);\n";
$new .= "{$scriptContentAfter}$closeScriptTag";
$content = $content->replace($old, $new)->value();
$original = null;
if ($response instanceof \Illuminate\Http\Response && $response->getOriginalContent()) {
$original = $response->getOriginalContent();
}
// Update the new content and reset the content length
$response->setContent($content);
$response->headers->remove('Content-Length');
// Restore original response (eg. the View or Ajax data)
if ($original) {
$response->original = $original;
} What it does is using a regex (uh oh) to grab the values of that. It can easily be loaded with JSON.parse(document.querySelector('script[data-phpdebugbar-data]').attributes['data-$debugBarVar-data'].value)) Now the content of the The only problem remaining now, is to get the middleware in the correct order so |
I am running into this too. I could really use a clean solution to setting a nonce for any styles/scripts that debugbar injects inline. This seems to be a recurring theme |
Only semi workaround for this (when using
Both options will allow debug bar to display. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
What about #1464? |
Hi,
i'm using the laravel-debugbar and works like a charm, but when adding CSP the debugbar stop showing.
Laravel :
"laravel/framework": "^8.0"
"spatie/laravel-csp": "2.6.4",
Debugbar :
"barryvdh/laravel-debugbar": "^3.5"
Thank's for the help
The text was updated successfully, but these errors were encountered: