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

[security] Slightly improve CSP header #3757

Merged
merged 5 commits into from
Jul 6, 2024
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
19 changes: 19 additions & 0 deletions packages/toolpad-studio/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,23 @@ async function createToolpadHandler({
res.setHeader('X-Content-Type-Options', 'nosniff');
res.setHeader('X-XSS-Protection', '1; mode=block');
res.setHeader('Referrer-Policy', 'strict-origin-when-cross-origin');

res.setHeader(
'Content-Security-Policy',
[
`default-src * data: mediastream: blob: filesystem: about: ws: wss: 'unsafe-eval' 'wasm-unsafe-eval' 'unsafe-inline';`,
`script-src * data: blob: 'unsafe-inline' 'unsafe-eval';`,
`script-src-elem * data: blob: 'unsafe-inline';`,
`connect-src * data: blob: 'unsafe-inline';`,
`img-src * data: blob: 'unsafe-inline';`,
`media-src * data: blob: 'unsafe-inline';`,
`frame-src * data: blob: ;`,
`style-src * data: blob: 'unsafe-inline';`,
`font-src * data: blob: 'unsafe-inline';`,
`frame-ancestors *;`,
].join(' '),
);

expressNext();
});

Expand Down Expand Up @@ -279,6 +296,8 @@ async function startToolpadServer({ port, ...config }: ToolpadServerConfig) {
const circleBuildNum = process.env.CIRCLE_BUILD_NUM || null;

const app = express();
app.disable('x-powered-by');

const httpServer = createServer(app);

app.use(compression());
Expand Down
3 changes: 2 additions & 1 deletion test/integration/deploy/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ test.use({
});

test('can render in an iframe', async ({ page, baseURL }) => {
await page.goto('https://example.com');
await page.evaluate(
([src]) => {
const iframe = document.createElement('iframe');
iframe.src = src;
iframe.id = 'my-frame';
document.body.append(iframe);
document.body.replaceChildren(iframe);
},
[`${baseURL}/prod/pages/o57cdlq`],
);
Expand Down
8 changes: 3 additions & 5 deletions test/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PlaywrightTestConfig, devices } from '@playwright/test';
import { devices, defineConfig } from '@playwright/test';

process.env.BROWSER = 'none';

Expand All @@ -11,7 +11,7 @@ function getShard() {
return undefined;
}

const config: PlaywrightTestConfig<{ toolpadDev: boolean }> = {
export default defineConfig({
shard: getShard(),
forbidOnly: !!process.env.CI,
retries: process.env.TOOLPAD_TEST_RETRIES ? Number(process.env.TOOLPAD_TEST_RETRIES) : 0,
Expand Down Expand Up @@ -45,6 +45,4 @@ const config: PlaywrightTestConfig<{ toolpadDev: boolean }> = {
use: { ...devices['Desktop Chrome'] },
},
],
};

export default config;
});
Loading