Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gapple created an issue. See original summary.

gapple’s picture

Maybe there should be toggle options for the static properties (e.g. 'unsafe-inline'), and a separate input for domains so that each domain can be validated and warnings can be placed on the appropriate toggle items.

gapple’s picture

Version: » 8.x-1.x-dev
Category: Task » Feature request
Priority: Normal » Major
FileSize
179.68 KB
307.4 KB

Report-URI has a CSP builder that uses a vertical-tabs like interface (https://report-uri.com/home/generate/)
Report-URI CSP builder

I've started to build out this, but it makes for a very long page if many directives are defined:
Proposed CSP admin form

gapple’s picture

New iteration with the list of directives for each of the enforced and report only policies in a separate vertical tab.
Proposed CSP admin form

gapple’s picture

Some smaller changes that you can see:
- A master checkbox to enable each of the enforced and report-only policies. The module won't do anything if both are disabled, so I'm pondering forcing at least one to be enabled when submitting the form.
- If automated values are provided for a directive (by default script-src and style-src), it must be enabled in configuration (the checkbox is checked and disabled). This forces setting a base value (by default 'self'), otherwise a directive could be enabled by an automated value and unexpectedly block resources. For example if a module were to provide a domain for connect-src but it's not configured, any http requests to the Drupal site would get reported or blocked (e.g. autocomplete, form AJAX...)

A lot of work behind the scenes:
- Updated the configuration schema and default configuration
- Update hook to modify the config for existing sites to the new defaults.
- Saving the form actually updates configuration
- The configuration affects the generated policies
- Policy class supports boolean directives ('block-all-mixed-content', 'upgrade-insecure-requests')

Since it's now actually functional, I'll attach a patch.

Proposed CSP admin form

Status: Needs review » Needs work

The last submitted patch, 5: csp-2895243-5-manual-policy.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

gapple’s picture

The configuration yml will look like this:

report:
  handler: csp-module
report-only:
  enable: true
  directives:
    script-src:
      base: 'self'
      flags:
        - 'unsafe-inline'
      sources:
        - 'test.example.com'
    style-src:
      base: 'self'
enforce:
  enable: false

Most directives use the same 'source-list' format as script-src and style-src, but a few directives are boolean values, or an array of keys:

    block-all-mixed-content: true
    plugin-types:
      - application/x-shockwave-flash
gapple’s picture

Status: Needs work » Needs review
FileSize
31.68 KB
5.93 KB

Add tests to the patch. Interdiff also shows an extra change that snuck into the previous patch.

Status: Needs review » Needs work

The last submitted patch, 8: csp-2895243-8-manual-policy.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

  • gapple committed eaa11a1 on 8.x-1.x
    Merge branch 'manual-options' into 8.x-1.x
    
    Issue #2895243:...
gapple’s picture

Status: Needs work » Fixed

Will open some follow up issues for a few remaining items, but I think this is sufficiently functional to put into a new release.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.