Skip to content

Commit

Permalink
chore: extend CSP based on audit suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
dmijatovic committed Sep 5, 2023
1 parent 033a498 commit 1f81bd2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions frontend/utils/contentSecurityPolicy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ beforeEach(() => {
it('sets content security policy header for development', () => {
const nonce = setContentSecurityPolicyHeader(res as any)
const policyName = 'Content-Security-Policy-Report-Only'
const policyText = `default-src 'self'; style-src 'self' 'unsafe-inline'; connect-src 'self' https://*; font-src 'self' https://fonts.gstatic.com; img-src 'self' data: https://*; base-uri 'none'; object-src 'none'; script-src 'nonce-${nonce}' 'strict-dynamic' 'unsafe-eval' 'unsafe-inline'`
const policyText = `default-src 'self'; style-src 'self' 'unsafe-inline'; connect-src 'self' https://*; font-src 'self' https://fonts.gstatic.com; img-src 'self' data: https://*; base-uri 'none'; object-src 'none'; script-src 'nonce-${nonce}' 'strict-dynamic' 'unsafe-eval' 'unsafe-inline' https:`

expect(mockSetHeader).toBeCalledTimes(1)
// const calledWith = mockSetHeader
Expand All @@ -32,7 +32,7 @@ it('sets content security policy header for production', () => {
process.env.MATOMO_URL = 'https://mamtomo.com/test-url'
const nonce = setContentSecurityPolicyHeader(res as any)
const policyName = 'Content-Security-Policy'
const policyText = `default-src 'self'; style-src 'self' 'unsafe-inline'; connect-src 'self' https://*; font-src 'self' https://fonts.gstatic.com; img-src 'self' data: https://*; base-uri 'none'; object-src 'none'; script-src 'nonce-${nonce}' 'strict-dynamic' https://mamtomo.com/test-url 'unsafe-inline'`
const policyText = `default-src 'self'; style-src 'self' 'unsafe-inline'; connect-src 'self' https://*; font-src 'self' https://fonts.gstatic.com; img-src 'self' data: https://*; base-uri 'none'; object-src 'none'; script-src 'nonce-${nonce}' 'strict-dynamic' https://mamtomo.com/test-url 'unsafe-inline' https:`


// "default-src 'self'; style-src 'self' 'unsafe-inline'; connect-src 'self' https://*; font-src 'self' https://fonts.gstatic.com; img-src 'self' data: https://*; base-uri 'none'; object-src 'none'; script-src 'self' 'unsafe-inline' https://mamtomo.com/test-url 'nonce-b771ce36-a563-4e69-b969-0a758ac0762e'"
Expand Down
2 changes: 1 addition & 1 deletion frontend/utils/contentSecurityPolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function devScript() {
export function nonceContentSecurity() {
const nonce = crypto.randomUUID()
// append default, monitoring scripts and dev script
let scriptSrc = `script-src 'nonce-${nonce}' 'strict-dynamic'${monitoringScripts()}${devScript()} 'unsafe-inline'`
let scriptSrc = `script-src 'nonce-${nonce}' 'strict-dynamic'${monitoringScripts()}${devScript()} 'unsafe-inline' https:`
// combine shared policies with script policy
const policy = `${sharedPolicy.replace(/\s{2,}/g, ' ').trim()} ${scriptSrc}`
// console.log('shaContentSecurity...', policy)
Expand Down

0 comments on commit 1f81bd2

Please sign in to comment.