Skip to content

Content-Security-Policy : Trusted Types #15913

Closed
@tsaigne-simpliciti

Description

@tsaigne-simpliciti

Is there an existing issue for this?

How do you use Sentry?

Self-hosted/on-premise

Which SDK are you using?

@sentry/vue

SDK Version

9.2.0

Framework Version

Vue 3.5.0

Link to Sentry event

No response

Reproduction Example/SDK Setup

Using Content Security Policy, we have an error occuring in Sentry SDK.

This document requires 'TrustedScriptURL' assignment.

It occurs on worker instanciation (see screenshot attached)
I traced back to the ts source code sentry-javascript/packages/replay-internal/src/eventBuffer/index.ts

Image
(on the screenshot there are 2 affected resources, one is sentry, the other is vuetify)

This is something that has been done about that in vue, with this PR : vuejs/core#10844
It's about setting an element innerHTML but the part about creating a policy is similar.

Extracts :

// creates the policy
    policy = /*#__PURE__*/ tt.createPolicy('vue', {
      createHTML: val => val,
    })

// define a method to use the policy if exists
const unsafeToTrustedHTML: (value: string) => TrustedHTML | string = policy
  ? val => policy.createHTML(val)
  : val => val

// safe usage to set innerHTML
templateContainer.innerHTML = unsafeToTrustedHTML(the value)

Steps to Reproduce

Adding a CSP HTTP header on the server

Exemple :

Header set content-security-policy-report-only "\
    script-src 'self' https://{sentry-endpoint}; \
    require-trusted-types-for 'script'; \
    trusted-types default vue; \
    worker-src 'self' blob: ; \
    object-src 'none'; \
    connect-src 'self' https://{sentry-endpoint}; \
    img-src 'self' \
    blob: data: ; \
    style-src 'self'  "

Thank you for your time.

Expected Result

No CSP error

Actual Result

CSP Error : This document requires 'TrustedScriptURL' assignment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: replayIssues related to the Sentry Replay SDKPackage: vueIssues related to the Sentry Vue SDK

    Type

    Projects

    Status

    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions