Skip to content

Open-source personal finance manager. Self-hosted, privacy-first.

Mitigate Supply chain attacks for frontend dependencies (#187)

Paulo Paesfaf70c6e9288
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 3ede5040..a4d4af24 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -73,6 +73,21 @@ local and CI stay in sync.
[prek](https://github.com/j178/prek) is a drop-in replacement for pre-commit:
same `.pre-commit-config.yaml`, but a single binary with no Python bootstrap.
+
+### Adding a frontend dependency
+
+`frontend/.npmrc` never runs a package's install scripts, and asks npm to skip
+releases younger than seven days so a compromised publish has time to be caught.
+The cooldown needs npm 11.10 or newer; the npm that ships with Node 22 is older
+and will ignore that line without saying so, so upgrade before you add anything:
+
+```bash
+npm install --global npm@latest
+cd frontend && npm install <package> # commit package.json and package-lock.json
+```
+
+If the package you want was published in the last week, npm resolves the release
+before it. That is the point — wait, or say in the PR why you can't.
Either works.
## Commit Messages
diff --git a/frontend/.npmrc b/frontend/.npmrc
new file mode 100644
index 00000000..ec456bc5
--- /dev/null
+++ b/frontend/.npmrc
@@ -0,0 +1,18 @@
+# Supply-chain hardening. See CONTRIBUTING.md.
+
+# Never run a dependency's install/postinstall script. The main vector in the
+# npm compromises of the last year: the payload runs at install time, before
+# any of our code does. Applies to every npm version, including the npm 10
+# that ships with Node 22.
+ignore-scripts=true
+
+# Cooldown, in days: only resolve versions that have been public long enough
+# for a compromised release to be caught and unpublished. Applies when a
+# version is *chosen* (`npm install <pkg>`), not when one is replayed from the
+# lockfile (`npm ci`), and needs npm >= 11.10. The enforced cooldown for this
+# repo lives in renovate.json, since Renovate is what bumps our dependencies.
+min-release-age=7
+
+# Pin what we add to an exact version instead of a caret range, so the range
+# can't widen into a release nobody reviewed.
+save-exact=true
diff --git a/frontend/Dockerfile b/frontend/Dockerfile
index c3741c50..4229cc16 100644
--- a/frontend/Dockerfile
+++ b/frontend/Dockerfile
@@ -5,7 +5,7 @@ WORKDIR /app
ARG VITE_APP_VERSION
ENV VITE_APP_VERSION=$VITE_APP_VERSION
-COPY package.json package-lock.json ./
+COPY package.json package-lock.json .npmrc ./
RUN npm ci
COPY . .
diff --git a/frontend/Dockerfile.dev b/frontend/Dockerfile.dev
index a196f845..55c82df9 100644
--- a/frontend/Dockerfile.dev
+++ b/frontend/Dockerfile.dev
@@ -5,7 +5,7 @@ WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends git \
&& rm -rf /var/lib/apt/lists/*
-COPY package.json package-lock.json ./
+COPY package.json package-lock.json .npmrc ./
RUN npm ci
COPY . .
diff --git a/renovate.json b/renovate.json
index 1cae4e09..e1a3d290 100644
--- a/renovate.json
+++ b/renovate.json
@@ -11,6 +11,11 @@
"schedule": ["before 8am on the first day of the month"]
},
"packageRules": [
+ {
+ "description": "Cooldown before we pick up a new release, so a compromised publish has time to be caught and unpublished. Mirrors `min-release-age` in frontend/.npmrc, which only covers a dependency added by hand.",
+ "matchManagers": ["npm"],
+ "minimumReleaseAge": "7 days"
+ },
{
"matchManagers": ["github-actions"],
"matchUpdateTypes": ["minor", "patch"],