Skip to content

feat(browser): Add a Trusted Types policy for scripts the SDK loads - #24738

Draft
oioki wants to merge 1 commit into
developfrom
feat/report-dialog-trusted-types
Draft

oioki wants to merge 1 commit into
developfrom
feat/report-dialog-trusted-types

Conversation

@oioki

@oioki oioki commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Pages that enforce Trusted Types (require-trusted-types-for 'script') reject plain strings in script-URL sinks, and the SDK has several that apps can't wrap because the URL is built internally. This adds a shared getTrustedScriptURL helper in @sentry/browser-utils that mints URLs through a single sentry-sdk policy, and uses it for showReportDialog as the first caller.

A single SDK-wide policy means users add one name to their trusted-types directive, instead of one per feature. The other script-URL sinks can then move onto it: the replay compression worker (new Worker(blobURL)) and lazyLoadIntegration. The policy only accepts the kinds of URL the SDK actually loads, currently just the error-page embed endpoint, so it can't be used to load arbitrary scripts. Each new kind gets added together with the code that loads it.

Without Trusted Types, or if the policy can't be created (for example the name isn't allowlisted), the raw URL is used exactly as before. The policy is per SDK copy rather than shared through the global carrier: sharing it across SDK versions would apply one version's URL rules to another's. Pages that load more than one SDK copy need 'allow-duplicates', which the debug warning mentions.

Minimal local types are declared for window.trustedTypes, since the DOM lib doesn't include Trusted Types and this avoids a new dependency.

Found while rolling out Trusted Types in Sentry's own frontend.

https://claude.ai/code/session_01T35on2nNWQAfBWfSA9eBp1

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 29.24 kB - -
@sentry/browser - with treeshaking flags 27.5 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 27.4 kB - -
@sentry/browser (incl. Tracing) 51.15 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 51.17 kB - -
@sentry/browser (incl. Tracing, Profiling) 54.18 kB - -
@sentry/browser (incl. Tracing, Replay) 90.76 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 79.86 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 95.46 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 108.41 kB - -
@sentry/browser (incl. Feedback) 46.76 kB - -
@sentry/browser (incl. sendFeedback) 34.3 kB - -
@sentry/browser (incl. FeedbackAsync) 39.41 kB - -
@sentry/browser (incl. Metrics) 30.25 kB - -
@sentry/browser (incl. Logs) 30.51 kB - -
@sentry/browser (incl. Metrics & Logs) 31.18 kB - -
@sentry/react 31.27 kB +0.89% +275 B 🔺
@sentry/react (incl. Tracing) 53.74 kB +0.55% +293 B 🔺
@sentry/vue 36.74 kB - -
@sentry/vue (incl. Tracing) 53.7 kB - -
@sentry/svelte 29.26 kB - -
CDN Bundle 31.09 kB +0.51% +156 B 🔺
CDN Bundle (incl. Tracing) 51.84 kB +0.3% +152 B 🔺
CDN Bundle (incl. Logs, Metrics) 33.35 kB +0.47% +154 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) 53.81 kB +0.28% +146 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) 74.08 kB +0.22% +160 B 🔺
CDN Bundle (incl. Tracing, Replay) 89.43 kB +0.17% +150 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 91.4 kB +0.17% +152 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) 95.61 kB +0.17% +160 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 97.58 kB +0.17% +165 B 🔺
CDN Bundle - uncompressed 91.85 kB +0.49% +442 B 🔺
CDN Bundle (incl. Tracing) - uncompressed 154.21 kB +0.29% +442 B 🔺
CDN Bundle (incl. Logs, Metrics) - uncompressed 98.42 kB +0.46% +442 B 🔺
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 160.17 kB +0.28% +442 B 🔺
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 227.99 kB +0.2% +442 B 🔺
CDN Bundle (incl. Tracing, Replay) - uncompressed 273.94 kB +0.17% +442 B 🔺
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 279.88 kB +0.16% +442 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 287.65 kB +0.16% +442 B 🔺
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 293.57 kB +0.16% +442 B 🔺
@sentry/nextjs (client) 55.77 kB - -
@sentry/sveltekit (client) 51.59 kB - -
@sentry/core/server 39.95 kB - -
@sentry/core/browser 13.63 kB - -
@sentry/node 134.08 kB +0.01% +10 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.43 kB - -
@sentry/node - without tracing 90.46 kB +0.02% +17 B 🔺
@sentry/node - without channel injection 112.59 kB +0.01% +11 B 🔺
@sentry/aws-serverless 98.72 kB +0.01% +4 B 🔺
@sentry/cloudflare (withSentry) - minified 206.49 kB - -
@sentry/cloudflare (withSentry) 513.73 kB - -

View base workflow run

showReportDialog assigned a plain string to script.src, which pages that
enforce Trusted Types reject. Add a shared getTrustedScriptURL helper in
browser-utils that mints URLs through a single "sentry-sdk" policy, and use
it for the report dialog.

One SDK-wide policy means users allowlist one name, and the other SDK script
sinks (the replay compression worker, lazy-loaded integrations) can move onto
it later. The policy only accepts the kinds of URL the SDK actually loads,
currently the error-page embed endpoint. Without Trusted Types, or if the
policy can't be created, the raw URL is used as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T35on2nNWQAfBWfSA9eBp1
@oioki
oioki force-pushed the feat/report-dialog-trusted-types branch from fece237 to ba2d12c Compare September 25, 2026 12:34
@oioki oioki changed the title feat(browser): Load the report dialog script through a Trusted Types policy feat(browser): Add a Trusted Types policy for scripts the SDK loads Sep 25, 2026

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant