PostHog / PostHog/posthog

CSP violation when enabling the recorder

Open
#34,840 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
39.9k
Forks
3.4k
Avg merge
7h 27m
Merged PRs (30d)
222

Description

Bug Description

Hi,
thank you for the great work.

I am here to report an issue with CSP: as context, the CSP config from the app on which I am running Posthog does not include unsafe-inline for the style-src.

When the session recording feature is enabled, I can see this error on the browser console:
Image

Checking the docs, I thought this was the fix:

      prepare_external_dependency_script: (script) => {
        script.nonce = appNonce;
        return script;
      },
      // this bit in particular
      prepare_external_dependency_stylesheet: (stylesheet) => {
        stylesheet.nonce = appNonce;
        return stylesheet;
      }

But from my tests, it does not fix it. To add more, adding a console.log there to print the files targeted by those functions, the record.js looks to be not one of them.

We have plenty of the errors as from screenshot and they are polluting the browser's console. I wonder if you can suggest a solution.

Thank you,
Luca

Debug info
- [X] PostHog Cloud, Debug information: [please copy/paste from https://us.posthog.com/settings/project-details#variables or https://eu.posthog.com/settings/project-details#variables]
- [ ] PostHog Hobby self-hosted with `docker compose`, version/commit: [please provide]
- [ ] PostHog self-hosted with Kubernetes (deprecated, see [`Sunsetting Kubernetes support`](https://posthog.com/blog/sunsetting-helm-support-posthog)), version/commit: [please provide]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how the session recorder loads record.js and compare that path with prepare_external_dependency_script and prepare_external_dependency_stylesheet. Reproduce the browser CSP error with recording enabled; done means the recorder no longer produces the reported style-src violations under a policy without unsafe-inline.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.