mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 07:30:04 +00:00
fix(plugins): close the UDP + DNS egress hole in the network guard
The egress guard only wrapped fetch and net.Socket.connect, so TCP and HTTP were contained but two channels stayed wide open: a plugin could send data out over UDP (node:dgram) or tunnel it inside DNS queries (dns.resolveTxt & friends) to any host it never declared. Neither goes through net.Socket.connect, so the allowlist never saw them. Wrap both now against the same declared-host allowlist: - dgram send/connect: the explicit destination is allowlisted and private-IP-checked like a TCP connect (a null address keeps the connected/localhost default, which the connect wrapper already vetted). - the dns resolver family (module fns, dns.promises, Resolver.prototype): a forward lookup for an undeclared name is refused, which kills DNS tunnelling even when no socket is ever opened. A plugin with no declared egress now really has no way out.
This commit is contained in:
@@ -5,7 +5,9 @@
|
||||
*/
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import net from 'node:net';
|
||||
import { isBlockedIp, makeHostAllow, classifyConnect } from '../../../src/nest/plugins/runtime/egress-policy';
|
||||
import {
|
||||
isBlockedIp, makeHostAllow, classifyConnect, dgramSendTarget, dgramConnectTarget,
|
||||
} from '../../../src/nest/plugins/runtime/egress-policy';
|
||||
|
||||
const isIP = (s: string) => net.isIP(s) !== 0;
|
||||
|
||||
@@ -69,3 +71,31 @@ describe('classifyConnect', () => {
|
||||
expect(classifyConnect([8080], isIP)).toEqual({ kind: 'hostname', host: 'localhost' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('dgramSendTarget', () => {
|
||||
const msg = Buffer.from('x');
|
||||
it('reads the address from send(msg, port, address)', () => {
|
||||
expect(dgramSendTarget([msg, 53, 'attacker.com'])).toBe('attacker.com');
|
||||
});
|
||||
it('reads the address from the send(msg, offset, length, port, address) form', () => {
|
||||
expect(dgramSendTarget([msg, 0, 1, 53, 'attacker.com'])).toBe('attacker.com');
|
||||
});
|
||||
it('is null when no explicit address is given (connected / localhost default)', () => {
|
||||
expect(dgramSendTarget([msg, 53])).toBeNull();
|
||||
expect(dgramSendTarget([msg])).toBeNull();
|
||||
expect(dgramSendTarget([msg, 0, 1, 53])).toBeNull();
|
||||
});
|
||||
it('ignores a trailing callback in the address slot', () => {
|
||||
expect(dgramSendTarget([msg, 53, () => {}])).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('dgramConnectTarget', () => {
|
||||
it('reads the address from connect(port, address)', () => {
|
||||
expect(dgramConnectTarget([53, 'attacker.com'])).toBe('attacker.com');
|
||||
});
|
||||
it('is null for connect(port) or connect(port, cb)', () => {
|
||||
expect(dgramConnectTarget([53])).toBeNull();
|
||||
expect(dgramConnectTarget([53, () => {}])).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user