WebSockets and raw TCP/UDP in Node (N3)
Ready
This package comes with the N1 hook: when the hub proposes N1 for a container, this is part of it, and nothing changes until a player approves the proposal (Hook proposals). The cheat sheet has the steps by hand.
For Node services that are not plain HTTP: WebSocket servers (ws, Socket.IO), line or binary protocols on net.createServer / tls.createServer, and UDP services on dgram. It is a part of the Node hook that N1's register.js loads automatically from /opt/vbxtrace/node/n3, so it gets in with the same compose-only change (mount plus NODE_OPTIONS=--require …); there is nothing extra to configure.
Covers
| Versions | |
|---|---|
| Node.js | as N1: 16–24 (samples run on Node 22) |
| WebSockets | ws 8 (tested 8.18.3), Socket.IO 4 (tested 4.8.1, websocket transport), any 'upgrade' listener |
| Raw TCP / TLS | net.createServer, tls.createServer |
| UDP | dgram sockets (servers: per datagram; clients: first send) |
| Not covered | uWebSockets.js (see Known gaps) |
Socket.IO's long-polling transport is ordinary HTTP requests, which N1 already reports.
What the kernel already links without a hook: nothing for these servers in Node — every session runs on the one event-loop thread.
How it gets in
From a registry (local development, or a build with network; the same release as the hook directory): npm install vbxtrace@1.0.0, then node --require vbxtrace/register app.js (ESM: --import vbxtrace/register.mjs); see Local development.
Exactly as N1: the hub proposes N1's template (hooks/node/n1/proposals/compose.toml); N3 has no template of its own because nothing about it is configurable. Detection adds ws and socket.io to N1's dependency list.
services:
<service>:
+ volumes:
+ - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro
+ environment:
+ NODE_OPTIONS: --require /opt/vbxtrace/node/register.jsWhat it records
| Event | Emitted from | Join key |
|---|---|---|
request_begin (protocol websocket, or unknown for other upgrades) | the 'upgrade' event of an http/https server (a guarded wrap of Server.prototype.emit for that event only: Node publishes no diagnostics channel for upgrades) | the upgraded socket's local port, peer address and port, request index on the connection (the same per-connection count N1 uses, so an upgrade after keep-alive requests gets the next index) |
request_begin (protocol raw, index 0) | net.Server 'connection' (TCP) or tls.Server 'secureConnection' (TLS, after the handshake); http, https and http2 servers are skipped | the accepted socket's local port, peer address and port |
request_begin (protocol raw, index 0) | a dgram socket's 'message' (one request per datagram) | the socket's local port, the datagram's source address and port |
request_end (status 0) | the session socket's 'close'; for a datagram, right after its 'message' handlers returned | context id |
connected (transport udp) | the first send() of a dgram socket made during a request (after its implicit bind, with the local port); not for sockets that receive datagrams themselves (a server's replies) | local port |
spawned, opened, connected (tcp), context_enter/context_exit | N1's hooks, inside the session's context | as N1 |
Why a wrap of net.Server.prototype.emit('connection') rather than the net.server.socket channel: enterWith in a channel subscriber would leave the context on the listening socket's async resource; running the 'connection' listeners inside the session's context scopes it exactly.
Context following
A session's context is entered around its 'connection'/'upgrade' listeners (AsyncLocalStorage), and the session socket is bound: every later event of that socket ('data', 'end', 'close', and the ws/Socket.IO frames parsed from them) runs in the session's context. Everything the handlers start carries it. A datagram's context covers its 'message' handlers and whatever async work they start (e.g. an fs.writeFile callback after request_end still reports under the datagram's context).
Known gaps
- uWebSockets.js is not hooked: its HTTP and WebSocket handling is native (µSockets), outside
node:http/net, and it exposes no connection identity, so no exact request index can be given. Its requests are not linked. - A WebSocket session is one request: individual messages are not separate requests, and
request_endcomes when the connection closes. - Socket.IO: only the websocket transport was sampled; long-polling requests are N1's (plain HTTP).
Safety
- Wrapped:
http.Server.prototype.emitandhttps.Server.prototype.emit(only the'upgrade'event is acted on),net.Server.prototype.emit('connection'/'secureConnection'),net.Socket.prototype.emit(binding owned sockets' events to their context),dgram.Socket.prototype.emit('message') anddgram.Socket.prototype.send. Each calls the original with the samethisand arguments and returns its result; exceptions pass through unchanged. One'close'listener is added to each session socket (and one'listening'listener to an unbound UDP socket on its first send during a request). - Same failure behaviour as N1: every core call guarded, off after 5 internal errors,
VBXTRACE=0switches the whole Node hook off, nothing but oneenabled()call while no tracer is attached. - Overhead: not measured yet; it will be measured in the performance phase.
Verified (hooks/run-samples.sh node --package n3, Node 22 on Alpine):
| Sample | What it does | events | chaos | baseline |
|---|---|---|---|---|
raw | a TCP session (spawn, file write, outgoing TCP and UDP), a TLS session (file write), two UDP datagrams | 14 events match | byte-identical | byte-identical |
ws | ws WebSocketServer sharing a node:http server: spawn, file write and connect from message handlers, plus a plain GET | 7 events match | byte-identical | byte-identical |
socketio | Socket.IO 4 events with acks: spawn, file write, connect | 5 events match | byte-identical | byte-identical |
Turning it off
Set VBXTRACE=0 in the service's environment and restart it, or revert the change that added the hook; vulnboxd's rollback covers a hook that breaks a service. N3 has no switch of its own: it is part of the Node hook.
Troubleshooting
- Are the probes there?
readelf -n /usr/local/lib/vulnboxd/trace/libvbxtrace-x86_64.solists them;sudo bpftrace -l 'usdt:/usr/local/lib/vulnboxd/trace/libvbxtrace-x86_64.so:*'too. - Is the hook loaded? As N1:
grep vbxtrace /proc/<pid>/maps. - Which links did a flow get? The hub shows each link's method; this package's are
hook:N3. - A WebSocket server shows no session: does it attach to an
http/httpsserver's'upgrade'(aswswith{ server }or{ port }and Socket.IO do)? uWebSockets.js is not supported.