Repository navigation
Conversation
|
bugbot run |
size-limit report 📦Compared: 2162c51 (PR test merge using develop at cf84d81) Against: cf84d81 (develop) · base run #68198 ✅ Baseline matches: this diff contains only this PR's changes.
|
|
One or more gzipped bundles increased by more than 500 bytes. If this increase is intentional, add the Accept Bundlesize Increase label to this PR to rerun and accept the check. |
Optional E2E testsSome optional checks were not successful. They do not block the merge. 1 not successful, 64 successful. See the run.
Successful checks
|
| window._violations = []; | ||
| document.addEventListener('securitypolicyviolation', event => { | ||
| window._violations.push(`${event.violatedDirective}: ${event.sample}`); | ||
| }); |
There was a problem hiding this comment.
l: I see in the lazyLoad test, we do this in test.ts, vs. in this test in subject.js. Any reason for this? I'm fine with both, just curious. If no reason, maybe it makes sense to settle on one way of doing it, but will leave it up to you
There was a problem hiding this comment.
no particular reason. moved this to test.ts since the replay test needs it there.
| // The DOM lib has no Trusted Types definitions. | ||
| interface ScriptURLPolicy { |
There was a problem hiding this comment.
l: just for future reference, because this isn't well-known yet, we could link to https://developer.mozilla.org/en-US/docs/Web/API/TrustedTypePolicy
| // The DOM lib has no Trusted Types definitions. | |
| interface ScriptURLPolicy { | |
| // The DOM lib has no Trusted Types definitions. | |
| // @see https://developer.mozilla.org/en-US/docs/Web/API/TrustedTypePolicy | |
| interface ScriptURLPolicy { |
|
|
||
| interface TrustedTypesWindow { | ||
| trustedTypes?: { | ||
| createPolicy(name: string, rules: { createScriptURL(input: string): string }): ScriptURLPolicy; |
There was a problem hiding this comment.
m: above in ScriptURLPolicy, createScriptURL returns unknown. Here it returns string. Is the divergence intentional?
There was a problem hiding this comment.
our policy returns a string, which the browser then wraps in aTrustedScriptURL, the unknown was sort of hiding that. Added a named type to make it more clear.
|
|
||
| function createScriptURL(input: string): string { | ||
| if (!isBlobURL(input) && !isReportDialogURL(input) && !isCdnBundleURL(input)) { | ||
| throw new TypeError(`Refusing to load ${input} as a Sentry SDK script`); |
There was a problem hiding this comment.
m/q: Would our SDK throw an error to the user application if we throw here? If so, is this expected behavior for policies?
There was a problem hiding this comment.
Yes, throwing is how policies should reject invalid values (example). Since we only call this with URLs we build ourselves, it should never happen in practice though. If it does, it's either 1) a bug on our side, where we changed a URL so it no longer matches, or 2) something untrusted got into the URL or is calling our policy directly (e.g. XSS), in which case we want to reject it. I added a test that checks all lazy-loaded bundle URLs against the policy to catch 1) better.
showReportDialog would indeed have thrown into the user app, also when the CSP doesn't allow our policy and the browser itself throws. I updated it to call onError instead. Replay and lazyLoadIntegration already catch this correctly.
Canvas recording creates its worker from a `blob:` URL string, which pages enforcing Trusted Types (`require-trusted-types-for 'script'`) block. The new option lets the caller convert that URL, so the Sentry SDK can use its own `sentry-sdk` policy (getsentry/sentry-javascript#26764) and users don't have to allow another policy name for rrweb. Behavior is unchanged without it. Refs getsentry/sentry-javascript#24744 Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
logaretm
left a comment
There was a problem hiding this comment.
Minor change, otherwise will approve 👍
| tunnelStore?: TunnelStore; | ||
|
|
||
| /** Trusted Types policy of the browser SDK. Shared because a page can only create a policy name once. */ | ||
| trustedTypesPolicy?: { createScriptURL(input: string): unknown }; |
There was a problem hiding this comment.
l: worth re-using the same types defined in the trustedTypes.ts in browser-utils if possible. Since both types can drift. WDYT?
There was a problem hiding this comment.
good point, i moved the shared type into core next to the other vendored web API types in 7e5046b
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 3 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 7e5046b. Configure here.
| function getScriptURL(bundle: string): string { | ||
| const client = getClient<BrowserClient>(); | ||
| const baseURL = client?.getOptions()?.cdnBaseUrl || 'https://browser.sentry-cdn.com'; | ||
|
|
There was a problem hiding this comment.
CDN base path is stripped
Medium Severity
getScriptURL and isCdnBundleURL both pass a path-absolute /${SDK_VERSION}/... into new URL with cdnBaseUrl as the base. A leading slash replaces the base path, so a value like https://cdn.example.com:8443/some/path/ loads and allowlists https://cdn.example.com:8443/${version}/... instead of keeping /some/path/. The new tests use that path-style base but only check that the generated URL is accepted, so the dropped prefix is not caught.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 7e5046b. Configure here.
There was a problem hiding this comment.
preexisting, but might be worth a follow-up
| function isReportDialogURL(input: string): boolean { | ||
| const dsn = getClient()?.getDsn(); | ||
| // Matching up to and including the `?` pins the origin and the full path, so only the query can vary. | ||
| return !!dsn && input.startsWith(`${getReportDialogEndpoint(dsn, {}).split('?')[0]}?`); |
There was a problem hiding this comment.
Policy looks up the current client
Low Severity
This is more an “is this necessary” check than a hard violation: getCdnBaseUrl and isReportDialogURL call getClient() for cdnBaseUrl and the DSN. The Trusted Types policy is a process-wide singleton, so a multi-client page can validate a URL against a different client than the one that built it and reject a legitimate script.
Additional Locations (1)
Triggered by project rule: PR Review Guidelines for Cursor Bot
Reviewed by Cursor Bugbot for commit 7e5046b. Configure here.
There was a problem hiding this comment.
both callers build the URL and pass it here synchronously, so i don't think it can happen that it's a different client here
…oads Add a `sentry-sdk` policy that only accepts the script URLs the SDK loads. It is shared between SDK copies of the same version, because a page can only create a policy name once unless it allows duplicates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Use the `sentry-sdk` Trusted Types policy for the report dialog, lazy loaded integrations and the replay compression worker, so they work on pages that enforce `require-trusted-types-for 'script'`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er-utils Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7e5046b to
8b5b5c4
Compare
Pages enforcing Trusted Types (`require-trusted-types-for 'script'`) block the Loader from setting the `src` of the SDK script. The Loader now creates a `sentry-loader` policy that only ever returns the bundle URL rendered by the backend. It's separate from the SDK's `sentry-sdk` policy (getsentry/sentry-javascript#26764) because it has to exist before the SDK loads, and sharing a name would require `'allow-duplicates'`. Pages with a `trusted-types` directive need to add `sentry-loader`. If it isn't allowed, the Loader falls back to the plain URL, as before. The object literal changes in `js-sdk-loader.js.tmpl` come from regenerating the template after #131758. Refs getsentry/sentry-javascript#24744 --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>


What
showReportDialog,lazyLoadIntegrationand the Replay compression worker now work on pages that enforce Trusted Types, if the page allows the SDK's policy withtrusted-types sentry-sdk. Nothing changes for pages without Trusted Types.Why
These sinks reject plain strings, and apps can't wrap URLs the SDK builds internally. One named policy that checks URLs means users allow a single name instead of adding a pass-through
defaultpolicy.'allow-duplicates'. Only pages with different SDK versions need that keyword.blob:URL of the page's own origin. It can't tell which ones the SDK created, because the Replay add-on may create the worker URL in a different copy. A private list would break that case. A shared list would be tighter, but any script could add to it, so it didn't seem worth the extra global state.workerUrlis passed through unchanged, so a plain string is still blocked and Replay falls back to uncompressed recordings.Not covered here: the canvas worker (in rrweb), the Loader Script, and
error-page-embed.js, whoseinnerHTMLuse still blocks the dialog itself. Based on the approach in #24738.Part of #24744