Repository navigation
fix(feedback): Render feedback widget without innerHTML for Trusted Types #26707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
msonnb
wants to merge
1
commit into
develop
Choose a base branch
from
ms/feedback-trusted-types
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+128
−90
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
dev-packages/browser-integration-tests/suites/feedback/trustedTypes/init.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import * as Sentry from '@sentry/browser'; | ||
| // Import this separately so that generatePlugin can handle it for CDN scenarios | ||
| import { feedbackIntegration } from '@sentry/browser'; | ||
|
|
||
| window.Sentry = Sentry; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| integrations: [feedbackIntegration({ enableScreenshot: true })], | ||
| }); |
4 changes: 4 additions & 0 deletions
4
dev-packages/browser-integration-tests/suites/feedback/trustedTypes/subject.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| window.__TRUSTED_TYPES_VIOLATIONS__ = []; | ||
| document.addEventListener('securitypolicyviolation', e => { | ||
| window.__TRUSTED_TYPES_VIOLATIONS__.push(`${e.violatedDirective}: ${e.sample}`); | ||
| }); |
8 changes: 8 additions & 0 deletions
8
dev-packages/browser-integration-tests/suites/feedback/trustedTypes/template.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <meta http-equiv="Content-Security-Policy" content="require-trusted-types-for 'script'" /> | ||
| </head> | ||
| <body></body> | ||
| </html> |
63 changes: 63 additions & 0 deletions
63
dev-packages/browser-integration-tests/suites/feedback/trustedTypes/test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import { expect } from '@playwright/test'; | ||
| import { sentryTest } from '../../../utils/fixtures'; | ||
| import { envelopeRequestParser, getEnvelopeType, testingCdnBundle } from '../../../utils/helpers'; | ||
|
|
||
| sentryTest.beforeEach(() => { | ||
| // CDN bundles lazy load the feedback modal through a `script.src` sink, which needs a Trusted Types policy. | ||
| sentryTest.skip(testingCdnBundle()); | ||
| }); | ||
|
|
||
| sentryTest('renders the feedback form without Trusted Types violations', async ({ getLocalTestUrl, page }) => { | ||
| const feedbackRequestPromise = page.waitForRequest(req => { | ||
| try { | ||
| return getEnvelopeType(req) === 'feedback'; | ||
| } catch { | ||
| return false; | ||
| } | ||
| }); | ||
|
|
||
| await page.goto(await getLocalTestUrl({ testDir: __dirname })); | ||
| await page.getByText('Report a Bug').click(); | ||
|
|
||
| await expect(page.locator('.brand-link svg')).toBeVisible(); | ||
|
|
||
| await page.locator('[name="message"]').fill('my example feedback'); | ||
| await page.locator('[data-sentry-feedback] .btn--primary').click(); | ||
|
|
||
| expect(envelopeRequestParser(await feedbackRequestPromise).contexts?.feedback?.message).toBe('my example feedback'); | ||
| await expect(page.locator('.success__icon svg')).toBeVisible(); | ||
| expect(await page.evaluate(() => (window as any).__TRUSTED_TYPES_VIOLATIONS__)).toEqual([]); | ||
| }); | ||
|
|
||
| sentryTest( | ||
| 'renders the screenshot editor without Trusted Types violations', | ||
| async ({ getLocalTestUrl, page, browserName }) => { | ||
| sentryTest.skip(browserName !== 'chromium', 'The canvas screen-capture fixture requires Chromium.'); | ||
|
|
||
| await page.addInitScript(() => { | ||
| // The fixture runs over HTTP, but screenshot capture is stubbed below. | ||
| Object.defineProperty(window, 'isSecureContext', { value: true }); | ||
| Object.defineProperty(navigator, 'mediaDevices', { | ||
| value: { | ||
| getDisplayMedia: async () => { | ||
| const canvas = document.createElement('canvas'); | ||
| canvas.width = 800; | ||
| canvas.height = 600; | ||
| const ctx = canvas.getContext('2d')!; | ||
| ctx.fillStyle = 'white'; | ||
| ctx.fillRect(0, 0, canvas.width, canvas.height); | ||
| return canvas.captureStream(); | ||
| }, | ||
| }, | ||
| configurable: true, | ||
| }); | ||
| }); | ||
|
|
||
| await page.goto(await getLocalTestUrl({ testDir: __dirname })); | ||
| await page.getByRole('button', { name: 'Report a Bug', exact: true }).click(); | ||
| await page.getByRole('button', { name: 'Add a screenshot', exact: true }).click(); | ||
|
|
||
| await expect(page.locator('.editor__image-container')).toHaveCSS('padding', '15px'); | ||
| expect(await page.evaluate(() => (window as any).__TRUSTED_TYPES_VIOLATIONS__)).toEqual([]); | ||
| }, | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import type { VNode } from 'preact'; | ||
| import { h } from 'preact'; | ||
|
|
||
| /** | ||
| * Sentry Logo | ||
| */ | ||
| export function SentryLogo(): VNode { | ||
| return ( | ||
| <svg width="32" height="30" viewBox="0 0 72 66" fill="inherit"> | ||
| <path | ||
| transform="translate(11, 11)" | ||
| d="M29,2.26a4.67,4.67,0,0,0-8,0L14.42,13.53A32.21,32.21,0,0,1,32.17,40.19H27.55A27.68,27.68,0,0,0,12.09,17.47L6,28a15.92,15.92,0,0,1,9.23,12.17H4.62A.76.76,0,0,1,4,39.06l2.94-5a10.74,10.74,0,0,0-3.36-1.9l-2.91,5a4.54,4.54,0,0,0,1.69,6.24A4.66,4.66,0,0,0,4.62,44H19.15a19.4,19.4,0,0,0-8-17.31l2.31-4A23.87,23.87,0,0,1,23.76,44H36.07a35.88,35.88,0,0,0-16.41-31.8l4.67-8a.77.77,0,0,1,1.05-.27c.53.29,20.29,34.77,20.66,35.17a.76.76,0,0,1-.68,1.13H40.6q.09,1.91,0,3.81h4.78A4.59,4.59,0,0,0,50,39.43a4.49,4.49,0,0,0-.62-2.28Z" | ||
| /> | ||
| </svg> | ||
| ); | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import type { VNode } from 'preact'; | ||
| import { h } from 'preact'; | ||
|
|
||
| /** | ||
| * Success Icon (checkmark) | ||
| */ | ||
| export function SuccessIcon(): VNode { | ||
| return ( | ||
| <svg width="16" height="17" viewBox="0 0 16 17" fill="inherit"> | ||
| <path | ||
| fill-rule="evenodd" | ||
| clip-rule="evenodd" | ||
| d="M3.55544 15.1518C4.87103 16.0308 6.41775 16.5 8 16.5C10.1217 16.5 12.1566 15.6571 13.6569 14.1569C15.1571 12.6566 16 10.6217 16 8.5C16 6.91775 15.5308 5.37103 14.6518 4.05544C13.7727 2.73985 12.5233 1.71447 11.0615 1.10897C9.59966 0.503466 7.99113 0.34504 6.43928 0.653721C4.88743 0.962403 3.46197 1.72433 2.34315 2.84315C1.22433 3.96197 0.462403 5.38743 0.153721 6.93928C-0.15496 8.49113 0.00346625 10.0997 0.608967 11.5615C1.21447 13.0233 2.23985 14.2727 3.55544 15.1518ZM4.40546 3.1204C5.46945 2.40946 6.72036 2.03 8 2.03C9.71595 2.03 11.3616 2.71166 12.575 3.92502C13.7883 5.13838 14.47 6.78405 14.47 8.5C14.47 9.77965 14.0905 11.0306 13.3796 12.0945C12.6687 13.1585 11.6582 13.9878 10.476 14.4775C9.29373 14.9672 7.99283 15.0953 6.73777 14.8457C5.48271 14.596 4.32987 13.9798 3.42502 13.075C2.52018 12.1701 1.90397 11.0173 1.65432 9.76224C1.40468 8.50718 1.5328 7.20628 2.0225 6.02404C2.5122 4.8418 3.34148 3.83133 4.40546 3.1204Z" | ||
| /> | ||
| <path d="M6.68775 12.4297C6.78586 12.4745 6.89218 12.4984 7 12.5C7.11275 12.4955 7.22315 12.4664 7.32337 12.4145C7.4236 12.3627 7.51121 12.2894 7.58 12.2L12 5.63999C12.0848 5.47724 12.1071 5.28902 12.0625 5.11098C12.0178 4.93294 11.9095 4.77744 11.7579 4.67392C11.6064 4.57041 11.4221 4.52608 11.24 4.54931C11.0579 4.57254 10.8907 4.66173 10.77 4.79999L6.88 10.57L5.13 8.56999C5.06508 8.49566 4.98613 8.43488 4.89768 8.39111C4.80922 8.34735 4.713 8.32148 4.61453 8.31498C4.51605 8.30847 4.41727 8.32147 4.32382 8.35322C4.23038 8.38497 4.14413 8.43484 4.07 8.49999C3.92511 8.63217 3.83692 8.81523 3.82387 9.01092C3.81083 9.2066 3.87393 9.39976 4 9.54999L6.43 12.24C6.50187 12.3204 6.58964 12.385 6.68775 12.4297Z" /> | ||
| </svg> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
general remark: I'm wondering why we previously didn't render the logos/icons as a Preact component but rather via
dangerouslySetInnerHTML. Any ideas?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from what I can tell the icons were just left as-is with minimal changes from their pre-Preact version. Using the plain
SVGElementthen requireddangerouslySetInnerHTMLin Preact. See https://github.com/getsentry/sentry-javascript/pull/10590/changes#diff-0b90146add02dcb414427bdcf514cde78470a7e12d95e50b2fec8ad32513a0a2