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
This commit is contained in:
John Jahn
2026-11-10 10:32:27 -05:00
committed by Maurice
parent 848e3f90e1
commit a9d11ccb2e
2 changed files with 33 additions and 0 deletions
+19
View File
@@ -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(),
];
}
@@ -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([]);