-
-
Notifications
You must be signed in to change notification settings - Fork 57
Added csp option on default script tag #98
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
base: 2.x
Are you sure you want to change the base?
Changes from 2 commits
b4a0790
6efe10d
c902ac4
2fbc9df
0def872
9bbe024
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,19 @@ | |
|
|
||
| 'policy' => null, | ||
|
|
||
| /* | ||
| |-------------------------------------------------------------------------- | ||
| | CSP configuration | ||
| |-------------------------------------------------------------------------- | ||
| | | ||
| | Most cookie notices display a link to a dedicated page explaining | ||
| | the extended cookies usage policy. If your application has such a page | ||
| | you can add its route name here. | ||
| | | ||
| */ | ||
|
|
||
| 'csp_enable' => env('CSP_ENABLE', false), | ||
|
||
|
|
||
| /* Google Analytics configuration | ||
| |-------------------------------------------------------------------------- | ||
| | | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
|
|
||
| use Illuminate\Http\Request; | ||
| use Illuminate\Support\Facades\Cookie as CookieFacade; | ||
| use Illuminate\Support\Str; | ||
|
||
| use Symfony\Component\HttpFoundation\Cookie as CookieComponent; | ||
|
|
||
| class CookiesManager | ||
|
|
@@ -198,13 +199,21 @@ protected function getConsentedScripts(bool $withDefault): string | |
|
|
||
| protected function getDefaultScriptTag(): string | ||
| { | ||
| $csp_enable = config('cookieconsent.csp_enable', false); | ||
|
|
||
| return '<script ' | ||
| . 'src="' . route('cookieconsent.script') . '?id=' | ||
| . md5(\filemtime(LCC_ROOT . '/dist/script.js')) . '" ' | ||
| . ($csp_enable ? 'nonce="' . $this->generateCspNonce() . '" ' : '') | ||
| . 'defer' | ||
| . '></script>'; | ||
| } | ||
|
|
||
| protected function generateCspNonce(): string | ||
| { | ||
| return bin2hex(random_bytes(16)); | ||
| } | ||
|
|
||
|
||
| /** | ||
| * Output the consent alert/modal for current consent state. | ||
| */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a specific description for the CSP configuration, including:
env('CSP_ENABLE', false) && env('CSP_NONCE_ENABLED', true)