Skip to content

Implement CSP support in Volto #7281

@nileshgulia1

Description

@nileshgulia1

Is your feature request related to a problem? Please describe.
Some JS scripts or third parties have unsafe-eval for their functionality. This is caused by the way webpack bundles the scripts, so it's not something that we can avoid. This impacts the security score of websites at EEA and in general.

Webpack provides a mechanism to mark scripts with a nonce string, which can then be added as a value in the CSP headers. This would properly identify the scripts to the browser and would get rid of this security vulneratiblity.

The task is to implement Webpack's CSP support in Volto, so that it can propagate to all Volto websites.

Deliverables
1 . We can generate nonces in Volto's SSR process and provide them to scripts and possibly styles too. That would mark them as "trusted" and potentially any other scripts loaded from those scripts as well.
2. Having a env var configuration something like:

config.settings.serverConfig.csp = {
      'script-src': `'self' {nonce}`,
    };

The nonce placeholder will be replaced by actual nonce at runtime. The CSP config will be then passed as Content-Security policy response header.

Assumptions:

Most websites already set these headers using a reverse proxy or HAProxy, which will override this setting. I suggest we handle it so that if the header contains a nonce placeholder, it gets replaced with the nonce generated by the express server.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions