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
|
||||
@Env('N8N_CONTENT_SECURITY_POLICY')
|
||||
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,
|
||||
daysAbandonedWorkflow: 90,
|
||||
contentSecurityPolicy: '{}',
|
||||
contentSecurityPolicyReportOnly: false,
|
||||
},
|
||||
executions: {
|
||||
pruneData: true,
|
||||
|
||||
@@ -354,11 +354,13 @@ export class Server extends AbstractServer {
|
||||
errorMessage: 'The contentSecurityPolicy is not valid JSON.',
|
||||
},
|
||||
);
|
||||
const cspReportOnly = Container.get(SecurityConfig).contentSecurityPolicyReportOnly;
|
||||
const securityHeadersMiddleware = helmet({
|
||||
contentSecurityPolicy: isEmpty(cspDirectives)
|
||||
? false
|
||||
: {
|
||||
useDefaults: false,
|
||||
reportOnly: cspReportOnly,
|
||||
directives: {
|
||||
...cspDirectives,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user