Hot Cell
Active Storage decodes uploaded images with libvips inside the Rails process, to make variants and to read their dimensions. That process holds the app’s code, its credentials and its environment. CVE-2026-66066 used exactly that path: a crafted upload read secret_key_base back out through a thumbnail.
Hot Cell moves the decoding into a cell: a sibling container on the same host with no network, no access to the app’s filesystem or environment, no capabilities, and a fresh worker process for every request. A file that exploits libvips lands in a process that holds nothing and is about to be reaped.
The template ships Hot Cell wired but off. Nothing changes until a fork sets HOTCELL_ROOT; until then Active Storage processes images in the app exactly as before.
What it protects, and what it doesn’t yet
| Decoding path | Off (default) | On |
|---|---|---|
| Variants (avatars, logos, rich-text images) | In the app | In the cell |
| Image analysis (width, height) | In the app | In the cell |
| Previews (PDF, video) | Not installed | Off: previewers = [], so a tool later added to the app image can’t start decoding there |
active_storage_validations content_type: and size: |
Declared type only, no decoding | Same |
libvips stays in the app image. While the cell is off, variants run in the app, so the library has to be there. A fork that has turned the cell on can remove ruby-vips, image_processing and the apt package from its own Dockerfile; Hot Cell’s README calls that removal the security improvement. Until then, what the cell buys is that no untrusted byte is decoded in the app process.
The attachment guard (spec/code_smells/attachments_are_validated_spec.rb, see Testing) forbids validators that would decode an upload in the app to check it.
Prerequisites
- Rails with the variant-processor seam.
config.active_storage.variant_processoraccepts a class from rails/rails#58384, which is on Railsmainand unreleased. This template tracksmain; a fork on a released Rails waits for 8.2. - Ruby 3.3 or newer for the gems; the template runs Ruby 4.0.
- A registry the host can pull from. Kamal doesn’t build or deploy accessory images, so the cell image has to be pushed somewhere. The template’s default
localhost:5555registry can’t serve an accessory; use GitHub Container Registry or another remote one (Deployment).
How it is wired
config/initializers/hotcell.rbis the only switch. It registers theactive_storagecell and, whenHOTCELL_ROOTis set, pointsvariant_processorandanalyzersat the Hot Cell classes and setspreviewersto[]. No environment file mentions Hot Cell.hotcell/is the cell image:Dockerfile,GemfileandGemfile.lock,config.rb(limits) andoperations/(what the cell serves). It installs libvips and libheif’s HEVC and AV1 decoders by name and nothing else, and its build fails unless libvips registers its HEIF loader.- A failed variant answers its image request instead of raising: a permanent failure redirects to a placeholder image, and a transient one (a cell restarting or unreachable) answers 503
no-store, so the next page view fetches it again (Security, Image Processing). - Gates:
hotcell_buildbuilds the image pre-push whenhotcell/changes;bundler-audit check hotcellaudits its gems pre-push and in CI;hotcell_image_scan.ymlscans it with Trivy on pull requests that changehotcell/, and weekly once theHOTCELL_SCANrepository variable istrue; template invariants keep the two lockfiles on one Hot Cell version and the cell’s operations equal to what the initializer routes.
Turn it on
These steps are for a fork’s production host. Run them in order.
-
Build and push the cell image, tagged with the Hot Cell version (never
:latest, so a rollback names an image and the running cell is identifiable):docker build --pull --platform linux/amd64 \ --build-arg RUBY_VERSION=$(awk '/^ruby/{print $2}' .tool-versions) \ -t <registry>/<image>-hotcell:1.2.0 hotcell docker push <registry>/<image>-hotcell:1.2.0--platformmatchesbuilder.archinconfig/deploy.yml; an image built on Apple silicon without it fails on the host withexec format error. -
Edit
config/deploy.yml, merging into the keys it already has.servers:,volumes:andenv:are already there: add these lines inside them, and never add a secondvolumes:orenv:. YAML keeps only the last of two keys with one name, and Kamal then deploys without the storage volume that holds SQLite and the uploads, or without your secrets — and the check in step 3 still passes.volumes:is the top-level key (Kamal roles have novolumes:). The volume name carries the app’s name so two apps on one host never share a socket directory.bin/forkdoesn’t rewrite this page, so in a fork replacemodelrails_basein the sample with your app’s name, the onebin/forkput in the storage volume’s name inconfig/deploy.yml.servers: web: options: group-add: 10001 # the cell's gid; admits the app to its sockets volumes: - "modelrails_base_storage:/rails/storage" # already there: keep it - "/srv/backups/modelrails_base:/backups" # already there: keep it - modelrails_base_hotcell_sockets:/run/hotcell/active_storage # $HOTCELL_ROOT/<cell name> env: clear: # every entry already under env.clear stays, and env.secret stays as it is HOTCELL_ROOT: /run/hotcell HOTCELL_GROUP: "10001" accessories: active_storage: image: <registry>/<image>-hotcell:1.2.0 roles: [ web ] network: none volumes: - modelrails_base_hotcell_sockets:/run/hotcell/cell options: cpus: 2 memory: 2g memory-swap: 2g read-only: true tmpfs: /tmp:rw,nosuid,nodev,noexec,size=512m cap-drop: ALL security-opt: no-new-privileges:true user: "10001:10001" pids-limit: 512network: noneis an accessory key, not an option: underoptions:Kamal emits a second--networkand Docker refuses the container. The values come from Hot Cell’s container reference;memorycounts every worker and the tmpfs, so keep the tmpfs at 512m withmemory: 2g. -
Check the command before you deploy. Kamal’s merged config doesn’t show a doubled flag, so print the command it will run:
bundle exec ruby -rkamal -e ' config = Kamal::Configuration.create_from(config_file: Pathname.new("config/deploy.yml"), version: "check") puts Kamal::Commands::Accessory.new(config, name: :active_storage).run.flatten.join(" ")'--network nonemust appear exactly once. -
Boot the cell, then deploy the app:
kamal accessory boot active_storage kamal deploy -
Read the app’s boot log (
kamal app logs). At boot the app asks the cell to describe itself and warns, without failing, about a cell that is unreachable, on another Hot Cell version, slower than the app waits, or in a group the app doesn’t hold. With the template’s limits the cell answers within 26 seconds and the app waits 30, so nohotcellwarning lines means the cell answered on the same version with the group held. If you raisedeadlineorqueue_wait, raise the app’stimeout:inconfig/initializers/hotcell.rbwith them; a template invariant fails when they cross. -
Check the running container’s flags:
docker inspect <cell container> --format '{{json .HostConfig}}' | jq '{ NetworkMode, ReadonlyRootfs, CapDrop, SecurityOpt, PidsLimit, Memory, MemorySwap, Tmpfs, Binds }'Expect
NetworkMode: "none",ReadonlyRootfs: trueandCapDrop: ["ALL"]. Hot Cell’s conformance script is a pre-deploy image check, not this: it supplies its own flags, so it passes against an image you’re about to deploy withcap-dropmissing. -
Re-run analysis for anything the cell couldn’t analyze. A transient failure (the cell restarting or unreachable) is retried by the job, ten times. A permanent one (for example a worker killed for exceeding
memorywhile the limits were being tuned) is recorded: Active Storage marks the image analyzed with no dimensions and never retries it (Hot Cell’s codes reference, What Active Storage records). After fixing the cause:ActiveStorage::Blob.where("content_type LIKE 'image/%'").find_each do |blob| next unless blob.metadata["width"].nil? blob.update!(metadata: blob.metadata.except("analyzed")) blob.analyze_later end
Tune it
| Setting | Where | Default | Keep together with |
|---|---|---|---|
cpus |
accessory options: |
2 | OMP_NUM_THREADS in hotcell/Dockerfile (default 2): libvips sizes its thread pool from the host’s cores, not the quota |
memory |
accessory options: |
2g | the tmpfs size, and concurrency × peak worker memory; above the cell’s own memory limit |
concurrency |
hotcell/config.rb |
4 | pids-limit, memory |
deadline |
hotcell/config.rb |
20 s | the longest image you accept, and the app’s timeout |
queue_wait |
hotcell/config.rb |
5 s | the app’s timeout |
timeout |
HotCell.register in config/initializers/hotcell.rb |
30 s | stays above queue_wait + deadline + 1, or every boot warns and a slow request ends in the app’s timeout instead of the cell’s answer |
A starting point for a small host (one vCPU, 2 GB RAM), not yet measured: cpus: 1, memory: 1g with memory-swap: 1g, concurrency: 2, OMP_NUM_THREADS=1. Hot Cell’s tuning guide has the arithmetic.
Upgrade it
The app’s hotcell-client and the cell’s hotcell-server must run the same version, so Dependabot leaves the Hot Cell gems alone and they move by hand, in one pull request:
- Bump the version in
Gemfileandhotcell/Gemfile; runbundle update activestorage-hotcell-clientand, from the repository root,BUNDLE_GEMFILE=hotcell/Gemfile bundle update hotcell-server activestorage-hotcell-server. The lockfile-parity invariant fails if they disagree. - Compare the gem’s
install/*.tttemplates between the two versions and apply what changed tohotcell/. Re-runningbin/rails hotcell:installshows nothing: it skips files that exist. - After the pull request merges, build and push the new tag, change the accessory’s
image:, and runkamal accessory reboot active_storage.kamal deploynever touches accessories.
The cell’s other gems (ruby-vips, ffi, …) are audited by bin/bundler-audit check hotcell on every push and CI run.
Add to it
- An attachment. Give it
content_type:andsize:validations; the attachment guard requires both. Nothing changes in the cell for images. - A tool or a custom operation. Add the apt packages on the reserved
RUNline inhotcell/Dockerfile, not on the template’s libvips line, so upstream changes to that line merge cleanly. Put each operation in its own file underhotcell/operations/. The operation-parity invariant then asks for the matching client class inconfig/initializers/hotcell.rb. Keephotcell/Gemfileshort: every gem in it is inside the blast radius.
Develop with it
The cell can run on a laptop as a plain process; a containerized cell works only on Linux, because descriptor passing doesn’t cross the VM Docker uses on macOS. Install the cell’s bundle once (BUNDLE_GEMFILE=hotcell/Gemfile bundle install), then add Hot Cell’s two lines to Procfile.dev:
web: HOTCELL_ROOT=$PWD/tmp/hotcell-sockets bin/rails server
cell: BUNDLE_GEMFILE=$PWD/hotcell/Gemfile HOTCELL_CONFIG=$PWD/hotcell/config.rb HOTCELL_OPERATIONS=$PWD/hotcell/operations HOTCELL_DIR=$PWD/tmp/hotcell-sockets/active_storage bundle exec hotcell --development
Keep --development: without it the cell empties the system temporary directory at boot. Under Docker Desktop the cell logs cell.ptrace_scope_unknown at boot, because the VM has no Yama security module; a Linux host has one.
Turn it off, or recover it
- Off. Remove
HOTCELL_ROOTandHOTCELL_GROUPfromenv.clearandkamal deploy. The app processes images itself again; the accessory can stay. - A cell that can’t create its sockets. If the app’s deploy created the socket volume before the cell’s first boot, the cell’s user may not own it.
kamal accessory remove active_storage,docker volume rm modelrails_base_hotcell_socketson the host, thenkamal accessory boot active_storageandkamal app boot.