From a9d11ccb2e23431ec12b15f8ba7c42a05b378a11 Mon Sep 17 00:00:00 2001 From: John Jahn Date: Tue, 10 Nov 2026 10:32:27 -0500 Subject: [PATCH] fix(plugins): grant plugin children the network on Node 25 and newer From Node 25 the permission model covers the network, so a plugin child forked with --permission and no --allow-net gets ERR_ACCESS_DENIED on every lookup and connect, and no plugin can reach a host it was granted. Node 24 is unaffected and rejects the flag as a bad option, so it is passed only where process.allowedNodeEnvironmentFlags knows it. Which hosts a plugin may reach is still decided by the egress guard inside the child. Fixes #3045 --- server/src/nest/plugins/paths.ts | 19 +++++++++++++++++++ .../tests/unit/plugins/protocol-paths.test.ts | 14 ++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/server/src/nest/plugins/paths.ts b/server/src/nest/plugins/paths.ts index 51e849841..93945f73e 100644 --- a/server/src/nest/plugins/paths.ts +++ b/server/src/nest/plugins/paths.ts @@ -126,6 +126,24 @@ export function serverCodeRoot(): string { return path.resolve(__dirname, '../..'); } +/** + * The network grant for a plugin child, on the Node versions that need one. + * + * Up to Node 24 `--permission` leaves the network alone. From Node 25 it covers the + * network too, and a child started without `--allow-net` gets ERR_ACCESS_DENIED on + * every lookup and connect, so no plugin can reach even a host it was granted (#3045). + * Node 24 exits with "bad option" when given the flag, so it is passed only where + * this Node knows it. + * + * This restores what Node 24 does and widens nothing: which hosts a plugin may reach + * is decided by the egress guard inside the child, from its granted `egress[]`. + */ +export function pluginNetPermissionArgs( + knownFlags: { has(flag: string): boolean } = process.allowedNodeEnvironmentFlags, +): string[] { + return knownFlags.has('--allow-net') ? ['--allow-net'] : []; +} + /** * Node OS-level permission-model flags for a plugin child (#plugins, #2 security * hardening). `--permission` denies filesystem write, child_process, worker @@ -171,5 +189,6 @@ export function pluginPermissionArgs(pluginId: string): string[] { `--allow-fs-read=${path.join(codeRoot, '..', 'package.json')}`, // The plugin's own code, by REAL path (see pluginRealCodeDir). `--allow-fs-read=${pluginRealCodeDir(pluginId)}`, + ...pluginNetPermissionArgs(), ]; } diff --git a/server/tests/unit/plugins/protocol-paths.test.ts b/server/tests/unit/plugins/protocol-paths.test.ts index ffb76de06..13a1de712 100644 --- a/server/tests/unit/plugins/protocol-paths.test.ts +++ b/server/tests/unit/plugins/protocol-paths.test.ts @@ -11,6 +11,7 @@ import { resolveChildEntry, serverCodeRoot, pluginPermissionArgs, + pluginNetPermissionArgs, pluginRealCodeDir, ensurePluginModuleType, } from '../../../src/nest/plugins/paths'; @@ -90,6 +91,19 @@ describe('paths', () => { expect(serverCodeRoot()).not.toContain(`${require('node:path').sep}data`); }); + // From Node 25 the permission model covers the network, and a child without the + // grant cannot reach any host (#3045). Node 24 refuses the flag as a bad option. + it('grants the network only on a Node that knows --allow-net', () => { + expect(pluginNetPermissionArgs(new Set(['--permission', '--allow-net']))).toEqual(['--allow-net']); + expect(pluginNetPermissionArgs(new Set(['--permission']))).toEqual([]); + }); + + it('passes the network grant to a plugin child exactly when this Node needs it', () => { + delete process.env.TREK_PLUGIN_PERMISSIONS; + const args = pluginPermissionArgs('flight-tracker'); + expect(args.includes('--allow-net')).toBe(process.allowedNodeEnvironmentFlags.has('--allow-net')); + }); + it('lets an operator opt out of the permission model', () => { process.env.TREK_PLUGIN_PERMISSIONS = 'off'; expect(pluginPermissionArgs('flight-tracker')).toEqual([]);