mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 17:03:15 +00:00
fix(plugins): validate stable egress options
Keep egress comparisons independent of mutable runtime methods and pass the same normalized options to validation and the socket. Restrict process signaling from plugin workers and disable signal-initiated debugging on standard server starts.
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
isBlockedIp,
|
||||
makeHostAllow,
|
||||
classifyConnect,
|
||||
snapshotConnectArgs,
|
||||
unwrapConnectArgs,
|
||||
dgramSendTarget,
|
||||
dgramConnectTarget,
|
||||
@@ -63,6 +64,7 @@ describe('isBlockedIp', () => {
|
||||
'100.63.0.1',
|
||||
'100.128.0.1',
|
||||
'2606:4700::1111',
|
||||
'2606:4700:0000:0000:0000:0000:0000:1111',
|
||||
'::ffff:8.8.8.8',
|
||||
// transition addresses to a public IPv4 are legitimate egress, not blocked
|
||||
'64:ff9b::808:808',
|
||||
@@ -70,6 +72,17 @@ describe('isBlockedIp', () => {
|
||||
])('allows public %s', (ip) => {
|
||||
expect(isBlockedIp(ip)).toBe(false);
|
||||
});
|
||||
|
||||
it.each(['word', '2001::x', '2001::1::2', '2001:0:0:0:0:0:0:0:0', '2001::300.1.1.1'])(
|
||||
'rejects invalid addresses as IP literals: %s',
|
||||
(ip) => {
|
||||
expect(isBlockedIp(ip)).toBe(false);
|
||||
},
|
||||
);
|
||||
|
||||
it('classifies a zoned IPv6 address after removing the interface name', () => {
|
||||
expect(isBlockedIp('[fe80::1%eth0]')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('makeHostAllow', () => {
|
||||
@@ -134,6 +147,41 @@ describe('classifyConnect', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('snapshotConnectArgs', () => {
|
||||
it('copies own options and preserves the callback for the normalized overload', () => {
|
||||
const callback = () => {};
|
||||
const original = { host: 'api.example.com', port: 443, family: 4 };
|
||||
const [copy, actualCallback] = snapshotConnectArgs([[original, callback]]);
|
||||
expect(copy).toEqual(original);
|
||||
expect(copy).not.toBe(original);
|
||||
expect(Object.getPrototypeOf(copy)).toBeNull();
|
||||
expect(actualCallback).toBe(callback);
|
||||
});
|
||||
|
||||
it('normalizes positional TCP and local socket overloads', () => {
|
||||
const callback = () => {};
|
||||
expect(snapshotConnectArgs([443, 'api.example.com', callback])).toEqual([
|
||||
{ port: 443, host: 'api.example.com' },
|
||||
callback,
|
||||
]);
|
||||
expect(snapshotConnectArgs([443, callback])).toEqual([{ port: 443 }, callback]);
|
||||
expect(snapshotConnectArgs(['/run/app.sock', callback])).toEqual([{ path: '/run/app.sock' }, callback]);
|
||||
});
|
||||
|
||||
it('rejects option accessors without invoking them', () => {
|
||||
const options = {
|
||||
get host() {
|
||||
throw new Error('host accessor was called');
|
||||
},
|
||||
};
|
||||
expect(() => snapshotConnectArgs([options])).toThrow('socket options must use data properties');
|
||||
});
|
||||
|
||||
it.each([{ path: false }, { host: 2 }, { port: {} }])('rejects non-primitive destinations', (options) => {
|
||||
expect(() => snapshotConnectArgs([options])).toThrow('invalid socket');
|
||||
});
|
||||
});
|
||||
|
||||
describe('dgramSendTarget', () => {
|
||||
const msg = Buffer.from('x');
|
||||
it('reads the address from send(msg, port, address)', () => {
|
||||
|
||||
Reference in New Issue
Block a user