mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat(core): Allow specifying Content-Security-Policy-Report-Only (#15805)
This commit is contained in:
@@ -32,4 +32,10 @@ export class SecurityConfig {
|
|||||||
// TODO: create a new type that parses and validates this string into a strongly-typed object
|
// TODO: create a new type that parses and validates this string into a strongly-typed object
|
||||||
@Env('N8N_CONTENT_SECURITY_POLICY')
|
@Env('N8N_CONTENT_SECURITY_POLICY')
|
||||||
contentSecurityPolicy: string = '{}';
|
contentSecurityPolicy: string = '{}';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to set the `Content-Security-Policy-Report-Only` header instead of `Content-Security-Policy`.
|
||||||
|
*/
|
||||||
|
@Env('N8N_CONTENT_SECURITY_POLICY_REPORT_ONLY')
|
||||||
|
contentSecurityPolicyReportOnly: boolean = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -272,6 +272,7 @@ describe('GlobalConfig', () => {
|
|||||||
blockFileAccessToN8nFiles: true,
|
blockFileAccessToN8nFiles: true,
|
||||||
daysAbandonedWorkflow: 90,
|
daysAbandonedWorkflow: 90,
|
||||||
contentSecurityPolicy: '{}',
|
contentSecurityPolicy: '{}',
|
||||||
|
contentSecurityPolicyReportOnly: false,
|
||||||
},
|
},
|
||||||
executions: {
|
executions: {
|
||||||
pruneData: true,
|
pruneData: true,
|
||||||
|
|||||||
@@ -354,11 +354,13 @@ export class Server extends AbstractServer {
|
|||||||
errorMessage: 'The contentSecurityPolicy is not valid JSON.',
|
errorMessage: 'The contentSecurityPolicy is not valid JSON.',
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
const cspReportOnly = Container.get(SecurityConfig).contentSecurityPolicyReportOnly;
|
||||||
const securityHeadersMiddleware = helmet({
|
const securityHeadersMiddleware = helmet({
|
||||||
contentSecurityPolicy: isEmpty(cspDirectives)
|
contentSecurityPolicy: isEmpty(cspDirectives)
|
||||||
? false
|
? false
|
||||||
: {
|
: {
|
||||||
useDefaults: false,
|
useDefaults: false,
|
||||||
|
reportOnly: cspReportOnly,
|
||||||
directives: {
|
directives: {
|
||||||
...cspDirectives,
|
...cspDirectives,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user