Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: CSP reportOnly behavior #6201

Merged
merged 1 commit into from
Jul 1, 2022
Merged

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Jun 29, 2022

Description

If we set $reportOnly = true, Content-Security-Policy header has some items.

How to Reproduce

diff --git a/app/Config/App.php b/app/Config/App.php
index 1a5e562dd..03e8eb649 100644
--- a/app/Config/App.php
+++ b/app/Config/App.php
@@ -461,5 +461,5 @@ class App extends BaseConfig
      *
      * @var bool
      */
-    public $CSPEnabled = false;
+    public $CSPEnabled = true;
 }
diff --git a/app/Config/ContentSecurityPolicy.php b/app/Config/ContentSecurityPolicy.php
index aa18ba9f1..d4a0d0817 100644
--- a/app/Config/ContentSecurityPolicy.php
+++ b/app/Config/ContentSecurityPolicy.php
@@ -24,7 +24,7 @@ class ContentSecurityPolicy extends BaseConfig
      *
      * @var bool
      */
-    public $reportOnly = false;
+    public $reportOnly = true;
 
     /**
      * Specifies a URL where a browser will send reports

before:

Content-Security-Policy: base-uri 'self'; child-src 'self'; connect-src 'self'; default-src 'self'; form-action 'self'; img-src 'self'; object-src 'self'; script-src 'self' 'nonce-3d1190def4cad593bb96b732'; style-src 'self' 'nonce-ddf1da493df6ee57425ef796';
Content-Security-Policy-Report-Only: img-src data:;

after:

Content-Security-Policy: 
Content-Security-Policy-Report-Only: base-uri 'self'; child-src 'self'; connect-src 'self'; default-src 'self'; form-action 'self'; img-src 'self' data:; object-src 'self'; script-src 'self' 'nonce-d13b60c8c68026e03a3377b7'; style-src 'self' 'nonce-f2471224b8c789bebddbb394'; report-uri /csp-report;

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added the bug Verified issues on the current code behavior or pull requests that will fix them label Jun 29, 2022
Copy link
Member

@MGatner MGatner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't say I fully understand it but the code and tests look good.

@lonnieezell
Copy link
Member

lonnieezell commented Jun 29, 2022

Side note: One thing that's been on my mental list since initial release was that it would be awesome to have a debug toolbar pane that show the CSP report. Not sure what all that would entail or if it's possible to show in a pane or not, but thought I'd drop the idea here before I forgot again. :)

@kenjis kenjis changed the title fix: CSR reportOnly behavior fix: CSP reportOnly behavior Jun 29, 2022
@kenjis
Copy link
Member Author

kenjis commented Jun 29, 2022

@kenjis kenjis merged commit 516e7dd into codeigniter4:develop Jul 1, 2022
@kenjis kenjis deleted the fix-csp-reportOnly branch July 1, 2022 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants