Deno (N5)
Ready
The hub proposes this hook for the containers it fits, and nothing changes until a player approves the proposal (Hook proposals). The cheat sheet has the steps by hand.
For services running on Deno 2: Deno.serve applications (plain, or frameworks the service starts with Deno.serve, e.g. Hono's Deno.serve(app.fetch)) and npm frameworks running on Deno's node:http. Services started with deno serve are not covered (see Known gaps). A preload loads vulnboxd's core through Deno.dlopen, installs the N1 hooks for Deno's Node-compatible modules and wraps Deno's own APIs. It gets in compose-only on Deno ≥ 2.4 (--preload plus two permissions in the command) or with a source change of one import line on older 2.x.
Covers
| Versions | |
|---|---|
| Deno | 2.4+ with --preload (samples: 2.7.14); 2.0–2.3 with the import line (sample: 2.1.4) |
| C library | Deno's official builds are glibc (samples: Debian) |
| Servers | Deno.serve (handler, options.handler, (options, handler)), WebSockets via Deno.upgradeWebSocket; node:http on Deno |
| APIs | Deno.Command (spawn, output, outputSync), Deno.connect, Deno.connectTls, sync file APIs; through N1: node:child_process, node:fs, node:net |
| Not covered | deno serve (declarative export default { fetch }), see Known gaps |
What the kernel already links without a hook: nothing — Deno serves every request on its JavaScript thread.
How it gets in
On a developer machine: Deno does not run TypeScript from node_modules, so the npm package vbxtrace does not serve Deno; use the hook directory from vulnboxctl hooks install-local: deno run --preload ~/.local/share/vulnboxd/trace/deno/register.ts --allow-ffi --allow-read ...; see Local development.
Compose-only, Deno ≥ 2.4 (template hooks/node/n5/proposals/compose-preload-command.toml):
services:
<service>:
+ volumes:
+ - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro
- command: ["deno", "run", "--allow-net", "main.ts"]
+ command: ["deno", "run", "--preload", "/opt/vbxtrace/deno/register.ts",
+ "--allow-ffi=/opt/vbxtrace", "--allow-read=/opt/vbxtrace", "--allow-env=VBXTRACE",
+ "--allow-net", "main.ts"]Source change, any Deno 2.x (template source-import.toml, example proposals/deno-import.diff): the same mount and permissions, and one line at the top of the entry module:
+import "/opt/vbxtrace/deno/register.ts";
import { Hono } from "jsr:@hono/hono";Permissions — what the hook needs and why:
| Permission | Why | Without it |
|---|---|---|
--allow-ffi=/opt/vbxtrace | load the core with Deno.dlopen | the hook does nothing (no prompt, no error) |
--allow-read=/opt/vbxtrace | read the shared binding files in /opt/vbxtrace/node | the hook does nothing |
--allow-env=VBXTRACE | read the VBXTRACE=0 off switch | the switch can't be read and counts as unset |
With -A/--allow-all none of them are added. They widen what the service may do only to reading and loading the hook directory. The hub proposes N5 when it detects deno.json/deno.jsonc/deno.lock, a denoland/deno image, or a deno run command; the --preload variant only when the Deno version is ≥ 2.4 (--preload does not exist before: absent in the 2.0.0 and 2.3.0 release binaries, present in 2.4.0, 2.5.0 and later).
What register.ts does: checks the permissions without prompting, loads the core with Deno.dlopen, loads N1's binding (/opt/vbxtrace/node/vbxtrace.js, CommonJS — through a minimal CommonJS loader of its own, because Deno before 2.9 loads type: commonjs .js files as ES modules), runs N1's register.js and wraps Deno's APIs.
What it records
| Event | Emitted from | Join key |
|---|---|---|
request_begin | a Deno.serve handler, before it runs; protocol websocket when the request asks for an upgrade, else http1 | local port (server.addr.port), peer address and port (info.remoteAddr), request index unknown (see below) |
request_end | when info.completed settles (the response was fully sent; a streamed body included), with the Response's status, 0 on failure; a WebSocket upgrade (101) ends at the handshake | context id |
request_begin / request_end | node:http servers on Deno: N1's Server.prototype.emit('request') path; Deno keeps one req.socket per connection, so the index is exact | as N1 |
spawned | Deno.Command.prototype.spawn (after it returns, child.pid); node:child_process async children through N1 | child pid |
context_enter / context_exit | around Deno.Command output() (it starts the child synchronously inside the call, through Deno's internals, before returning its promise) and outputSync(), the sync file APIs (openSync, createSync, writeFileSync, writeTextFileSync, readFileSync, readTextFileSync, copyFileSync, truncateSync) and N1's sync calls | thread |
connected | Deno.connect, Deno.connectTls (once connected: conn.localAddr.port); node:net through N1 | local port |
opened | node:fs openSync/open through N1 — only on Deno ≥ 2.7.12 | pid + fd |
Request index on Deno.serve: unknown. Deno.serve exposes no connection identity, so the binding passes VBX_REQUEST_INDEX_UNKNOWN (never a guess); the sensor links such requests only through other exact facts (its own accept events), or not at all. node:http on Deno gets exact indexes.
File descriptors. Deno's own file API exposes no fd (Deno.FsFile has a resource id), so its sync calls are bracketed instead. Deno's node:fs hands out real OS file descriptors only from 2.7.12 (verified: 2.0.0–2.7.11 return resource ids — e.g. 3 pointing at an epoll fd —, 2.7.12, 2.7.13, 2.7.14 and 2.9.7 real fds); before that node:fs openSync is bracketed instead of reported with an fd.
Context following
AsyncLocalStorage from node:async_hooks. Each Deno.serve handler runs inside its request's context; every promise, timer and callback it starts carries it — including the WebSocket's onmessage handlers set up in the handler (the sample checks a file opened from onmessage). The handler is wrapped in a copy of the options (same prototype and properties); the service's object is never modified.
Known gaps
deno serve(an entry module withexport default { fetch }started withdeno serve): Deno starts it through an internal server function, notDeno.serve, so its requests are not reported (checked on Deno 2.9.7 with--preload). Start the server withDeno.serve(...)in the entry module instead.- Async file APIs (
Deno.open,Deno.writeTextFile,Deno.readFile, …): they run on Deno's blocking thread pool and expose no fd — not reported. Asyncnode:fson Deno (fs.writeFile, …) is Deno's own implementation and does not go through the exportedfs.open— not reported either. - ES module named imports of Node builtins (
import { openSync } from "node:fs") are snapshots in Deno, so they don't see N1's wrappers;import fs from "node:fs"/fs.openSync(...)does. - Outgoing
fetch: native, noconnected.Deno.connectandnode:netare reported. Deno.serverequest indexes are unknown (above).- Deno before 2.4 has no
--preload: source change only.
Safety
- Wrapped:
Deno.serve(copies options; wraps the handler),Deno.Command.prototype.spawn,.output,.outputSync,Deno.connect,Deno.connectTls, the sync file APIs listed above; plus N1's wrappers. The handler is called with the samethisand arguments and its result is returned unchanged; exceptions propagate.Deno.connect/connectTlsreturn an equivalent promise (same connection or rejection, a constant few microtask ticks later) — only while a tracer is attached and a request is current. - Without the FFI permission for the core, the hook loads nothing and wraps nothing.
- Same failure behaviour as N1: every core call guarded, off after 5 internal errors,
VBXTRACE=0switches it off (with--allow-env=VBXTRACE), nothing but oneenabled()call while no tracer is attached;VBXTRACE_CHAOS=1makes every core event throw inside the guards. - Overhead: not measured yet; it will be measured in the performance phase.
Verified (hooks/run-samples.sh node --package n5, Deno on Debian):
| Sample | Deno | Way in, permissions | events | chaos | baseline |
|---|---|---|---|---|---|
serve | 2.7.14 | --preload, least privilege (--allow-net=127.0.0.1 --allow-run=/bin/true --allow-write=/tmp) plus the hook's permissions | 29 events match: Deno.serve, output(), outputSync(), node:fs openSync, Deno.connect, writeTextFileSync in a streamed body and after a JSON body, a WebSocket message | byte-identical | byte-identical |
node-http | 2.7.14 | --preload, -A | 21 events match: node:http on Deno with exact keep-alive indexes, execFile, execFileSync, http.get, openSync; fs.writeFile produces no event (gap above) | byte-identical | byte-identical |
import-2.1 | 2.1.4 | the import line, least privilege plus the hook's permissions | 31 events match: as serve, with node:fs openSync bracketed (resource ids before 2.7.12) | byte-identical | byte-identical |
The serve and import-2.1 samples also grant --allow-env=VBXTRACE_CHAOS so the harness's chaos mode reaches the hook. Deno sends a Date header on every response; the sample drivers drop that one header before comparing.
Turning it off
Set VBXTRACE=0 in the service's environment (needs --allow-env=VBXTRACE, which the proposal adds) and restart it, or revert the change that added the hook (the --preload and permission arguments or the import line, and the mount); vulnboxd's rollback covers a hook that breaks a service.
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?
grep vbxtrace /proc/<pid>/maps; from inside the serviceglobalThis[Symbol.for('vbxtrace.node.v1')]?.status()→{ loaded: true, core: 'deno:ffi', … }. - Which links did a flow get? The hub shows each link's method; this package's are
hook:N5. - Deno refuses
--preload: Deno older than 2.4 — use the import line. - No events: missing
--allow-ffi/--allow-readfor/opt/vbxtrace(the hook stays silent then),deno serveinstead ofDeno.serve, or the mount missing.