chore(core): Show a warning if N8N_BLOCK_ENV_ACCESS_IN_NODE is not set (#18629)

This commit is contained in:
Tomi Turtiainen
2025-08-21 15:12:04 +03:00
committed by GitHub
parent 9881b9e435
commit b7909196ff
2 changed files with 38 additions and 2 deletions

View File

@@ -18,7 +18,9 @@ describe('DeprecationService', () => {
beforeEach(() => {
// Ignore environment variables coming in from the environment when running
// this test suite.
process.env = {};
process.env = {
N8N_BLOCK_ENV_ACCESS_IN_NODE: 'false',
};
jest.resetAllMocks();
});
@@ -135,7 +137,10 @@ describe('DeprecationService', () => {
const envVar = 'OFFLOAD_MANUAL_EXECUTIONS_TO_WORKERS';
beforeEach(() => {
process.env = { N8N_RUNNERS_ENABLED: 'true' };
process.env = {
N8N_RUNNERS_ENABLED: 'true',
N8N_BLOCK_ENV_ACCESS_IN_NODE: 'false',
};
jest.spyOn(config, 'getEnv').mockImplementation((key) => {
if (key === 'executions.mode') return 'queue';
@@ -229,4 +234,29 @@ describe('DeprecationService', () => {
});
});
});
describe('N8N_BLOCK_ENV_ACCESS_IN_NODE', () => {
beforeEach(() => {
process.env = {
N8N_RUNNERS_ENABLED: 'true',
};
jest.resetAllMocks();
});
test('should warn when N8N_BLOCK_ENV_ACCESS_IN_NODE is not set', () => {
delete process.env.N8N_BLOCK_ENV_ACCESS_IN_NODE;
deprecationService.warn();
expect(logger.warn).toHaveBeenCalled();
});
test.each(['false', 'true'])(
'should not warn when N8N_BLOCK_ENV_ACCESS_IN_NODE is %s',
(value) => {
process.env.N8N_BLOCK_ENV_ACCESS_IN_NODE = value;
deprecationService.warn();
expect(logger.warn).not.toHaveBeenCalled();
},
);
});
});

View File

@@ -103,6 +103,12 @@ export class DeprecationService {
'n8n does not support `own` mode since May 2023. Please remove this environment variable to allow n8n to start. If you need the isolation and performance gains, please consider queue mode: https://docs.n8n.io/hosting/scaling/queue-mode/',
checkValue: (value: string) => value === 'own',
},
{
envVar: 'N8N_BLOCK_ENV_ACCESS_IN_NODE',
message:
'The default value of N8N_BLOCK_ENV_ACCESS_IN_NODE will be changed from false to true in a future version. If you need to access environment variables from the Code Node or from expressions, please set N8N_BLOCK_ENV_ACCESS_IN_NODE=false. Learn more: https://docs.n8n.io/hosting/configuration/environment-variables/security/',
checkValue: (value: string | undefined) => value === undefined || value === '',
},
];
/** Runtime state of deprecation-related env vars. */