Problem/Motivation
Provide an alter hook enabling themes to alter the CSP policy.
Proposed resolution
/**
* Alters the CSP policy.
*
* This hook is only invoked for themes, modules should add an event subscriber listening to the CspEvents::POLICY_ALTER event.
*
* @param \Drupal\csp\Csp $policy
* The CSP policy.
* @param \Symfony\Component\HttpFoundation\Response $response
* The response the policy is applied to.
*/
function hook_csp_policy_alter(Csp $policy, Response $response): void {}
Remaining tasks
Invoke the hook and document it in csp.api.php.
Issue fork csp-3409435
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3409435-add-hookcsppolicyalter-for
changes, plain diff MR !21
Comments
Comment #3
dieterholvoet commentedComment #4
dieterholvoet commentedI added a first implementation in this Gin MR.
Comment #5
gappleI was thinking of adding it right in the response handler, but I like separating out the extra service dependency 🙂.
My only thought currently is to (de)prioritize this handler (e.g.
-10) so that it executes after module subscribers with a default priority.Comment #6
dieterholvoet commentedChanged it!
Comment #8
gapple