Skip to content

Commit

Permalink
Extract content-security-policy generation logic, add support for Mak…
Browse files Browse the repository at this point in the history
…eswift builder (#1159)
  • Loading branch information
bookernath authored Jul 26, 2024
1 parent e37cd50 commit 6f46f00
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 11 deletions.
36 changes: 36 additions & 0 deletions core/lib/content-security-policy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// @ts-check
const makeswiftEnabled = !!process.env.MAKESWIFT_SITE_API_KEY;

const makeswiftBaseUrl = process.env.MAKESWIFT_BASE_URL || 'https://app.makeswift.com';

const frameAncestors = makeswiftEnabled ? makeswiftBaseUrl : 'none';

const builder = require('content-security-policy-builder');

// customize the directives as needed
const cspHeader = builder({
directives: {
baseUri: ['self'],
formAction: ['self'],
frameAncestors: [frameAncestors],
// defaultSrc: ['self'],
// scriptSrc: ['self'],
// styleSrc: ['self'],
// imgSrc: ['self'],
// connectSrc: ['self'],
// fontSrc: ['self'],
// objectSrc: ['none'],
// mediaSrc: ['self'],
// frameSrc: ['self'],
// childSrc: ['self'],
// manifestSrc: ['self'],
// workerSrc: ['self'],
// prefetchSrc: ['self'],
// navigateTo: ['self'],
// reportUri: ['none'],
},
});

module.exports = {
cspHeader,
};
6 changes: 1 addition & 5 deletions core/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ const createNextIntlPlugin = require('next-intl/plugin');

const withNextIntl = createNextIntlPlugin();

const cspHeader = `
base-uri 'self';
form-action 'self';
frame-ancestors 'none';
`;
const { cspHeader } = require('./lib/content-security-policy');

/** @type {import('next').NextConfig} */
const nextConfig = {
Expand Down
1 change: 1 addition & 0 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@vercel/speed-insights": "^1.0.12",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"content-security-policy-builder": "^2.2.0",
"embla-carousel-react": "8.1.6",
"focus-trap-react": "^10.2.3",
"gql.tada": "^1.8.2",
Expand Down
21 changes: 15 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6f46f00

Please sign in to comment.