Skip to content

Commit c127846

Browse files
authored
feat(core): Allow specifying Content-Security-Policy-Report-Only (#15805)
1 parent e860dd6 commit c127846

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

packages/@n8n/config/src/configs/security.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,10 @@ export class SecurityConfig {
3232
// TODO: create a new type that parses and validates this string into a strongly-typed object
3333
@Env('N8N_CONTENT_SECURITY_POLICY')
3434
contentSecurityPolicy: string = '{}';
35+
36+
/**
37+
* Whether to set the `Content-Security-Policy-Report-Only` header instead of `Content-Security-Policy`.
38+
*/
39+
@Env('N8N_CONTENT_SECURITY_POLICY_REPORT_ONLY')
40+
contentSecurityPolicyReportOnly: boolean = false;
3541
}

packages/@n8n/config/test/config.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ describe('GlobalConfig', () => {
272272
blockFileAccessToN8nFiles: true,
273273
daysAbandonedWorkflow: 90,
274274
contentSecurityPolicy: '{}',
275+
contentSecurityPolicyReportOnly: false,
275276
},
276277
executions: {
277278
pruneData: true,

packages/cli/src/server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,13 @@ export class Server extends AbstractServer {
354354
errorMessage: 'The contentSecurityPolicy is not valid JSON.',
355355
},
356356
);
357+
const cspReportOnly = Container.get(SecurityConfig).contentSecurityPolicyReportOnly;
357358
const securityHeadersMiddleware = helmet({
358359
contentSecurityPolicy: isEmpty(cspDirectives)
359360
? false
360361
: {
361362
useDefaults: false,
363+
reportOnly: cspReportOnly,
362364
directives: {
363365
...cspDirectives,
364366
},

0 commit comments

Comments
 (0)