Hook cheat sheet: Dart
How to add a vulnboxd runtime hook to a Dart service by hand. Find your setup in the table, then follow its block.
- Without source access: only the compose file changes; redeploy. With source access: you change the code or Dockerfile and rebuild.
- Hub automation says how much the hub's proposals do for you. Fully: approve the proposal in the hub; the block is the fallback when it failed. With conditions: the same, when the conditions listed hold. Partly: the hub pushes the compose part, the rest is yours. Not at all: everything is by hand.
/usr/local/lib/vulnboxd/traceis the hook directory vulnboxd installs on the vulnbox. Compose snippets mount it read-only at/opt/vbxtracein the container.- How to check that the hook works and undo it is at the end of the page.
- Runtime hooks explains what a hook does.
Dart
| Setup | Use this when | Change | Hub automation |
|---|---|---|---|
| Add the vulnboxd hook to a Dart service (shelf / dart_frog) | Depends on shelf, dart_frog or shelf_router (in its manifest) | source, rebuild | partly |
With source access
These change the service's code or Dockerfile, then it is rebuilt.
Add the vulnboxd hook to a Dart service (shelf / dart_frog)
- Use this when: Dart service that depends on
shelf,dart_frogorshelf_router(in its manifest). - Hub automation: partly. The hub pushes the compose lines; the source change is yours.
- Check and undo: hook mounted into the container
Vendors the vbxtrace Dart package into vendor/vbxtrace (path dependency), calls vbxInstallServerSockets() at the start of main for exact per-connection request indexes, adds vbxMiddleware() to the shelf pipeline (dart_frog: fromShelfMiddleware in routes/_middleware.dart), and replaces Process.start / Socket.connect / Isolate.run with the VbxTrace helpers where their effects should be linked; mounts the hook directory read-only.
1. Compose: merge into the service (app is its name) and redeploy:
services:
app:
volumes:
- /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro2. Source change, then rebuild:
- copy
/usr/local/lib/vulnboxd/trace/native/dart/vbxtraceto<service>/vendor/vbxtrace(pure Dart; needs onlyshelf, which a shelf/dart_frog service already has) pubspec.yamldependencies:vbxtrace: { path: vendor/vbxtrace }; rundart pub getsopubspec.locklists it (or let the Dockerfile'spub getdo it); make sure the Dockerfile copiesvendor/beforedart pub get- first line of
main()(dart_frog: ofrun()inmain.dart, creatingmain.dartif the project has none):vbxInstallServerSockets(); - shelf: add
.addMiddleware(vbxMiddleware())to thePipeline(outermost is best); dart_frog:routes/_middleware.dart:handler.use(fromShelfMiddleware(vbxMiddleware())) Process.start(...)→VbxTrace.startProcess(...);Process.run(...)→VbxTrace.runProcess(...);Socket.connect(h, p)→VbxTrace.connect(h, p)(orVbxTrace.socketConnected(socket)after any connect);Isolate.run(f)→VbxTrace.isolateRun(f)- if the service installs its own global
IOOverrides, serve withvbxServe(handler, address, port)instead ofshelf_io.serve(vbxInstallServerSocketsthen returnsfalse)
Example change on a sample service (hooks/native/c3/proposals/dart-shelf.diff):
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -6,3 +6,5 @@
dependencies:
shelf: ^1.4.0
shelf_router: ^1.1.0
+ vbxtrace:
+ path: vendor/vbxtrace
--- a/bin/server.dart
+++ b/bin/server.dart
@@ -1,15 +1,17 @@
import 'dart:io';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as shelf_io;
import 'package:shelf_router/shelf_router.dart';
+import 'package:vbxtrace/shelf.dart';
Future<Response> _ping(Request request) async {
- final result = await Process.run('ping', ['-c', '1', request.url.queryParameters['host']!]);
+ final result = await VbxTrace.runProcess('ping', ['-c', '1', request.url.queryParameters['host']!]);
return Response.ok(result.stdout);
}
Future<void> main() async {
+ vbxInstallServerSockets();
final router = Router()..get('/ping', _ping);
- final handler = const Pipeline().addMiddleware(logRequests()).addHandler(router.call);
+ final handler = const Pipeline().addMiddleware(vbxMiddleware()).addMiddleware(logRequests()).addHandler(router.call);
await shelf_io.serve(handler, InternetAddress.anyIPv4, 8080);
}
--- a/Dockerfile
+++ b/Dockerfile
@@ -2,6 +2,7 @@
FROM dart:3.8 AS build
WORKDIR /app
COPY pubspec.* ./
+COPY vendor ./vendor
RUN dart pub get
COPY . .
RUN dart compile exe bin/server.dart -o bin/serverExample change on a sample service (hooks/native/c3/proposals/dart-frog.diff):
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -6,3 +6,5 @@
dependencies:
dart_frog: ^1.2.0
+ vbxtrace:
+ path: vendor/vbxtrace
--- /dev/null
+++ b/main.dart
@@ -0,0 +1,9 @@
+import 'dart:io';
+
+import 'package:dart_frog/dart_frog.dart';
+import 'package:vbxtrace/vbxtrace.dart';
+
+Future<HttpServer> run(Handler handler, InternetAddress ip, int port) {
+ vbxInstallServerSockets();
+ return serve(handler, ip, port);
+}
--- a/routes/_middleware.dart
+++ b/routes/_middleware.dart
@@ -1,5 +1,8 @@
import 'package:dart_frog/dart_frog.dart';
+import 'package:vbxtrace/shelf.dart';
Handler middleware(Handler handler) {
- return handler.use(requestLogger());
+ return handler.use(requestLogger()).use(fromShelfMiddleware(vbxMiddleware()));
}
--- a/routes/exec.dart
+++ b/routes/exec.dart
@@ -1,8 +1,9 @@
import 'dart:io';
import 'package:dart_frog/dart_frog.dart';
+import 'package:vbxtrace/vbxtrace.dart';
Future<Response> onRequest(RequestContext context) async {
- final p = await Process.start('sh', ['-c', 'id']);
+ final p = await VbxTrace.startProcess('sh', ['-c', 'id']);
return Response(body: await p.stdout.transform(systemEncoding.decoder).join());
}Exact detection rules
Package C3 (Swift, Dart, Kotlin/Native), proposal C3:dart, defined in hooks/native/c3/proposals/dart.toml.
- Image matches (regex):
^(docker\.io/)?(library/)?dart:,^(docker\.io/)?dart-lang/ - Command matches (regex):
\bdart\b,/server$,\bdart_frog\b - Dependency on:
shelf,dart_frog,shelf_router - Files:
pubspec.yaml,pubspec.lock,routes/_middleware.dart,main.dart
Check that it works, and undo
Each block links the variant it needs.
Hook mounted into the container
Check: After the redeploy, this lists the processes that loaded the hook (empty: it is not loaded):
docker compose exec app sh -c 'grep -l vbxtrace /proc/[0-9]*/maps'The hub's Trace tab then shows links whose method starts with hook:.
Undo: Set VBXTRACE: "0" in the service's environment and restart it, or revert the commit (the hub's proposal screen has a revert per container). Remove the mount of /opt/vbxtrace only together with what loads from it: a runtime told to preload a missing file may refuse to start.