-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1609 from oasisprotocol/lw/dev-e2e
Add security headers to dev server
- Loading branch information
Showing
12 changed files
with
91 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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,17 @@ | ||
// @ts-check | ||
|
||
/** | ||
* Add security headers to dev server | ||
* @param {import('connect').Server} app | ||
*/ | ||
module.exports = (app) => { | ||
app.use((req, res, next) => { | ||
// Re-generate headers on every request so editing the file is reflected on reload. | ||
delete require.cache[require.resolve('./internals/getSecurityHeaders.js')]; | ||
const { getCsp, getPermissionsPolicy } = require('./internals/getSecurityHeaders.js') | ||
|
||
res.setHeader('Content-Security-Policy', getCsp({ isDev: true, isExtension: false })) | ||
res.setHeader('Permissions-Policy', getPermissionsPolicy()) | ||
next() | ||
}) | ||
} |
This file contains 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 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 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 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 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,12 @@ | ||
import { test, expect } from '@playwright/test' | ||
import { reactErrorOverlay } from '../../internals/getSecurityHeaders.js' | ||
|
||
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 expect(page.locator('iframe')).toBeVisible() | ||
await expect(page.frameLocator('iframe').getByText('ReferenceError')).toBeVisible() | ||
}) |
This file contains 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 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 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 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 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 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 |
---|---|---|
|
@@ -3554,6 +3554,13 @@ | |
resolved "https://registry.yarnpkg.com/@types/body-scroll-lock/-/body-scroll-lock-3.1.0.tgz#435f6abf682bf58640e1c2ee5978320b891970e7" | ||
integrity sha512-3owAC4iJub5WPqRhxd8INarF2bWeQq1yQHBgYhN0XLBJMpd5ED10RrJ3aKiAwlTyL5wK7RkBD4SZUQz2AAAMdA== | ||
|
||
"@types/[email protected]": | ||
version "3.4.35" | ||
resolved "https://registry.yarnpkg.com/@types/connect/-/connect-3.4.35.tgz#5fcf6ae445e4021d1fc2219a4873cc73a3bb2ad1" | ||
integrity sha512-cdeYyv4KWoEgpBISTxWvqYsVy444DOqehiF3fM3ne10AmJ62RSyNkUnxMJXHQWRQQX2eR94m5y1IZyDwBjV9FQ== | ||
dependencies: | ||
"@types/node" "*" | ||
|
||
"@types/graceful-fs@^4.1.3": | ||
version "4.1.5" | ||
resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.5.tgz#21ffba0d98da4350db64891f92a9e5db3cdb4e15" | ||
|