Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ FROM ${NODE_IMAGE}
# Remove everything the server never uses but an attacker inside the
# container would: package managers (npm, yarn, corepack, apk) and the
# busybox network/privilege tools (wget, nc, su). The health check uses
# node instead of wget.
# node instead of wget. /lib/apk/db stays: without that list of installed
# packages, scanners see 0 OS packages and report 0 CVEs however many there are.
RUN apk upgrade --no-cache \
&& rm -rf /usr/local/lib/node_modules/npm /usr/local/lib/node_modules/corepack /opt/yarn-* \
/usr/local/bin/npm /usr/local/bin/npx /usr/local/bin/corepack /usr/local/bin/yarn /usr/local/bin/yarnpkg \
/usr/bin/wget /usr/bin/nc /bin/su \
/sbin/apk /etc/apk /lib/apk /usr/share/apk /var/cache/apk
/sbin/apk /etc/apk /lib/apk/exec /usr/share/apk /var/cache/apk
WORKDIR /app
# Copied as root and left root-owned: the node user can read the code but
# never change it.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ The image is built so that code running inside the server process — for exampl

- **Non-root:** the server runs as `node` (uid 1000). The code in `/app` is owned by root and read-only for that user.
- **Node permission model:** the default `CMD` starts `node --permission --allow-fs-read=/app`. The process may read its own code and nothing else; writing files, child processes (no shell), worker threads and native addons are denied. Outbound network access is not affected. The server needs none of the denied operations, including `download_file`, which extracts PDF text in memory.
- **No tools for an attacker:** npm, npx, yarn, corepack and apk are removed, and so are busybox `wget`, `nc` and `su`. The health check uses `node`. There are no setuid binaries.
- **No tools for an attacker:** npm, npx, yarn, corepack and apk are removed, and so are busybox `wget`, `nc` and `su`. The health check uses `node`. There are no setuid binaries. Only apk's package list in `/lib/apk/db` stays, so that vulnerability scanners can see the OS packages. Without `/sbin/apk` it can't install anything, and the permission model denies the server read access to it.
- **Pinned base image:** `node:22.23.4-alpine3.24` (build argument `NODE_IMAGE`), with `apk upgrade` at build time.

At runtime, add the restrictions the image can't set itself. `docker-compose.yml` contains all of them:
Expand Down
Loading