Skip to content

HoneyPot CSS Style nonce (when using CSP) does not work with Web Page Caching #8020

Description

@lazaruscorporation

PHP Version

8.1

CodeIgniter4 Version

4.4.0

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Linux

Which server did you use?

apache

Database

10.6.15-MariaDB

What happened?

My site uses CodeIgniter's CSP settings to add a nonce to all CSS and JS files.

The HoneyPot functionality automatically adds a line like this to the :

<style nonce="12ee98b7295c5cf83507941d">#hpc { display:none }</style>

However I have noticed in my browser console that occasionally (not always) this throws a CSP error:

Content-Security-Policy: The page's settings blocked the loading of a resource at inline ("style-src").

Examining the HTML on these errors I noticed that the nonce value for the HoneyPot style is incorrect (i.e. it differs from the nonce value generated by CodeIgniter for my website CSS file. For example, the CSS nonce value on my website stylesheet is "6db8349911d11cd230ce3ad5" but the CSS nonce value on the Honeypot style element is "12ee98b7295c5cf83507941d"

In these cases the website CSS is delivered to the browser correctly, but the HoneyPot CSS is not, so I presume that the nonce on the Honeypot is being generated incorrectly on these occasions.

Temporary fix: I have added the HoneyPot CSS rule into my general website CSS so that the HoneyPot field is always styled as display:none

I can't supply a URL where you can definitely test this as the console error is not always there (and on these occasions the Honeypot CSS nonce is the same as the website CSS nonce in the HTML).

Steps to Reproduce

The error is intermittent, so I can't give a URL where you will definitely see it, but you could start at https://www.lazaruscorporation.co.uk/blogs/artists-notebook/posts/new-site-2023 and navigate around until you see the console error

Note that as mentioned above, even though the Honeypot CSS is not being deployed on the page I have added the HoneyPot CSS rule into my website CSS as a temporary fix so that the HoneyPot field is always styled as display:none

Expected Output

I expected the nonce on the HoneyPot CSS to be correct on every request so that it is not blocked when using CSP.

Anything else?

No response

Activity

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

Metadata

Metadata

Assignees

No one assigned

    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