Skip to content

Extend CSP Configuration #909

@guspower

Description

@guspower

What are you building with SQLPage ?

A blog

What is your problem ? A description of the problem, not the solution you are proposing.

The Mozilla observatory marks the site down on the CSP configuration. This configuration has not been modified from the default values.

Image

If I set the configuration value CONTENT_SECURITY_POLICY then I lose the nonce functionality as this only kicks in if there is no explicit configuration specified.

I also tried to add multiple values to the same header:

SELECT 'http_header'          AS component,
       'object-src ''none'';' AS "Content-Security-Policy";

SELECT 'http_header'        AS component,
       'base-uri ''none'';' AS "Content-Security-Policy";

but alas it seems the last value wins (they are not combined or multiples sent to the client).

What are you currently doing ? Since your solution is not implemented in SQLPage currently, what are you doing instead ?

I could workaround the limitation as described in an earlier issue. However I would like to extend SQLpage to handle this circumstance.

Describe the solution you'd like

The CSP headers could be configured as per the strict definition without workaround:

Content-Security-Policy:
  frame-ancestors 'none';
  upgrade-insecure-requests;
  script-src 'nonce-{RANDOM}';
  object-src 'none';
  base-uri 'none';

Describe alternatives you've considered

It seems like there could be a few ways to handle this:

  1. Enhance the CSP configuration parsing to cater for nonce
  2. Go long on CSP configuration and allow each element to be optionally configured ('script-src', 'object-src' etc.)
  3. Create a CSP component
  4. Make the nonce value available in the SQL context
  5. Allow the same header to be written multiple times
  6. Combine / append header values with the same name

Additional context

It would also be great to be able to test a CSP policy change, but looking at it it does seem pretty wild (report only with reporting endpoints etc.). There is also the situation where certain pages need a custom CSP configuration because they actually contain an embed.

If you think this is worthwhile and have a preferred route, I would be happy to create a patch for consideration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions