close
Skip to content

Improve CSP instructions #20

Closed
Closed

Description

@louh

Similar to #4, but CSP headers need to be added even if it's not served from a custom subdomain. I think these instructions should be much more upfront, maybe here: https://docs.plausible.io/plausible-script

In particular I think it would be helpful to note specifically which CSP policies need to be edited, and provide some examples. e.g.

Lax CSP (simple and future proof):

Content-Security-Policy: default-src 'self' *.plausible.io

Stricter CSP (more precise, but can break if the implementation is changed, like reporting back to a different subdomain) (the script-src and connect-src policies need to be merged with any other existing domains for those directives

Content-Security-Policy: default-src 'self'; script-src plausible.io; connect-src plausible.io

Thanks for your work on this, giving this service a try now with the hope of replacing GA.

Activity

  1. metmarkosaric commented on Sep 24, 2020

    @metmarkosaric
    Contributor

    Thanks Lou! The reason we don't mention it much is because it doesn't seem to be a big problem for vast majority so didn't want to "clutter" the instructions with edge cases. Only heard from 2 people about CSP out of thousands who've used Plausible. Either most people don't use CSP or those that do are aware that they need to edit their policies for new services they add.

  2. divinerites commented on May 8, 2022

    @divinerites
    Contributor

    FYI in my plausible-hugo module, there is a dedicated partial for taking care of plausible in your CSP

  3. metmarkosaric commented on May 13, 2022

    @metmarkosaric
    Contributor

    thanks! i've added a note about CSP with a link to this thread on our troubleshoot your integration docs page

  4. jeremiahlee commented on Nov 21, 2024

    @jeremiahlee

    Adding to the above recommendation to include https://:

    Content-Security-Policy: default-src 'self'; script-src https://plausible.io; connect-src https://plausible.io

  5. JLT032 commented on Sep 30, 2026

    @JLT032

    based on my trials and errors it is recommended to insert a nonce to the script tags generated
    in addition it would be sensible to offer the script tags as two one-liners, since the larger script appears to be multi-line

    example:

    <script nonce="ceea07aa109f2e7b04c388ed0eaec9d223bac7085734fa3efcd6fe3aedcc35d0" async src="https://plausible.io/js/pa-ySovz4M_Z6ZkDkO-1i041.js"></script>
    <script nonce="76440ecf1f22af738c5b4c688a0bc31b61e3bcab108ec4a0f53c369290d5e92a">window.plausible=window.plausible||function(){(plausible.q=plausible.q||[]).push(arguments)},plausible.init=plausible.init||function(i){plausible.o=i||{}}; plausible.init()</script>
    

    this also requires for the script-src to be set as

    script-src 'nonce-ceea07aa109f2e7b04c388ed0eaec9d223bac7085734fa3efcd6fe3aedcc35d0' 'nonce-76440ecf1f22af738c5b4c688a0bc31b61e3bcab108ec4a0f53c369290d5e92a';
    
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