Skip to content

[Enhancement]: Enable CSP 3 support in app config #4488

Open

Description

@coderabbitai

Overview

Now that all the keywords and directives are supported for CSP 3, we should look into and attempt to enable $CSPEnabled in app/Config/App.

Background

This was identified as a follow-up task from PR #4485 (Update to CodeIgniter 4.7.2). The $CSPEnabled property was previously disabled due to CSP 3 tag incompatibilities, but those limitations have since been addressed in the updated configuration.

Tasks

  • Review the current CSP configuration in app/Config/ContentSecurityPolicy.php
  • Verify that all CSP 3 keywords and directives are properly supported
  • Enable $CSPEnabled = true in app/Config/App.php
  • Test thoroughly to ensure no regressions

References

Activity

  1. coderabbitai commented on Apr 13, 2026

    @coderabbitai
    ContributorAuthor

    CSP *-src-elem / *-src-attr directive defaults

    Carried over from PR #4485 (discussion at #4485 (comment)).

    Context

    As part of the CodeIgniter 4.7.2 upgrade, four new CSP Level 3 properties were added to app/Config/ContentSecurityPolicy.php with the CI upstream defaults of 'self':

    • $scriptSrcElem = 'self'
    • $scriptSrcAttr = 'self'
    • $styleSrcElem = 'self'
    • $styleSrcAttr = 'self'

    Issue

    In CSP Level 3, the script-src-elem and script-src-attr directives supersede script-src when present — the browser only falls back to script-src if the more-specific directive is absent. The same applies to style-src-elem / style-src-attr vs style-src.

    This means the CI defaults of 'self' override — rather than refine — the existing $scriptSrc and $styleSrc rules, which allow:

    • unsafe-inline, unsafe-eval, www.google.com, www.gstatic.com (scripts)
    • unsafe-inline, nonce placeholder, https://fonts.googleapis.com (styles)

    If $CSPEnabled were set to true today without adjusting these properties, Google Maps scripts, Google Fonts stylesheets, and all inline scripts/styles would be blocked even though they are explicitly permitted in the broader $scriptSrc/$styleSrc rules.

    Options to consider when enabling CSP

    Option Behaviour
    Keep CI defaults ('self') Stricter — CDN/inline permissions must be explicitly duplicated into each *-src-elem/attr property. Safer long-term for a tightened policy.
    Set to null Browser falls back to $scriptSrc/$styleSrc; existing allowlists remain effective immediately. Less migration work.
    Explicitly mirror existing $scriptSrc/$styleSrc values Most explicit; no ambiguity about what is allowed per directive.

    Since $CSPEnabled remains false there is no current impact, but this should be resolved before enabling CSP.

  2. added a commit that references this issue on Apr 15, 2026
    5d782fa
  3. changed the title [-]Enable $CSPEnabled in app/Config/App (CSP 3 Support)[/-] [+][Enhancement]: Enable CSP 3 support in app config[/+] on Apr 20, 2026
  4. objecttothis commented on Oct 27, 2026

    @objecttothis
    Member

    Claude Issue Checker Agent (cc @objecttothis)

    Investigated against current master.

    Status: Still present (not yet merged).

    app/Config/App.php still has public bool $CSPEnabled = false; — CSP remains disabled by default. There is an open, unmerged PR addressing this directly: #4502 "feat: Enable Content Security Policy (CSP)" (linked to this issue), which has not landed on master yet. The enhancement requested here (enabling $CSPEnabled = true after verifying CSP 3 keyword/directive support) has not been completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions