Skip to content

Commit

Permalink
Fix the default CSP directive for frameAncestors (#1883)
Browse files Browse the repository at this point in the history
Resolves #1783
  • Loading branch information
blittle authored Mar 21, 2024
1 parent adb37c3 commit 9e89921
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/smooth-cooks-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/hydrogen': patch
---

Fix default content secuirty policy directive for `frameAncestors`. Resolves [#1783](https://github.com/Shopify/hydrogen/issues/1793)
6 changes: 3 additions & 3 deletions packages/hydrogen/src/csp/csp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ afterEach(() => {
describe('createContentSecurityPolicy', () => {
it('creates default policy', () => {
expect(createContentSecurityPolicy().header).toBe(
`base-uri 'self'; default-src 'self' 'nonce-somenonce' https://cdn.shopify.com https://shopify.com; frame-ancestors none; style-src 'self' 'unsafe-inline' https://cdn.shopify.com; connect-src 'self' https://monorail-edge.shopifysvc.com`,
`base-uri 'self'; default-src 'self' 'nonce-somenonce' https://cdn.shopify.com https://shopify.com; frame-ancestors 'none'; style-src 'self' 'unsafe-inline' https://cdn.shopify.com; connect-src 'self' https://monorail-edge.shopifysvc.com`,
);
});

Expand All @@ -28,7 +28,7 @@ describe('createContentSecurityPolicy', () => {
styleSrc: ['https://some-custom-css.cdn'],
}).header,
).toBe(
`base-uri 'self'; default-src 'self' 'nonce-somenonce' https://cdn.shopify.com https://shopify.com; frame-ancestors none; style-src https://some-custom-css.cdn 'self' 'unsafe-inline' https://cdn.shopify.com; connect-src 'self' https://monorail-edge.shopifysvc.com`,
`base-uri 'self'; default-src 'self' 'nonce-somenonce' https://cdn.shopify.com https://shopify.com; frame-ancestors 'none'; style-src https://some-custom-css.cdn 'self' 'unsafe-inline' https://cdn.shopify.com; connect-src 'self' https://monorail-edge.shopifysvc.com`,
);
});

Expand All @@ -38,7 +38,7 @@ describe('createContentSecurityPolicy', () => {
scriptSrc: ['https://some-custom-css.cdn'],
}).header,
).toBe(
`base-uri 'self'; default-src 'self' 'nonce-somenonce' https://cdn.shopify.com https://shopify.com; frame-ancestors none; style-src 'self' 'unsafe-inline' https://cdn.shopify.com; connect-src 'self' https://monorail-edge.shopifysvc.com; script-src https://some-custom-css.cdn 'nonce-somenonce'`,
`base-uri 'self'; default-src 'self' 'nonce-somenonce' https://cdn.shopify.com https://shopify.com; frame-ancestors 'none'; style-src 'self' 'unsafe-inline' https://cdn.shopify.com; connect-src 'self' https://monorail-edge.shopifysvc.com; script-src https://some-custom-css.cdn 'nonce-somenonce'`,
);
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/hydrogen/src/csp/csp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function createCSPHeader(
const defaultDirectives: Record<string, string[] | string | boolean> = {
baseUri: ["'self'"],
defaultSrc,
frameAncestors: ['none'],
frameAncestors: ["'none'"],
styleSrc,
connectSrc,
};
Expand Down

0 comments on commit 9e89921

Please sign in to comment.