From d3359902e6446cc77fea3a2352ba3cb18f6cf656 Mon Sep 17 00:00:00 2001 From: kleinbem Date: Fri, 13 Nov 2026 15:28:49 +0000 Subject: [PATCH] fix(nix): replace stdenv store hashes so fetchFromGitHub FOD succeeds Test fixtures in `test/attic-api.test.ts` and `DEFAULT_UPSTREAM_SAMPLES` contained real Nix store hashes for `glibc` and `curl`, which appear in `fetchFromGitHub`'s `stdenv` closure and trigger Nix's fixed-output derivation store-reference check when unpacking release tarballs. Switch test fixtures to synthetic `0000...` Nix-base32 hashes (enforced by a new contract test) and replace `curl` in `DEFAULT_UPSTREAM_SAMPLES` with `fd-10.5.1`. --- src/lib/attic-api.ts | 4 ++-- test/attic-api.test.ts | 14 ++++++++------ test/ui-contracts.test.ts | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/lib/attic-api.ts b/src/lib/attic-api.ts index aeee8cb..47ab71f 100644 --- a/src/lib/attic-api.ts +++ b/src/lib/attic-api.ts @@ -11,11 +11,11 @@ export const PUBLIC_NIXOS_CACHE = 'https://cache.nixos.org'; export const PUBLIC_NIXOS_KEY = 'cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY='; -// Leaf packages outside stdenv/nodejs so Nix's hash scanner keeps allowedReferences = []. +// Leaf packages outside stdenv/fetchFromGitHub/nodejs so Nix FOD and allowedReferences = [] stay clean. export const DEFAULT_UPSTREAM_SAMPLES: SamplePath[] = [ { name: 'hello-2.12.3', hash: 'sd779x86bjaqxj2lzh2jsir4h0zjz6d1', group: 'Upstream' }, { name: 'ripgrep-15.2.0', hash: 'whbrk657qmih065xal60m4khwf6cb9pj', group: 'Upstream' }, - { name: 'curl-8.22.0', hash: '5lpg7j8y8lf8c4zv318yi4rmgyn5yhip', group: 'Upstream' } + { name: 'fd-10.5.1', hash: 'p7m1rnj0fm1nm9hwwj9vrgy3fc7grgg2', group: 'Upstream' } ]; const WITHHELD_MSG = 'Token not sent over plain HTTP: use an https:// endpoint'; diff --git a/test/attic-api.test.ts b/test/attic-api.test.ts index 8e3ae70..02f450c 100644 --- a/test/attic-api.test.ts +++ b/test/attic-api.test.ts @@ -27,7 +27,9 @@ import { updateBreadcrumbTrail } from '../src/lib/attic-api.ts'; -const SAMPLE_HASH = '9l0j15jg8634hkb6d4c9y95mpxl0nhrd'; +// Synthetic Nix-base32 hashes so fetchFromGitHub's FOD scanner never matches stdenv inputs. +const SAMPLE_HASH = '00000000000000000000000000000001'; +const DEP_HASH = '00000000000000000000000000000002'; const SAMPLE_NARINFO = [ `StorePath: /nix/store/${SAMPLE_HASH}-jq-1.8.2`, 'URL: nar/1abc2def.nar.zst', @@ -36,7 +38,7 @@ const SAMPLE_NARINFO = [ 'FileSize: 204800', 'NarHash: sha256:fedcba9876543210', 'NarSize: 614400', - `References: ${SAMPLE_HASH}-jq-1.8.2 pqyiidz5mi73wv5f91d48s9plcqyj5bz-glibc-2.44`, + `References: ${SAMPLE_HASH}-jq-1.8.2 ${DEP_HASH}-glibc-2.44`, 'Deriver: 00000000000000000000000000000000-jq-1.8.2.drv', 'Sig: cache.nixos.org-1:sigOne==', 'Sig: custom-cache-1:sigTwo==', @@ -68,7 +70,7 @@ describe('parseNarInfo & parseCacheInfo', () => { assert.equal(parsed.narSize, 614400); assert.deepEqual(parsed.references, [ `${SAMPLE_HASH}-jq-1.8.2`, - 'pqyiidz5mi73wv5f91d48s9plcqyj5bz-glibc-2.44' + `${DEP_HASH}-glibc-2.44` ]); assert.equal(parsed.deriver, '00000000000000000000000000000000-jq-1.8.2.drv'); assert.deepEqual(parsed.sig, ['cache.nixos.org-1:sigOne==', 'custom-cache-1:sigTwo==']); @@ -578,9 +580,9 @@ describe('Target resolution, presets, public keys, and breadcrumb state', () => }); it('appends, rewinds, and caps closure breadcrumb history cleanly', () => { - const h1 = '9l0j15jg8634hkb6d4c9y95mpxl0nhrd'; - const h2 = 'pqyiidz5mi73wv5f91d48s9plcqyj5bz'; - const h3 = '5lpg7j8y8lf8c4zv318yi4rmgyn5yhip'; + const h1 = '00000000000000000000000000000001'; + const h2 = '00000000000000000000000000000002'; + const h3 = '00000000000000000000000000000003'; let trail = updateBreadcrumbTrail([], `/nix/store/${h1}-jq-1.8.2`); trail = updateBreadcrumbTrail(trail, `/nix/store/${h2}-glibc-2.44`); diff --git a/test/ui-contracts.test.ts b/test/ui-contracts.test.ts index f4b7c8c..f1e85d3 100644 --- a/test/ui-contracts.test.ts +++ b/test/ui-contracts.test.ts @@ -87,4 +87,19 @@ describe('Frontend static, security, and accessibility contracts', () => { ); } }); + + it('uses only synthetic store hashes in test/ so fetchFromGitHub FOD checks never match stdenv', async () => { + const files = await listFiles('test'); + for (const file of files) { + const content = await readFile(file, 'utf8'); + const matches = content.match(/[0-9a-df-np-sv-z]{32}/g) ?? []; + for (const hash of matches) { + assert.match( + hash, + /^0{28}[0-9a-df-np-sv-z]{4}$/, + `Non-synthetic Nix store hash '${hash}' in ${file} risks colliding with fetchFromGitHub FOD inputs` + ); + } + } + }); });