Repository navigation
feat(feedback): Render error page embed without innerHTML - #132185
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🚨 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 |
mjq
left a comment
There was a problem hiding this comment.
@msonnb I'd recommend adding an integration test for this that checks that the Django and html_to_tree versions match:
- Render the Django template with a representative
UserReportFormand context. - Load the actual embed endpoint.
- 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);
- 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.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Good points, thanks! Did both in ca23465. |
Pages enforcing Trusted Types (
require-trusted-types-for 'script') block the crash report dialog because its script assignsinnerHTML.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_htmlsafebecause 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