Skip to content

Hook cheat sheet: R ​

How to add a vulnboxd runtime hook to a R 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/trace is the hook directory vulnboxd installs on the vulnbox. Compose snippets mount it read-only at /opt/vbxtrace in 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.

R ​

SetupUse this whenChangeHub automation
vulnboxd hook for plumber (R)Depends on plumber or httpuv (in its manifest)source, rebuildpartly

With source access ​

These change the service's code or Dockerfile, then it is rebuilt.

vulnboxd hook for plumber (R) ​

  • Use this when: R service that depends on plumber or httpuv (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 an R-callable shim around vbxhook (built with R CMD SHLIB in the image) and adds plumber hooks: request boundaries with the exact peer, the request index reported as unknown (httpuv exposes no connection identity), and spawned processes where the pid is known (processx).

1. Compose: merge into the service (app is its name) and redeploy:

yaml
services:
  app:
    volumes:
      - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro

2. Source change, then rebuild:

  1. copy /usr/local/lib/vulnboxd/trace/native/r/vbxtrace.R and vbxtrace_r.c into <service>/vbxtrace/, plus native/c/vbxhook.c, native/c/vbxhook.h and include/vbxtrace.h
  2. build the shim in the Dockerfile: RUN cd vbxtrace && PKG_CPPFLAGS=-I. R CMD SHLIB -o vbxtrace_r.so vbxtrace_r.c vbxhook.c
  3. in the entrypoint: source("vbxtrace/vbxtrace.R"); vbx_load("vbxtrace/vbxtrace_r.so"); then pass the router through vbx_plumber() before pr_run()
  4. optional: report processx children with vbx_spawned(p$get_pid())
  5. mount the hook directory read-only at /opt/vbxtrace in the service's compose entry

Example change on a sample service (hooks/native/c4/proposals/r-plumber.diff):

diff
# Example: a plumber service (Dockerfile, entrypoint.R, plumber.R) after copying vbxtrace/.
--- a/Dockerfile
+++ b/Dockerfile
@@ -3,3 +3,5 @@ FROM rstudio/plumber
 COPY . /app
 WORKDIR /app
+RUN cd vbxtrace && PKG_CPPFLAGS=-I. R CMD SHLIB -o vbxtrace_r.so vbxtrace_r.c vbxhook.c
 CMD ["Rscript", "entrypoint.R"]
--- a/entrypoint.R
+++ b/entrypoint.R
@@ -1,2 +1,4 @@
 library(plumber)
-pr("plumber.R") |> pr_run(host = "0.0.0.0", port = 8000)
+source("vbxtrace/vbxtrace.R")
+vbx_load("vbxtrace/vbxtrace_r.so")
+pr("plumber.R") |> vbx_plumber() |> pr_run(host = "0.0.0.0", port = 8000)
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -3,2 +3,4 @@ services:
   <service>:
     build: .
+    volumes:
+      - /usr/local/lib/vulnboxd/trace:/opt/vbxtrace:ro
Exact detection rules

Package C4 (Haskell, OCaml, Julia, R, Scala Native), proposal C4:r, defined in hooks/native/c4/proposals/r.toml.

  • Image matches (regex): ^rocker/, ^r-base, ^rstudio/plumber
  • Command matches (regex): \bRscript\b, plumb\(
  • Dependency on: plumber, httpuv
  • Files: plumber.R, entrypoint.R, DESCRIPTION, renv.lock, *.R

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):

sh
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.