Skip to content
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

Update react-error-overlay CSP hash #1792

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/1792.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update react-error-overlay CSP hash
3 changes: 2 additions & 1 deletion internals/getSecurityHeaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const localnet = `
const hmrWebsocket = `
ws://localhost:2222
`
const reactErrorOverlay = `'sha256-RV6I4HWPb71LvA27WVD3cEz8GsJrHlfcM/2X2Q5gV00='`
// If this changes csp-react-error-overlay.spec.ts will print a new sha in an error in csp-react-error-overlay.spec.ts.
const reactErrorOverlay = `'sha256-yt+SNVxRkIi6H6yb7ndFuZM1esMX9esg3UpRHaTsyVk='`
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment where we can find this ID so everyone is aware of it and also when it changes?

Copy link
Member Author

Choose a reason for hiding this comment

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

Related: #1609 (comment)

I copy it from chrome console, it's printed on any hot-module-reload when it's broken.

Modified the test so it would now print:

  1) [chromium]  csp-react-error-overlay.spec.ts:5:5  Dev Content-Security-Policy should allow react-error-overlay 

    Error: expect(received).not.toMatchObject(expected)

    Expected: not {"type": "error"}
    Received:     {"args": [], "location": {"columnNumber": 0, "lineNumber": 2769, "url": "http://localhost:3000/index.2b04b272.js"}, "text": "Refused to execute inline script because it violates the following Content Security Policy directive: \"script-src 'self' 'sha256-RV6I4HWPb71LvA27WVD3cEz8GsJrHlfcM/2X2Q5gV00=' 'unsafe-eval' 'report-sample'\". Either the 'unsafe-inline' keyword, a hash ('sha256-yt+SNVxRkIi6H6yb7ndFuZM1esMX9esg3UpRHaTsyVk='), or a nonce ('nonce-...') is required to enable inline execution.
    ", "type": "error"}

       at ../utils/expectNoErrorsInConsole.ts:37

      35 |         text: message.text(),
      36 |         type: message.type(),
    > 37 |       }).not.toMatchObject({
         |              ^
      38 |         type: 'error',
      39 |       })
      40 |     }

it's hard to make a prettier output

const hmrScripts = `
'unsafe-eval'
`
Expand Down
2 changes: 2 additions & 0 deletions playwright/tests/csp-react-error-overlay.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { test, expect } from '@playwright/test'
import { reactErrorOverlay } from '../../internals/getSecurityHeaders.js'
import { expectNoErrorsInConsole } from '../utils/expectNoErrorsInConsole'

test('Dev Content-Security-Policy should allow react-error-overlay', async ({ page, baseURL }) => {
if (baseURL !== 'http://localhost:3000') test.skip()
expect((await page.request.head('/')).headers()).toHaveProperty('content-security-policy')
expect((await page.request.head('/')).headers()['content-security-policy']).toContain(reactErrorOverlay)
await page.goto('/e2e')
await page.getByRole('button', { name: 'Trigger uncaught error' }).click()
await expectNoErrorsInConsole(page)
await expect(page.locator('iframe')).toBeVisible()
await expect(page.frameLocator('iframe').getByText('ReferenceError')).toBeVisible()
})
Loading