Skip to content

Node HTTP frameworks (N2) ​

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 web frameworks: Express, Koa, Fastify, Hapi, NestJS, Next.js, Nuxt/Nitro, Restify, Sails, Remix, AdonisJS and the core http2 server. Everything that serves through Node's http/https servers is already covered by N1's request hook — the frameworks need nothing of their own, and N2's samples verify that for each of them, including streamed responses and request bodies parsed by the framework. N2 adds the http2 server (plain and TLS, core and compatibility API), where every stream is a request. It is part of the Node hook that N1's register.js loads from /opt/vbxtrace/node/n2, so it gets in with the same compose-only change.

Covers ​

Versions (sampled)
Node.jsas N1: 16–24 (framework samples run on Node 22, Alpine)
Express4.21.2, 5.1.0
Koa2.16.1 (@koa/router 13.1.0, @koa/bodyparser 5.1.1)
Fastify5.4.0
Hapi21.4.0
NestJS11.1.3 (Express adapter)
Next.js15.3.4 (standalone server)
Nuxt / NitroNuxt 4.6.2 (Nitro node-server preset, nitropack 2.13.5)
Restify11.1.0
Sails1.5.18
http2core server: h2c (compatibility API) and TLS (core stream API)
RemixReact Router 8.4.0 framework mode (Remix's successor), served by react-router-serve
AdonisJS6.21.0 (node ace build, slim starter layout)
Meteornot sampled: needs the Meteor tool and its own build system (about 1 GB); it serves through node:http, so N1's hook applies

What the kernel already links without a hook: nothing — every Node framework serves its requests 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), whose detection already lists the frameworks (express, koa, fastify, @hapi/hapi, @nestjs/core, next, restify, …). N2 has no template of its own because nothing about it is configurable.

diff
 services:
   <service>:
+    volumes:
+      - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro
+    environment:
+      NODE_OPTIONS: --require /opt/vbxtrace/node/register.js

Frameworks with a build step (Next.js, Nuxt, Remix, AdonisJS) need nothing at build time: the hook only acts in the running server process, so the image is built exactly as before.

What it records ​

EventEmitted fromJoin key
request_begin / request_end (HTTP/1.1)N1: http.server.request.start / http.server.response.finish — for every framework on node:http/https; request_end comes when the response is finished, so a streamed (chunked) response ends after its last chunkpeer address and port, request index on the keep-alive connection
request_begin (protocol http2, or grpc when the content-type is application/grpc*)the http2 server's 'stream' event (a guarded wrap of the server prototypes' emit; the compatibility API's 'request' is emitted from inside it)the session socket's local port, peer address and port, request index = the stream's 0-based order on the session
request_end (http2)the stream's 'close', with the :status it sent (0 if none)context id
spawned, opened, connected, context_enter/context_exitN1's hooks, inside the request's contextas N1

Context following ​

N1's AsyncLocalStorage context covers each framework's whole request pipeline: middleware, async handlers, body parsers (which read the body in later socket events — the request and response objects are bound to the request's context), streamed responses and timers. For http2, the 'stream' listeners run inside the stream's context and the stream (plus the compatibility API's request/response objects) is bound to it.

Known gaps ​

  • Framework-internal work is attributed to the request it happens in. Lazy require()s of framework modules during the first requests show up as context_enter/context_exit pairs (readFileSync through Node's module loader); Next.js reads its 404 page through fs.promises (an opened with unknown flags). These are real, correct events; the samples ignore them in their golden files.

Safety ​

  • Wrapped by N2: the http2 server prototypes' emit (only 'stream' and 'request' are acted on; the prototypes are taken from unlistened http2.createServer()/createSecureServer({}) instances, which do no I/O), Http2ServerRequest.prototype.emit, Http2ServerResponse.prototype.emit and the server stream prototype's emit (binding owned objects' events to their context). One 'close' listener is added to each stream. Everything else is N1's.
  • Same failure behaviour as N1: every core call guarded, off after 5 internal errors, VBXTRACE=0 switches the whole Node hook off, nothing but one enabled() 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 n2, Node 22 on Alpine). Each framework sample serves: two requests on one keep-alive connection (indexes 0 and 1, the second a 404), child_process.execFile in a handler, fs.writeFile in an async handler, an outgoing http.get, a streamed response with a file opened between chunks, and a JSON body parsed by the framework followed by a file write.

Sampleeventschaosbaseline
express (4)37 events matchbyte-identicalbyte-identical
express539 events matchbyte-identicalbyte-identical
koa37 events matchbyte-identicalbyte-identical
fastify19 events matchbyte-identicalbyte-identical
hapi19 events matchbyte-identicalbyte-identical
nestjs39 events matchbyte-identicalbyte-identical
nextjs24 events matchbyte-identicalbyte-identical
nuxt35 events matchbyte-identicalbyte-identical
restify19 events matchbyte-identicalbyte-identical
sails37 events matchbyte-identicalbyte-identical
remix23 events matchbyte-identicalbyte-identical
adonis39 events matchbyte-identicalbyte-identical
http230 events match: six streams on one h2c session (indexes 0–5, the last grpc) and six on one TLS sessionbyte-identicalbyte-identical

(Event counts differ by the framework-internal context_enter/context_exit pairs the golden files ignore; the events checked are the same for every framework.)

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. N2 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.so lists 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:N2 (http2) and hook:N1 (everything on node:http).
  • Next.js / Nuxt / Remix started through a process manager or npm start: NODE_OPTIONS reaches the server process through the parent, which loads the hook too (harmlessly). Check the server process's maps, not the parent's.