Skip to content

Commit

Permalink
Fix nonce filter and csp test (#2508)
Browse files Browse the repository at this point in the history
  • Loading branch information
wizardlyhel authored Sep 9, 2024
1 parent d633e49 commit ed2657b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
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).toMatchInlineSnapshot(
`"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' https://cdn.shopify.com https://shopify.com 'nonce-somenonce'; 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,
).toMatchInlineSnapshot(
`"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' https://cdn.shopify.com https://shopify.com 'nonce-somenonce'; 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 @@ -41,7 +41,7 @@ describe('createContentSecurityPolicy', () => {
},
}).header,
).toMatchInlineSnapshot(
`"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 https://checkout.myshopify.com https://test.myshopify.com"`,
`"base-uri 'self'; default-src 'self' https://cdn.shopify.com https://shopify.com 'nonce-somenonce'; frame-ancestors 'none'; style-src 'self' 'unsafe-inline' https://cdn.shopify.com; connect-src 'self' https://monorail-edge.shopifysvc.com https://checkout.myshopify.com https://test.myshopify.com"`,
);
});

Expand Down
4 changes: 2 additions & 2 deletions packages/hydrogen/src/csp/csp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ function createCSPHeader(
// shouldn't use our utilities and just manually create their CSP.
if (combinedDirectives.scriptSrc instanceof Array) {
combinedDirectives.scriptSrc = [
...combinedDirectives.scriptSrc.filter((ss) => !ss.startsWith('nonce')),
...combinedDirectives.scriptSrc.filter((ss) => !ss.startsWith(`'nonce`)),
nonceString,
];
} else if (combinedDirectives.defaultSrc instanceof Array) {
combinedDirectives.defaultSrc = [
...combinedDirectives.defaultSrc.filter((ss) => !ss.startsWith('nonce')),
...combinedDirectives.defaultSrc.filter((ss) => !ss.startsWith(`'nonce`)),
nonceString,
];
}
Expand Down

0 comments on commit ed2657b

Please sign in to comment.