Skip to content

feat(feedback): Render error page embed without innerHTML - #132185

Merged
msonnb merged 2 commits into
masterfrom
ms/error-embed-trusted-types
Nov 26, 2026
Merged

msonnb merged 2 commits into
masterfrom
ms/error-embed-trusted-types

Conversation

@msonnb

@msonnb msonnb commented Nov 23, 2026

Copy link
Copy Markdown
Member

Pages enforcing Trusted Types (require-trusted-types-for 'script') block the crash report dialog because its script assigns innerHTML.

The backend now sends the rendered template as a node tree that the script builds with DOM APIs. Unlike a Trusted Types policy, this needs no CSP change from users, and the Django template stays the single source for the markup. The tree is serialized with dumps_htmlsafe because text in it is no longer HTML-escaped.

Compared the old and new dialog in Chromium and WebKit (en, fr, ja): identical DOM and pixels.

Refs getsentry/sentry-javascript#24744

@github-actions github-actions Bot added Scope: Frontend Automatically applied to PRs that change frontend components Scope: Backend Automatically applied to PRs that change backend components labels Nov 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚨 Warning: This pull request contains Frontend and Backend changes!

It's discouraged to make changes to Sentry's Frontend and Backend in a single pull request. The Frontend and Backend are not atomically deployed. If the changes are interdependent of each other, they must be separated into two pull requests and be made forward or backwards compatible, such that the Backend or Frontend can be safely deployed independently.

Have questions? Please ask in the #discuss-dev-infra channel.

@msonnb
msonnb marked this pull request as ready for review November 24, 2026 15:37
@msonnb
msonnb requested review from a team as code owners November 24, 2026 15:37

@mjq mjq left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@msonnb I'd recommend adding an integration test for this that checks that the Django and html_to_tree versions match:

  1. Render the Django template with a representative UserReportForm and context.
  2. Load the actual embed endpoint.
  3. Construct a detached reference element using the original rendered HTML, e.g.:
      const expected = document.createElement('div');
      expected.innerHTML = renderedHtml;
    
      const actual = document.querySelector('.sentry-error-embed-wrapper');
    
      return expected.isEqualNode(actual);
  4. Assert equality in Python too.

It may be true that _HTMLTreeBuilder can accurately reproduce the current template, but there are likely edge cases it doesn't support that we could start hitting if the template (or Chrome) changed in the future, and this protects us from that.


Separately, for defence in depth, may want to blocklist script explicitly when constructing the tree. innerHTML would prevent those from running even if one snuck in, but the new way would actually execute it.

@msonnb

msonnb commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Good points, thanks! Did both in ca23465.

@msonnb
msonnb merged commit 828aac0 into master Nov 26, 2026
89 checks passed
@msonnb
msonnb deleted the ms/error-embed-trusted-types branch November 26, 2026 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants