From a121fe2585a9165b3c6dbbbcef082d74fe246100 Mon Sep 17 00:00:00 2001 From: Josh Mandel Date: Thu, 3 Dec 2026 15:10:35 -0600 Subject: [PATCH 1/7] Install tar 8 everywhere: route sqlite3, node-gyp and node-pre-gyp through a small shim tar 7 has open advisories that are fixed only in tar 8. sqlite3, node-gyp and @mapbox/node-pre-gyp still ask for tar 7, and two of their calls changed in tar 8, so a plain override to tar 8 breaks installs that build from source or download a prebuilt binary. vendor/tar-stream-shim is tar 8 with those two call forms restored (extract() with no file returning a writable stream, and extract({sync: true})). package.json overrides point the three packages at it, so the only tar code in node_modules is tar 8. The lock file changes only in the tar entries. The Dockerfile copies the shim in before npm ci. The Install check workflow installs on Linux, macOS and Windows, checks no tar older than 8 is present, loads the native modules and builds sqlite3 from source. Co-Authored-By: Claude --- .github/workflows/install-check.yml | 91 +++++++++++++++++++ CHANGELOG.md | 1 + Dockerfile | 2 + audit-allowlist.json | 4 +- package-lock.json | 135 +++++++--------------------- package.json | 11 ++- vendor/README.md | 35 ++++++++ vendor/tar-stream-shim-1.0.0.tgz | Bin 0 -> 1049 bytes vendor/tar-stream-shim/index.js | 32 +++++++ vendor/tar-stream-shim/package.json | 11 +++ 10 files changed, 216 insertions(+), 106 deletions(-) create mode 100644 .github/workflows/install-check.yml create mode 100644 vendor/README.md create mode 100644 vendor/tar-stream-shim-1.0.0.tgz create mode 100644 vendor/tar-stream-shim/index.js create mode 100644 vendor/tar-stream-shim/package.json diff --git a/.github/workflows/install-check.yml b/.github/workflows/install-check.yml new file mode 100644 index 000000000..5072f4016 --- /dev/null +++ b/.github/workflows/install-check.yml @@ -0,0 +1,91 @@ +name: Install check + +# Installs the dependencies on Linux, macOS and Windows and checks what the tar overrides in +# package.json are there for (see vendor/README.md): no tar older than 8 is installed, the native +# modules load, and sqlite3 still builds from source. Runs when the dependencies change +on: + push: + paths: + - package.json + - package-lock.json + - vendor/** + - .github/workflows/install-check.yml + pull_request: + paths: + - package.json + - package-lock.json + - vendor/** + - .github/workflows/install-check.yml + workflow_dispatch: + +jobs: + install: + name: Install (${{ matrix.os }}) + runs-on: ${{ matrix.os }} + timeout-minutes: 30 + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + defaults: + run: + shell: bash + + steps: + - uses: actions/checkout@v4 + + - name: Use Node.js + uses: actions/setup-node@v4 + with: + node-version: '24' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Check no tar older than 8 is installed + run: | + node -e ' + const fs = require("fs"), path = require("path"); + const found = []; + (function look(dir) { + for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { + if (!entry.isDirectory()) continue; + const sub = path.join(dir, entry.name); + if (entry.name.startsWith("@")) { look(sub); continue; } + const manifest = path.join(sub, "package.json"); + if (fs.existsSync(manifest)) { + const { name, version } = JSON.parse(fs.readFileSync(manifest, "utf8")); + if (name === "tar") found.push({ version, sub }); + } + if (fs.existsSync(path.join(sub, "node_modules"))) look(path.join(sub, "node_modules")); + } + })("node_modules"); + for (const { version, sub } of found) console.log(`tar ${version} in ${sub}`); + const old = found.filter(({ version }) => parseInt(version, 10) < 8); + if (found.length === 0 || old.length > 0) { console.error("expected tar 8 or later, and nothing older"); process.exit(1); } + ' + + - name: Load the native modules + run: | + node -e ' + const { RoaringBitmap32 } = require("roaring"); + console.log("roaring", new RoaringBitmap32([1, 2, 3]).size); + console.log("better-sqlite3", require("better-sqlite3")(":memory:").prepare("select sqlite_version() v").get().v); + require("bcrypt").hashSync("x", 4); + new (require("sqlite3").Database)(":memory:").get("select sqlite_version() v", (error, row) => { + if (error) throw error; + console.log("sqlite3", row.v); + }); + ' + + # The build unpacks the SQLite source with tar (node_modules/sqlite3/deps/extract.js) and + # then deletes its VERSION file, which on macOS and Windows hides the C++ header + - name: Build sqlite3 from source + working-directory: node_modules/sqlite3 + run: | + node ../node-gyp/bin/node-gyp.js rebuild + left=$(find build -name VERSION | wc -l) + echo "VERSION files left: $left" + [ "$left" -eq 0 ] + node -e 'new (require(".").Database)(":memory:").get("select sqlite_version() v", (error, row) => { if (error) throw error; console.log("sqlite3 built from source", row.v); })' diff --git a/CHANGELOG.md b/CHANGELOG.md index bbda88d0f..697743319 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Security - Packages are read with tar 8 (was 7, which has 16 high advisories, most of them ways for an archive's links to get out of the folder it is extracted into): the package manager (the tx module's packages) and the packages crawler, which read packages from elsewhere. A package is unzipped against the unpacked size limit as before, and a second layer of compression inside one is now refused +- No tar 7 is installed any more. sqlite3, node-gyp and @mapbox/node-pre-gyp (under roaring) each asked for tar 7, which they use while installing to unpack a prebuilt binary, the Node headers or the SQLite source, and none has a release on tar 8. package.json `overrides` now gives them tar 8, through a small adapter for the two calls tar 8 changed (vendor/README.md). The tar advisory is gone from audit-allowlist.json ### Added diff --git a/Dockerfile b/Dockerfile index 4278c5485..c9f8585d7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,8 @@ RUN apk add --no-cache python3 make g++ # Install app dependencies COPY package*.json ./ +# package.json "overrides" installs this in place of tar 7 (vendor/README.md) +COPY vendor/tar-stream-shim-1.0.0.tgz ./vendor/ RUN npm ci --omit=dev # Stage 2: Runtime image (no build tools) diff --git a/audit-allowlist.json b/audit-allowlist.json index 25e7ce94e..ee1371abd 100644 --- a/audit-allowlist.json +++ b/audit-allowlist.json @@ -1,6 +1,4 @@ { "comment": "Advisories the CI npm audit steps accept (utilities/audit-check.js). Each entry needs a reason, and an expiry date after which it fails again so it gets looked at. Remove an entry once a fixed version is installed - the check warns when an entry no longer matches anything.", - "advisories": [{ "id": "GHSA-25mm-r35j-6hgm", "until": "2027-03-01", - "reason": "tar <8: FHIRsmith's own tar is 8.0.5. The tar 7 copies left are sqlite3 6.0.1's, node-gyp 12's and @mapbox/node-pre-gyp 2.0.3's (under roaring), with no release on tar 8 yet; they use it only while installing, on archives from fixed sources. Remove once they move to tar 8" - }] + "advisories": [] } diff --git a/package-lock.json b/package-lock.json index c023ae168..245a0b6b5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -41,7 +41,7 @@ "qrcode-generator": "^2.0.4", "re2js": "^2.8.0", "sqlite3": "^6.0.1", - "tar": "^8.0.5", + "tar": "^8.1.2", "turndown": "^7.2.5", "winston": "^3.19.0", "winston-daily-rotate-file": "^4.7.1", @@ -966,18 +966,6 @@ "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, - "node_modules/@isaacs/fs-minipass": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/@isaacs/fs-minipass/-/fs-minipass-4.0.1.tgz", - "integrity": "sha512-wgm9Ehl2jpeqP3zw/7mo3kRHFp5MEDhqAdwy1fTGkHAwnkGOVsgpvQhL8B5n1qlb01jV3n/bI0ZfZp5lWA1k4w==", - "license": "ISC", - "dependencies": { - "minipass": "^7.0.4" - }, - "engines": { - "node": ">=18.0.0" - } - }, "node_modules/@isaacs/nonrecursive-glob-match": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@isaacs/nonrecursive-glob-match/-/nonrecursive-glob-match-1.1.0.tgz", @@ -1947,30 +1935,14 @@ } }, "node_modules/@mapbox/node-pre-gyp/node_modules/tar": { - "version": "7.5.24", - "resolved": "https://registry.npmjs.org/tar/-/tar-7.5.24.tgz", - "integrity": "sha512-to/OxuCk5DeVONcjjODT7aeoRq5NIPPlfPc0tNML+wLlnf6u5BcJz97Uukv3pT3jzorkFhUevylkAiBr+ZmV2w==", - "license": "BlueOak-1.0.0", + "name": "tar-stream-shim", + "version": "1.0.0", + "resolved": "file:vendor/tar-stream-shim-1.0.0.tgz", + "integrity": "sha512-/FbyFhKmsOQ3fZo9E3vf4hs5Rm8Y+O7MYcS4yDosAYg6YCWb6UeAQNvrTz4iQ1sbbNiPYKhdVYKj8ybE7laLwg==", + "license": "BSD-3-Clause", "optional": true, "dependencies": { - "@isaacs/fs-minipass": "^4.0.0", - "chownr": "^3.0.0", - "minipass": "^7.1.2", - "minizlib": "^3.1.0", - "yallist": "^5.0.0" - }, - "engines": { - "node": ">=18" - } - }, - "node_modules/@mapbox/node-pre-gyp/node_modules/yallist": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-5.0.0.tgz", - "integrity": "sha512-YgvUTfwqyc7UXVMrB+SImsVYSmTS8X/tSrtdNZMImM+n7+QTriRXyXim0mBrTXNeqzVF0KWGgHPeiyViFFrNDw==", - "license": "BlueOak-1.0.0", - "optional": true, - "engines": { - "node": ">=18" + "tar8": "npm:tar@^8.1.2" } }, "node_modules/@mixmark-io/domino": { @@ -3938,15 +3910,6 @@ "integrity": "sha512-rddelWYNPRrXq6PtNEN2S3f6t9ILzvqaN5pVgi4kqt9jHQaXIial9PznB5iSPVlQSLNaaH22ItWz3EJtQ10+OA==", "license": "MIT" }, - "node_modules/chownr": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/chownr/-/chownr-3.0.0.tgz", - "integrity": "sha512-+IxzY9BZOQd/XuYPRmrvEVjF/nqj5kgT4kEq7VofrDoM1MxoRjEWkrCC3EtLi59TVawxTAn+orJwFQcrqEN1+g==", - "license": "BlueOak-1.0.0", - "engines": { - "node": ">=18" - } - }, "node_modules/ci-info": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-4.4.0.tgz", @@ -7493,23 +7456,12 @@ "version": "7.1.3", "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.3.tgz", "integrity": "sha512-tEBHqDnIoM/1rXME1zgka9g6Q2lcoCkxHLuc7ODJ5BxbP5d4c2Z5cGgtXAku59200Cx7diuHTOYfSBD8n6mm8A==", + "dev": true, "license": "BlueOak-1.0.0", "engines": { "node": ">=16 || 14 >=14.17" } }, - "node_modules/minizlib": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-3.1.0.tgz", - "integrity": "sha512-KZxYo1BUkWD2TVFLr0MQoM8vUUigWD3LlD83a/75BqC+4qE0Hb1Vo5v1FgcfaNXvfXzr+5EhQ6ing/CaBijTlw==", - "license": "MIT", - "dependencies": { - "minipass": "^7.1.2" - }, - "engines": { - "node": ">= 18" - } - }, "node_modules/mkdirp": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", @@ -7906,20 +7858,14 @@ } }, "node_modules/node-gyp/node_modules/tar": { - "version": "7.5.24", - "resolved": "https://registry.npmjs.org/tar/-/tar-7.5.24.tgz", - "integrity": "sha512-to/OxuCk5DeVONcjjODT7aeoRq5NIPPlfPc0tNML+wLlnf6u5BcJz97Uukv3pT3jzorkFhUevylkAiBr+ZmV2w==", - "license": "BlueOak-1.0.0", + "name": "tar-stream-shim", + "version": "1.0.0", + "resolved": "file:vendor/tar-stream-shim-1.0.0.tgz", + "integrity": "sha512-/FbyFhKmsOQ3fZo9E3vf4hs5Rm8Y+O7MYcS4yDosAYg6YCWb6UeAQNvrTz4iQ1sbbNiPYKhdVYKj8ybE7laLwg==", + "license": "BSD-3-Clause", "optional": true, "dependencies": { - "@isaacs/fs-minipass": "^4.0.0", - "chownr": "^3.0.0", - "minipass": "^7.1.2", - "minizlib": "^3.1.0", - "yallist": "^5.0.0" - }, - "engines": { - "node": ">=18" + "tar8": "npm:tar@^8.1.2" } }, "node_modules/node-gyp/node_modules/which": { @@ -7938,16 +7884,6 @@ "node": "^20.17.0 || >=22.9.0" } }, - "node_modules/node-gyp/node_modules/yallist": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-5.0.0.tgz", - "integrity": "sha512-YgvUTfwqyc7UXVMrB+SImsVYSmTS8X/tSrtdNZMImM+n7+QTriRXyXim0mBrTXNeqzVF0KWGgHPeiyViFFrNDw==", - "license": "BlueOak-1.0.0", - "optional": true, - "engines": { - "node": ">=18" - } - }, "node_modules/node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -9382,28 +9318,13 @@ } }, "node_modules/sqlite3/node_modules/tar": { - "version": "7.5.24", - "resolved": "https://registry.npmjs.org/tar/-/tar-7.5.24.tgz", - "integrity": "sha512-to/OxuCk5DeVONcjjODT7aeoRq5NIPPlfPc0tNML+wLlnf6u5BcJz97Uukv3pT3jzorkFhUevylkAiBr+ZmV2w==", - "license": "BlueOak-1.0.0", + "name": "tar-stream-shim", + "version": "1.0.0", + "resolved": "file:vendor/tar-stream-shim-1.0.0.tgz", + "integrity": "sha512-/FbyFhKmsOQ3fZo9E3vf4hs5Rm8Y+O7MYcS4yDosAYg6YCWb6UeAQNvrTz4iQ1sbbNiPYKhdVYKj8ybE7laLwg==", + "license": "BSD-3-Clause", "dependencies": { - "@isaacs/fs-minipass": "^4.0.0", - "chownr": "^3.0.0", - "minipass": "^7.1.2", - "minizlib": "^3.1.0", - "yallist": "^5.0.0" - }, - "engines": { - "node": ">=18" - } - }, - "node_modules/sqlite3/node_modules/yallist": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-5.0.0.tgz", - "integrity": "sha512-YgvUTfwqyc7UXVMrB+SImsVYSmTS8X/tSrtdNZMImM+n7+QTriRXyXim0mBrTXNeqzVF0KWGgHPeiyViFFrNDw==", - "license": "BlueOak-1.0.0", - "engines": { - "node": ">=18" + "tar8": "npm:tar@^8.1.2" } }, "node_modules/stack-trace": { @@ -9702,9 +9623,9 @@ } }, "node_modules/tar": { - "version": "8.0.5", - "resolved": "https://registry.npmjs.org/tar/-/tar-8.0.5.tgz", - "integrity": "sha512-iYroSHv/iVs5Bfy7uXCZVTye64oecqEETP3jvxksDcJlf8E3hreHYyhT+Qu7b+JgniditLaQbk4ZujNAnPEX9w==", + "version": "8.1.2", + "resolved": "https://registry.npmjs.org/tar/-/tar-8.1.2.tgz", + "integrity": "sha512-yzdgDKPqRFlEYBtTJVP91hT2zyTwadRzAALlGccmGhNYucV2iJyShQLTdSAh/YY9efLmjNjkktsvAwhVg6Sifw==", "license": "BlueOak-1.0.0", "engines": { "node": ">=22" @@ -9744,6 +9665,16 @@ "node": ">=6" } }, + "node_modules/tar8": { + "name": "tar", + "version": "8.1.2", + "resolved": "https://registry.npmjs.org/tar/-/tar-8.1.2.tgz", + "integrity": "sha512-yzdgDKPqRFlEYBtTJVP91hT2zyTwadRzAALlGccmGhNYucV2iJyShQLTdSAh/YY9efLmjNjkktsvAwhVg6Sifw==", + "license": "BlueOak-1.0.0", + "engines": { + "node": ">=22" + } + }, "node_modules/test-exclude": { "version": "7.0.2", "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-7.0.2.tgz", diff --git a/package.json b/package.json index be04d6944..9ac8f6e0d 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "qrcode-generator": "^2.0.4", "re2js": "^2.8.0", "sqlite3": "^6.0.1", - "tar": "^8.0.5", + "tar": "^8.1.2", "turndown": "^7.2.5", "winston": "^3.19.0", "winston-daily-rotate-file": "^4.7.1", @@ -114,6 +114,15 @@ "overrides": { "@istanbuljs/load-nyc-config": { "js-yaml": "^4.1.0" + }, + "sqlite3": { + "tar": "file:./vendor/tar-stream-shim-1.0.0.tgz" + }, + "@mapbox/node-pre-gyp": { + "tar": "file:./vendor/tar-stream-shim-1.0.0.tgz" + }, + "node-gyp": { + "tar": "file:./vendor/tar-stream-shim-1.0.0.tgz" } }, "bin": { diff --git a/vendor/README.md b/vendor/README.md new file mode 100644 index 000000000..5d143cac4 --- /dev/null +++ b/vendor/README.md @@ -0,0 +1,35 @@ +# vendor + +## tar-stream-shim + +`sqlite3`, `node-gyp` and `@mapbox/node-pre-gyp` (the last two come with `roaring`) depend on +tar 7. They use it only while installing: to unpack a prebuilt binary, the Node headers, or the +SQLite source for a build from source. tar 7 has advisories that are fixed only in tar 8, and +none of the three has a release on tar 8. + +tar 8 can't simply be put in its place (`"overrides": { "tar": "$tar" }`), as it changed two +calls they make: + +- `tar.extract(opts)` with no `file` returned a stream to pipe an archive into. In tar 8 the + archive is the `input` option and the call returns a Promise. `node-gyp` and + `@mapbox/node-pre-gyp` pipe their download into it, so `roaring` fails to install. +- `tar.extract({ sync: true, ... })` had finished when it returned. tar 8 ignores `sync` + (the synchronous call is `extractSync`), so `sqlite3/deps/extract.js` goes on before + anything is extracted, and the `VERSION` file it means to delete stays - which breaks a + build of sqlite3 from source on a case-insensitive file system (macOS, Windows). + +`tar-stream-shim` is tar 8 with those two calls as they were. package.json `overrides` installs +it as `tar` under the three packages, so the only tar installed is tar 8. + +The override names the packed file, `tar-stream-shim-1.0.0.tgz`, not the directory: npm links a +directory named in an override from the wrong place. After changing `tar-stream-shim/`: + + cd vendor/tar-stream-shim && npm pack --pack-destination .. + +and update the three `node_modules/*/node_modules/tar` entries' `integrity` in +package-lock.json. npm (11 and 12) fails to add these entries to an existing package-lock.json +by itself (it looks for the file under the package the override is for); they were written to +a new lock file and copied in. + +Remove all of this - the directory, the `.tgz`, the three `overrides`, and the `COPY` in the +Dockerfile - once `sqlite3`, `node-gyp` and `@mapbox/node-pre-gyp` depend on tar 8. diff --git a/vendor/tar-stream-shim-1.0.0.tgz b/vendor/tar-stream-shim-1.0.0.tgz new file mode 100644 index 0000000000000000000000000000000000000000..c8768306483c00d9b98d9765a245a3ee8b99b753 GIT binary patch literal 1049 zcmV+!1m^o6iwFP!00002|Ls@bkK#5E=9$0Z6E7rEa02_|R-kRK?cHOg(`}`Dt1$7f z@oi$~YzG!`{O^^W1n6F+_Mu(rD&_?=GyZ12nZX`vo zN>{)Y1h>^e_XasHORTl2EL_1|uu5f}SKHjk+F9r|bYq~nlN*Adnv@`wOR~c>g>|wl z(O6=r+eu@etyUQ64H+W^*%9i-d36xkzx%Xl${Piksch9<#PnaQumE=tUoZ+YWvyRo%E{C`X&41;+=YD{0Ad z#Oy?HZ+9x6!FvbpXPp{wtYpJ9yNMN;Vr$SZ)=}y$6uHNH5xS-mm9XR`JA*dur zJ^^1ltc|V$Qs+Vf&JaPXpjGtjP)bEdp7K#?Lq}>p+vOto`mcr2N;fu)r*CkF`mj@Z z6tiKjm30B=9)`X&(oi&Z+}w@hMQ7aO1Go0K!szC)Nbsp^WP*>xMQG{a{BYY}e|)%Z zRPLl!f0`BCV}A&RG-O?j{Sc6A1RL`iw<@5I?sdUmyMl}j(Y*5lX$rEXRBj@q^_fh3 zVW9M+QH>=r*>Gb6R@)8Flbsi!MLZ?57y^g$d_qUQehu+h7@9u2ZxO?ZZ?Re${RrMe z(e}KcQE+UXgjU|;9CIIt2jCEXeylok`V+094midk0C@<@7$l%ZOi zFidS+Ke)V%;sh%y^>%n<8KISNQh&vLA-SN{gl>M$f*=Va9#q95+cn{0W}t{dXJ| z!@)(qBk5k{^!#;x-Tg1SzP*0A|4nahW|#f%HN;k48|dlWc?eZkbH~lw-|yIz%|_wnJ6vwK Ti(KR){|os8oZ=|~01^NIdN>o3 literal 0 HcmV?d00001 diff --git a/vendor/tar-stream-shim/index.js b/vendor/tar-stream-shim/index.js new file mode 100644 index 000000000..431cecf8e --- /dev/null +++ b/vendor/tar-stream-shim/index.js @@ -0,0 +1,32 @@ +// tar 8, with the two tar 7 call forms that the install scripts of our native dependencies +// still use. package.json "overrides" puts this in place of `tar` under node-gyp, +// @mapbox/node-pre-gyp and sqlite3, so that no tar 7 is installed. See vendor/README.md. +// +// 1. extract(opts) with no `file`: tar 7 returned a writable stream to pipe an archive into +// (node-gyp's header download, node-pre-gyp's binary download). tar 8 takes the archive as +// `input` and returns a Promise. +// 2. extract({sync: true, ...}): tar 7 had finished by the time it returned (sqlite3's +// deps/extract.js deletes a file from the extracted tree on the next line). tar 8 ignores +// `sync`; the synchronous form is extractSync(). +const tar = require('tar8'); +const { PassThrough, Writable, Readable } = require('stream'); + +function extract(opts = {}, ...rest) { + if (opts.sync) { + const { sync, ...others } = opts; // eslint-disable-line no-unused-vars + return tar.extractSync(others, ...rest); + } + if (opts.file || opts.input) { + return tar.extract(opts, ...rest); + } + const archive = new PassThrough(); + const done = tar.extract({ ...opts, input: Readable.toWeb(archive) }); + done.catch(() => {}); // reported through final(), below + return new Writable({ + write: (chunk, encoding, callback) => (archive.write(chunk, encoding) ? callback() : archive.once('drain', callback)), + final: (callback) => { archive.end(); done.then(() => callback(), callback); }, + destroy: (error, callback) => { archive.destroy(error); callback(error); } + }); +} + +module.exports = { ...tar, extract, x: extract }; diff --git a/vendor/tar-stream-shim/package.json b/vendor/tar-stream-shim/package.json new file mode 100644 index 000000000..23368bcbc --- /dev/null +++ b/vendor/tar-stream-shim/package.json @@ -0,0 +1,11 @@ +{ + "name": "tar-stream-shim", + "version": "1.0.0", + "description": "tar 8 with the two tar 7 call forms that node-gyp, @mapbox/node-pre-gyp and sqlite3 still use at install time", + "main": "index.js", + "license": "BSD-3-Clause", + "private": true, + "dependencies": { + "tar8": "npm:tar@^8.1.2" + } +} From 0946eefa9bbc1cb27da0fa62dda301efaebdd4bf Mon Sep 17 00:00:00 2001 From: Josh Mandel Date: Thu, 3 Dec 2026 15:30:08 -0600 Subject: [PATCH 2/7] Approve the install scripts of sqlite3, better-sqlite3 and roaring npm 12 (and recent npm 11) runs a dependency's install script only when the project approves it in package.json allowScripts. Without that, npm install finishes without error and these three packages have no native binary, so the server cannot open a database. Older npm ignores the field. Co-Authored-By: Claude --- CHANGELOG.md | 1 + package.json | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 697743319..c0d6389ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Packages are read with tar 8 (was 7, which has 16 high advisories, most of them ways for an archive's links to get out of the folder it is extracted into): the package manager (the tx module's packages) and the packages crawler, which read packages from elsewhere. A package is unzipped against the unpacked size limit as before, and a second layer of compression inside one is now refused - No tar 7 is installed any more. sqlite3, node-gyp and @mapbox/node-pre-gyp (under roaring) each asked for tar 7, which they use while installing to unpack a prebuilt binary, the Node headers or the SQLite source, and none has a release on tar 8. package.json `overrides` now gives them tar 8, through a small adapter for the two calls tar 8 changed (vendor/README.md). The tar advisory is gone from audit-allowlist.json +- npm versions that only run the install scripts a project approves (npm 12, and recent npm 11) left sqlite3, better-sqlite3 and roaring without their native binary after `npm install`, with no error. package.json `allowScripts` now approves those three ### Added diff --git a/package.json b/package.json index 9ac8f6e0d..1905522c7 100644 --- a/package.json +++ b/package.json @@ -137,5 +137,10 @@ "bugs": { "url": "https://github.com/HealthIntersections/fhirsmith/issues" }, - "homepage": "https://github.com/HealthIntersections/fhirsmith#readme" + "homepage": "https://github.com/HealthIntersections/fhirsmith#readme", + "allowScripts": { + "roaring": true, + "sqlite3": true, + "better-sqlite3": true + } } From 24f27c0989b3a8e9f5d488b3a01775d7b7945699 Mon Sep 17 00:00:00 2001 From: Josh Mandel Date: Thu, 3 Dec 2026 15:31:48 -0600 Subject: [PATCH 3/7] Ask for Node 24: roaring has no build for Node 26 Co-Authored-By: Claude --- CHANGELOG.md | 1 + README.md | 2 +- package-lock.json | 2 +- package.json | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0d6389ef..dfcdceaa3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Packages are read with tar 8 (was 7, which has 16 high advisories, most of them ways for an archive's links to get out of the folder it is extracted into): the package manager (the tx module's packages) and the packages crawler, which read packages from elsewhere. A package is unzipped against the unpacked size limit as before, and a second layer of compression inside one is now refused - No tar 7 is installed any more. sqlite3, node-gyp and @mapbox/node-pre-gyp (under roaring) each asked for tar 7, which they use while installing to unpack a prebuilt binary, the Node headers or the SQLite source, and none has a release on tar 8. package.json `overrides` now gives them tar 8, through a small adapter for the two calls tar 8 changed (vendor/README.md). The tar advisory is gone from audit-allowlist.json - npm versions that only run the install scripts a project approves (npm 12, and recent npm 11) left sqlite3, better-sqlite3 and roaring without their native binary after `npm install`, with no error. package.json `allowScripts` now approves those three +- package.json `engines` asks for Node 24, not 24 or later: on Node 26 roaring 2.7.0 has no prebuilt binary and does not compile, and as an optional dependency it is left out without an error, so the sqlite-v2 providers cannot load ### Added diff --git a/README.md b/README.md index 038589cb6..679832961 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ During development with a cloned repository, the data directory defaults to `[ro is provided by the host — see Deployment below. ### Prerequisites -- Node.js 24+ +- Node.js 24 (not 26 yet: roaring, which the sqlite-v2 terminology providers need, has no build for it) - NPM or Yarn - Java 17+ (for FHIR validator, also for the test cases) diff --git a/package-lock.json b/package-lock.json index 245a0b6b5..8b890b5a8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -68,7 +68,7 @@ "tmp": "^0.2.5" }, "engines": { - "node": ">=24" + "node": "^24" }, "optionalDependencies": { "koffi": "^3.3.6", diff --git a/package.json b/package.json index 1905522c7..425bd9a92 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "description": "A Node.js server that provides a collection of tools to serve the FHIR ecosystem", "main": "server.js", "engines": { - "node": ">=24" + "node": "^24" }, "scripts": { "start": "node --expose-gc server.js", From 7dabee921cc33a8a2524082a5d5f821b1e910a0f Mon Sep 17 00:00:00 2001 From: Josh Mandel Date: Thu, 3 Dec 2026 15:43:33 -0600 Subject: [PATCH 4/7] tar shim: an extraction error ends the write instead of hanging it When tar stopped reading part way (not an archive, a bad entry), the stream handed to node-gyp and node-pre-gyp waited for a drain that never came, so a failed download hung the install instead of failing it. The error now destroys the stream. Also treat tar's f alias as file. Co-Authored-By: Claude --- package-lock.json | 6 +++--- vendor/tar-stream-shim-1.0.0.tgz | Bin 1049 -> 1193 bytes vendor/tar-stream-shim/index.js | 18 ++++++++++++++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8b890b5a8..cd7828b87 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1938,7 +1938,7 @@ "name": "tar-stream-shim", "version": "1.0.0", "resolved": "file:vendor/tar-stream-shim-1.0.0.tgz", - "integrity": "sha512-/FbyFhKmsOQ3fZo9E3vf4hs5Rm8Y+O7MYcS4yDosAYg6YCWb6UeAQNvrTz4iQ1sbbNiPYKhdVYKj8ybE7laLwg==", + "integrity": "sha512-+wZjAAA69cxXKASR20ipmvuWTKoNIQjw/HRdNO8SMQADPx29xcZhO+EMECUOA2EDfACEBliEh7jmK/NZN+IKTw==", "license": "BSD-3-Clause", "optional": true, "dependencies": { @@ -7861,7 +7861,7 @@ "name": "tar-stream-shim", "version": "1.0.0", "resolved": "file:vendor/tar-stream-shim-1.0.0.tgz", - "integrity": "sha512-/FbyFhKmsOQ3fZo9E3vf4hs5Rm8Y+O7MYcS4yDosAYg6YCWb6UeAQNvrTz4iQ1sbbNiPYKhdVYKj8ybE7laLwg==", + "integrity": "sha512-+wZjAAA69cxXKASR20ipmvuWTKoNIQjw/HRdNO8SMQADPx29xcZhO+EMECUOA2EDfACEBliEh7jmK/NZN+IKTw==", "license": "BSD-3-Clause", "optional": true, "dependencies": { @@ -9321,7 +9321,7 @@ "name": "tar-stream-shim", "version": "1.0.0", "resolved": "file:vendor/tar-stream-shim-1.0.0.tgz", - "integrity": "sha512-/FbyFhKmsOQ3fZo9E3vf4hs5Rm8Y+O7MYcS4yDosAYg6YCWb6UeAQNvrTz4iQ1sbbNiPYKhdVYKj8ybE7laLwg==", + "integrity": "sha512-+wZjAAA69cxXKASR20ipmvuWTKoNIQjw/HRdNO8SMQADPx29xcZhO+EMECUOA2EDfACEBliEh7jmK/NZN+IKTw==", "license": "BSD-3-Clause", "dependencies": { "tar8": "npm:tar@^8.1.2" diff --git a/vendor/tar-stream-shim-1.0.0.tgz b/vendor/tar-stream-shim-1.0.0.tgz index c8768306483c00d9b98d9765a245a3ee8b99b753..923b95f692d9d9faacddbfd88467239851dea68f 100644 GIT binary patch literal 1193 zcmV;a1XlYWiwFP!00002|Ls>zZ{s!)_1VAT!52$_EXnzXjTGB<_gG-DDX_P~v^b8q zkw`5`*)g*I?*&OocCrOp6m5VOnTwnu`8e;*keoEEcwqOG3CZa({bEM{g5`OBb#Z|| z^5=Peem&1II={Ti=ku$p`~stVo?o9`VU&+v!CGUP9_9HzKr+vB4B!8VWf?5fxJj@R zwuCJScBj1W8U?E=Y?Q7IY{{%271CJeHiZ_AHBcLz$AzHS_w<%35*Ki%ASXZ_F)rGaYuwLNv?GE>BEojfBBHsJRN751D~g$N2^(3 zBh^?F2UVoPY9lIIEjmC=w$+k27EKsFHmzNGIYNvE3?H?sg(1fg zXGelhW-p5ctZpemnx==ir<LjgZ2W#IfFost`3n*dz6*(|g))&Z#k32cCX0;8c+% z7l6|a8?9=O)J-7{tBIhb_ey%SsDz|}r?{6&(?HEdyIT6W?q{i$RITyl=@Q(b-tA=( z#p$?E(pV343r$~Jp(&bLrf;V4vKxHDM`p~grB>~Inc#Dm$ONB=ai7w|>Ee)Iw|u;5 zWnqPq&uRs?csh6?H5nV@X$*)B{8;KD4lbbI-TC}{WlPe=@8%{ik!2uL32A3s7#GRR z2?MESt!xeP*_LVJu|hT+&-7G)fOrgMIR*}=@%W5<`-bqx@XMD^ALsYje(m?DflyzJ zw~(|ul{WGdyWv#HXi8cuJxvhBxcvc7huBlr)F|!CBCPYN9?C7qpI}Xu+6|j>CEbpv zF+O=oeW0GsV#sG|)n{5qT_iCMKCl4Po!$_9UkXtW!X0s1AS%jMJ|rMnC@$oE;_t^b zD;@$3KR0OHljUTrR(s-3;oj-tUV_E(0Du8EDCg_|stlb>Im%g3H07EJIXwwzSm(co z#D6wIvdZyz7WM!|l1K5UlJ1JNC%10`hBf0LY4tu{1blZd7^@ls zP0Y#fU}g7mP)N8&-5QHE!K#WUP}*I8J0{$tC&A!F?_L_(l18Cwa>vpuSTI|ZQAf{d z5i0D35T0;%(87e}_%I&VinkS|^yp56zgb*STc(p<1tvgj^YN9V>t$fjOcrr-T`lg`t#iGS}7 zN>{)Y1h>^e_XasHORTl2EL_1|uu5f}SKHjk+F9r|bYq~nlN*Adnv@`wOR~c>g>|wl z(O6=r+eu@etyUQ64H+W^*%9i-d36xkzx%Xl${Piksch9<#PnaQumE=tUoZ+YWvyRo%E{C`X&41;+=YD{0Ad z#Oy?HZ+9x6!FvbpXPp{wtYpJ9yNMN;Vr$SZ)=}y$6uHNH5xS-mm9XR`JA*dur zJ^^1ltc|V$Qs+Vf&JaPXpjGtjP)bEdp7K#?Lq}>p+vOto`mcr2N;fu)r*CkF`mj@Z z6tiKjm30B=9)`X&(oi&Z+}w@hMQ7aO1Go0K!szC)Nbsp^WP*>xMQG{a{BYY}e|)%Z zRPLl!f0`BCV}A&RG-O?j{Sc6A1RL`iw<@5I?sdUmyMl}j(Y*5lX$rEXRBj@q^_fh3 zVW9M+QH>=r*>Gb6R@)8Flbsi!MLZ?57y^g$d_qUQehu+h7@9u2ZxO?ZZ?Re${RrMe z(e}KcQE+UXgjU|;9CIIt2jCEXeylok`V+094midk0C@<@7$l%ZOi zFidS+Ke)V%;sh%y^>%n<8KISNQh&vLA-SN{gl>M$f*=Va9#q95+cn{0W}t{dXJ| z!@)(qBk5k{^!#;x-Tg1SzP*0A|4nahW|#f%HN;k48|dlWc?eZkbH~lw-|yIz%|_wnJ6vwK Ti(KR){|os8oZ=|~01^NIdN>o3 diff --git a/vendor/tar-stream-shim/index.js b/vendor/tar-stream-shim/index.js index 431cecf8e..3147c1377 100644 --- a/vendor/tar-stream-shim/index.js +++ b/vendor/tar-stream-shim/index.js @@ -16,17 +16,27 @@ function extract(opts = {}, ...rest) { const { sync, ...others } = opts; // eslint-disable-line no-unused-vars return tar.extractSync(others, ...rest); } - if (opts.file || opts.input) { + if (opts.file || opts.f || opts.input) { return tar.extract(opts, ...rest); } const archive = new PassThrough(); + archive.on('error', () => {}); // reported through the returned stream, below const done = tar.extract({ ...opts, input: Readable.toWeb(archive) }); - done.catch(() => {}); // reported through final(), below - return new Writable({ - write: (chunk, encoding, callback) => (archive.write(chunk, encoding) ? callback() : archive.once('drain', callback)), + const stream = new Writable({ + write: (chunk, encoding, callback) => { + if (archive.destroyed || archive.write(chunk, encoding)) { + callback(); + } else { + archive.once('drain', callback); + } + }, final: (callback) => { archive.end(); done.then(() => callback(), callback); }, destroy: (error, callback) => { archive.destroy(error); callback(error); } }); + // extraction can fail before the archive has all been written (not an archive, a bad entry): + // tar stops reading then, so the writer must be told, or it waits on a drain that never comes + done.catch((error) => stream.destroy(error)); + return stream; } module.exports = { ...tar, extract, x: extract }; From a7c705ec7acbadb97c9861d3f345b06c84adbf75 Mon Sep 17 00:00:00 2001 From: Josh Mandel Date: Thu, 3 Dec 2026 15:43:33 -0600 Subject: [PATCH 5/7] Audit of a published install accepts tar 7, with the reason; say what the overrides cover npm doesn't apply a package's overrides when it is installed from the registry, so npm install fhirsmith still gets tar 7 under sqlite3, node-gyp and node-pre-gyp. The fresh install audit has its own allowlist for that (audit-allowlist-published.json), and audit-check.js takes an entry for a whole package, so the next tar 7 advisory doesn't fail a check nothing can be done about. The changelog and vendor/README.md say the overrides cover a clone and the Docker image only. vendor/ is left out of the published package, and the Install check fails if the packed shim and its source differ. Co-Authored-By: Claude --- .github/workflows/install-check.yml | 8 ++++++++ .github/workflows/pr-pipeline.yml | 5 +++-- .npmignore | 1 + CHANGELOG.md | 2 +- audit-allowlist-published.json | 6 ++++++ tests/utilities/audit-check.test.js | 11 +++++++++++ utilities/audit-check.js | 20 ++++++++++++++------ vendor/README.md | 6 +++++- 8 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 audit-allowlist-published.json diff --git a/.github/workflows/install-check.yml b/.github/workflows/install-check.yml index 5072f4016..304ef8f3d 100644 --- a/.github/workflows/install-check.yml +++ b/.github/workflows/install-check.yml @@ -40,6 +40,12 @@ jobs: node-version: '24' cache: 'npm' + - name: Check the packed shim is the one in vendor/tar-stream-shim + run: | + mkdir "$RUNNER_TEMP/shim" + tar -xzf vendor/tar-stream-shim-1.0.0.tgz -C "$RUNNER_TEMP/shim" + diff -r --strip-trailing-cr vendor/tar-stream-shim "$RUNNER_TEMP/shim/package" + - name: Install dependencies run: npm ci @@ -79,6 +85,8 @@ jobs: }); ' + # node-gyp is found at node_modules/node-gyp (npm puts it there for sqlite3 and roaring); if a + # dependency change moves it, this step fails at once, and the path needs changing. # The build unpacks the SQLite source with tar (node_modules/sqlite3/deps/extract.js) and # then deletes its VERSION file, which on macOS and Windows hides the C++ header - name: Build sqlite3 from source diff --git a/.github/workflows/pr-pipeline.yml b/.github/workflows/pr-pipeline.yml index db853c81b..5100e8dd4 100644 --- a/.github/workflows/pr-pipeline.yml +++ b/.github/workflows/pr-pipeline.yml @@ -70,14 +70,15 @@ jobs: # npm ignores package.json "overrides" when FHIRsmith is installed (npm install -g fhirsmith) # rather than cloned, and the published package has no lock file. So the repo's own audit can # be clean while installed servers get vulnerable transitive versions. This installs the - # package the way users do, into an empty folder, and audits what that actually gets + # package the way users do, into an empty folder, and audits what that actually gets. + # It has its own allowlist: what only an override can fix is accepted there, with the reason run: | npm pack --pack-destination "$RUNNER_TEMP" mkdir "$RUNNER_TEMP/fresh-install" cd "$RUNNER_TEMP/fresh-install" npm init -y > /dev/null npm install --ignore-scripts --no-audit --no-fund "$RUNNER_TEMP"/fhirsmith-*.tgz - node "$GITHUB_WORKSPACE/utilities/audit-check.js" --omit=dev --audit-level=moderate + node "$GITHUB_WORKSPACE/utilities/audit-check.js" --omit=dev --audit-level=moderate --allowlist="$GITHUB_WORKSPACE/audit-allowlist-published.json" dependency-check: name: Dependency Analysis diff --git a/.npmignore b/.npmignore index c98d422a8..a255b9467 100644 --- a/.npmignore +++ b/.npmignore @@ -63,6 +63,7 @@ docs/ # Release and development scripts, and test reports release.sh +vendor/ changelog-template.md tsconfig.eslint.json test-scripts/ diff --git a/CHANGELOG.md b/CHANGELOG.md index dfcdceaa3..4b06e0d9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Security - Packages are read with tar 8 (was 7, which has 16 high advisories, most of them ways for an archive's links to get out of the folder it is extracted into): the package manager (the tx module's packages) and the packages crawler, which read packages from elsewhere. A package is unzipped against the unpacked size limit as before, and a second layer of compression inside one is now refused -- No tar 7 is installed any more. sqlite3, node-gyp and @mapbox/node-pre-gyp (under roaring) each asked for tar 7, which they use while installing to unpack a prebuilt binary, the Node headers or the SQLite source, and none has a release on tar 8. package.json `overrides` now gives them tar 8, through a small adapter for the two calls tar 8 changed (vendor/README.md). The tar advisory is gone from audit-allowlist.json +- A clone (`npm install`, `npm ci`) and the Docker image no longer install tar 7. sqlite3, node-gyp and @mapbox/node-pre-gyp (under roaring) each ask for tar 7, which they use while installing to unpack a prebuilt binary, the Node headers or the SQLite source, and none has a release on tar 8. package.json `overrides` now gives them tar 8, through a small adapter for the two calls tar 8 changed (vendor/README.md). The tar advisories are gone from audit-allowlist.json. npm doesn't apply a package's `overrides` when the package is installed from the registry, so `npm install fhirsmith` still gets tar 7 under those three until they move to tar 8; the pipeline's audit of a published install accepts that, in audit-allowlist-published.json - npm versions that only run the install scripts a project approves (npm 12, and recent npm 11) left sqlite3, better-sqlite3 and roaring without their native binary after `npm install`, with no error. package.json `allowScripts` now approves those three - package.json `engines` asks for Node 24, not 24 or later: on Node 26 roaring 2.7.0 has no prebuilt binary and does not compile, and as an optional dependency it is left out without an error, so the sqlite-v2 providers cannot load diff --git a/audit-allowlist-published.json b/audit-allowlist-published.json new file mode 100644 index 000000000..6dac07ccc --- /dev/null +++ b/audit-allowlist-published.json @@ -0,0 +1,6 @@ +{ + "comment": "Advisories the CI audit of a fresh install of the published package accepts, on top of nothing else (utilities/audit-check.js --allowlist). npm ignores package.json overrides for an installed package, so what FHIRsmith's overrides fix for a clone or the Docker image is still there for npm install fhirsmith.", + "advisories": [{ "package": "tar", "until": "2027-03-01", + "reason": "tar <8: sqlite3 6.0.1, node-gyp 12 and @mapbox/node-pre-gyp 2.0.3 (under roaring) depend on tar 7 and have no release on tar 8. A clone or the Docker image gets tar 8 under them through package.json overrides (vendor/README.md); npm doesn't apply overrides to an installed package, so npm install fhirsmith still gets their tar 7. They use it only while installing, on archives from fixed sources. FHIRsmith's own tar is 8. Remove once they move to tar 8" + }] +} diff --git a/tests/utilities/audit-check.test.js b/tests/utilities/audit-check.test.js index 58db1a6f9..2b373dd4b 100644 --- a/tests/utilities/audit-check.test.js +++ b/tests/utilities/audit-check.test.js @@ -44,4 +44,15 @@ describe('audit-check', () => { const allow = { advisories: [{ id: 'GHSA-aaaa-bbbb-cccc' }] }; expect(check(advisories(report), allow, 'high', '2026-11-18').unused).toHaveLength(1); }); + + test('a package entry accepts every advisory against that package, and no other', () => { + const allow = { advisories: [{ package: 'glob', until: '2099-01-01' }, { package: 'tar', until: '2099-01-01' }] }; + const r = check(advisories(report), allow, 'moderate', '2026-11-18'); + expect(r.accepted.map(a => a.id)).toEqual(['GHSA-3g3m-2fjr-6pw4']); + expect(r.failures.map(a => a.id)).toEqual(['GHSA-fc5q-39xc-vjpf']); + expect(r.unused.map(e => e.package)).toEqual(['tar']); + const late = check(advisories(report), allow, 'moderate', '2099-01-02'); + expect(late.accepted).toEqual([]); + expect(late.expired.length).toBe(2); + }); }); diff --git a/utilities/audit-check.js b/utilities/audit-check.js index bbaaa3503..3428ce68e 100644 --- a/utilities/audit-check.js +++ b/utilities/audit-check.js @@ -11,7 +11,10 @@ // defaults to the one at the repository root. // // Allowlist entries: { "id": "GHSA-...", "reason": "...", "until": "YYYY-MM-DD" }. An entry -// past its date no longer applies, so it can't quietly outlive the reason for it. +// past its date no longer applies, so it can't quietly outlive the reason for it. An entry +// with "package" in place of "id" accepts every advisory against that package, for a package +// that can't be updated where it is audited: new advisories against it would fail the check +// with nothing to be done about them. const { execFileSync } = require('child_process'); const fs = require('fs'); @@ -69,6 +72,7 @@ function check(found, allowlist, level, today = new Date().toISOString().substri const min = LEVELS.indexOf(level); const entries = (allowlist && allowlist.advisories) || []; const active = new Map(); + const packages = new Map(); const expired = []; for (const e of entries) { const id = String(e.id || '').toUpperCase(); @@ -76,6 +80,8 @@ function check(found, allowlist, level, today = new Date().toISOString().substri expired.push(e); } else if (id) { active.set(id, e); + } else if (e.package) { + packages.set(e.package, e); } } const failures = []; @@ -84,14 +90,16 @@ function check(found, allowlist, level, today = new Date().toISOString().substri if (LEVELS.indexOf(a.severity) < min) { continue; } - if (active.has(a.id.toUpperCase())) { + if (active.has(a.id.toUpperCase()) || packages.has(a.name)) { accepted.push(a); } else { failures.push(a); } } const seen = new Set(found.map(a => a.id.toUpperCase())); - const unused = [...active.values()].filter(e => !seen.has(String(e.id).toUpperCase())); + const names = new Set(found.map(a => a.name)); + const unused = [...active.values()].filter(e => !seen.has(String(e.id).toUpperCase())) + .concat([...packages.values()].filter(e => !names.has(e.package))); return { failures, accepted, expired, unused }; } @@ -118,13 +126,13 @@ function main() { } const result = check(advisories(report), allowlist, args.level); for (const a of result.accepted) { - console.log(`accepted (audit-allowlist.json): ${a.id} ${a.name} ${a.range} (${a.severity}) - ${a.title}`); + console.log(`accepted (${path.basename(args.allowlist)}): ${a.id} ${a.name} ${a.range} (${a.severity}) - ${a.title}`); } for (const e of result.expired) { - console.log(`::warning::audit-allowlist.json entry ${e.id} expired on ${e.until}: it no longer applies - look at it again`); + console.log(`::warning::${path.basename(args.allowlist)} entry ${e.id || e.package} expired on ${e.until}: it no longer applies - look at it again`); } for (const e of result.unused) { - console.log(`::warning::audit-allowlist.json entry ${e.id} matches nothing any more: remove it`); + console.log(`::warning::${path.basename(args.allowlist)} entry ${e.id || e.package} matches nothing any more: remove it`); } for (const a of result.failures) { console.log(`::error::${a.id} ${a.name} ${a.range} (${a.severity}) - ${a.title} ${a.url || ''}`); diff --git a/vendor/README.md b/vendor/README.md index 5d143cac4..b1272fa21 100644 --- a/vendor/README.md +++ b/vendor/README.md @@ -21,13 +21,17 @@ calls they make: `tar-stream-shim` is tar 8 with those two calls as they were. package.json `overrides` installs it as `tar` under the three packages, so the only tar installed is tar 8. +This holds for a clone and for the Docker image. npm doesn't apply a package's `overrides` when +the package is itself installed (`npm install fhirsmith`), so an install from the registry still +gets tar 7 under the three; `vendor/` is not in the published package. + The override names the packed file, `tar-stream-shim-1.0.0.tgz`, not the directory: npm links a directory named in an override from the wrong place. After changing `tar-stream-shim/`: cd vendor/tar-stream-shim && npm pack --pack-destination .. and update the three `node_modules/*/node_modules/tar` entries' `integrity` in -package-lock.json. npm (11 and 12) fails to add these entries to an existing package-lock.json +package-lock.json (the Install check workflow fails if the `.tgz` and the directory differ). npm (11 and 12) fails to add these entries to an existing package-lock.json by itself (it looks for the file under the package the override is for); they were written to a new lock file and copied in. From e06385fda174d06480594e16ee7342948782d1fa Mon Sep 17 00:00:00 2001 From: Josh Mandel Date: Thu, 3 Dec 2026 15:51:04 -0600 Subject: [PATCH 6/7] Install check: compare the packed shim with node, not tar and diff; approve bcrypt's install script Git for Windows' tar could not open the runner's temp folder. bcrypt carries prebuilt binaries, and its install script builds it where there is none. The allowScripts and engines changelog entries move from Security to Changed. Co-Authored-By: Claude --- .github/workflows/install-check.yml | 20 ++++++++++++++------ CHANGELOG.md | 4 ++-- package.json | 3 ++- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.github/workflows/install-check.yml b/.github/workflows/install-check.yml index 304ef8f3d..89944a795 100644 --- a/.github/workflows/install-check.yml +++ b/.github/workflows/install-check.yml @@ -40,15 +40,23 @@ jobs: node-version: '24' cache: 'npm' - - name: Check the packed shim is the one in vendor/tar-stream-shim - run: | - mkdir "$RUNNER_TEMP/shim" - tar -xzf vendor/tar-stream-shim-1.0.0.tgz -C "$RUNNER_TEMP/shim" - diff -r --strip-trailing-cr vendor/tar-stream-shim "$RUNNER_TEMP/shim/package" - - name: Install dependencies run: npm ci + - name: Check the packed shim is the one in vendor/tar-stream-shim + run: | + node -e ' + const fs = require("fs"), path = require("path"), tar = require("tar"); + const out = fs.mkdtempSync(path.join(process.env.RUNNER_TEMP, "shim-")); + tar.extractSync({ file: "vendor/tar-stream-shim-1.0.0.tgz", cwd: out }); + const read = (dir) => Object.fromEntries(fs.readdirSync(dir).sort().map((name) => + [name, fs.readFileSync(path.join(dir, name), "utf8").replace(/\r\n/g, "\n")])); + const source = read("vendor/tar-stream-shim"), packed = read(path.join(out, "package")); + const differ = [...new Set([...Object.keys(source), ...Object.keys(packed)])].filter((name) => source[name] !== packed[name]); + if (differ.length > 0) { console.error("differ: " + differ.join(", ") + " - pack it again (vendor/README.md)"); process.exit(1); } + console.log("the same: " + Object.keys(source).join(", ")); + ' + - name: Check no tar older than 8 is installed run: | node -e ' diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b06e0d9a..9cec656e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,8 +11,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Packages are read with tar 8 (was 7, which has 16 high advisories, most of them ways for an archive's links to get out of the folder it is extracted into): the package manager (the tx module's packages) and the packages crawler, which read packages from elsewhere. A package is unzipped against the unpacked size limit as before, and a second layer of compression inside one is now refused - A clone (`npm install`, `npm ci`) and the Docker image no longer install tar 7. sqlite3, node-gyp and @mapbox/node-pre-gyp (under roaring) each ask for tar 7, which they use while installing to unpack a prebuilt binary, the Node headers or the SQLite source, and none has a release on tar 8. package.json `overrides` now gives them tar 8, through a small adapter for the two calls tar 8 changed (vendor/README.md). The tar advisories are gone from audit-allowlist.json. npm doesn't apply a package's `overrides` when the package is installed from the registry, so `npm install fhirsmith` still gets tar 7 under those three until they move to tar 8; the pipeline's audit of a published install accepts that, in audit-allowlist-published.json -- npm versions that only run the install scripts a project approves (npm 12, and recent npm 11) left sqlite3, better-sqlite3 and roaring without their native binary after `npm install`, with no error. package.json `allowScripts` now approves those three -- package.json `engines` asks for Node 24, not 24 or later: on Node 26 roaring 2.7.0 has no prebuilt binary and does not compile, and as an optional dependency it is left out without an error, so the sqlite-v2 providers cannot load ### Added @@ -20,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- npm versions that only run the install scripts a project approves (npm 12, and recent npm 11) left sqlite3, better-sqlite3 and roaring without their native binary after `npm install`, with no error. package.json `allowScripts` now approves those three, and bcrypt (which comes with binaries for the usual platforms, and builds from source elsewhere) +- package.json `engines` asks for Node 24, not 24 or later: on Node 26 roaring 2.7.0 has no prebuilt binary and does not compile, and as an optional dependency it is left out without an error, so the sqlite-v2 providers cannot load - tx: `check-system-version` never influences which version of a code system is used (community decision on Zulip, Terminology Service Test Cases, check-system-version semantics): the version is chosen as if it weren't there - from the coding, the value set, `system-version`/`force-system-version`, or the default - and the operation fails (`VALUESET_VERSION_CHECK`) if that version doesn't match. Before, when nothing else named a version, the check's version was used. This includes the edition of an implicit SNOMED CT value set, and `$closure` tables. It is no longer echoed in expansion parameters. `check-valueset-version` is unchanged - tx-import: the sqlite-v2 importers (`loinc-v2`, `loinc-v2-classic`, `snomed-v2`, `snomed-v2-from-cache`, `rxnorm-v2`) take the classic importers' options: `-v, --version` for the release's version (`snomed-v2`'s was `--snomed-version`) and `-y, --yes` to replace an existing destination; without `-y` an existing destination is asked about. The earlier names (`--loinc-version`, `--rxnorm-version`, `--snomed-version`, `--overwrite`) still work. Documented in tx/importers/readme.md diff --git a/package.json b/package.json index 425bd9a92..cc946e1f0 100644 --- a/package.json +++ b/package.json @@ -141,6 +141,7 @@ "allowScripts": { "roaring": true, "sqlite3": true, - "better-sqlite3": true + "better-sqlite3": true, + "bcrypt": true } } From 7ee5293983fe4e9e7241d30b2fa9e0f17728f781 Mon Sep 17 00:00:00 2001 From: Josh Mandel Date: Thu, 3 Dec 2026 15:58:31 -0600 Subject: [PATCH 7/7] vendor/README.md: when and how to remove the tar shim and its overrides Co-Authored-By: Claude --- vendor/README.md | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/vendor/README.md b/vendor/README.md index b1272fa21..fe5d4dfa3 100644 --- a/vendor/README.md +++ b/vendor/README.md @@ -35,5 +35,35 @@ package-lock.json (the Install check workflow fails if the `.tgz` and the direct by itself (it looks for the file under the package the override is for); they were written to a new lock file and copied in. -Remove all of this - the directory, the `.tgz`, the three `overrides`, and the `COPY` in the -Dockerfile - once `sqlite3`, `node-gyp` and `@mapbox/node-pre-gyp` depend on tar 8. +### When and how to remove it + +Each of the three overrides can go as soon as its package depends on tar 8 or later. To see what +the latest releases ask for: + + npm view sqlite3 dependencies.tar + npm view node-gyp dependencies.tar + npm view @mapbox/node-pre-gyp dependencies.tar + +An override can also go when its package is no longer installed at all (`npm ls node-gyp +@mapbox/node-pre-gyp sqlite3`): `@mapbox/node-pre-gyp` is there only for `roaring`, and +`node-gyp` only for `roaring` and `sqlite3`. + +For a package that has moved to tar 8: + +1. Update to that release (for `node-gyp` and `@mapbox/node-pre-gyp` that means a release of + `roaring` or `sqlite3` that depends on it, or `npm update`). +2. Delete its entry from `overrides` in package.json and run `npm install`. +3. `npm ls tar` should show no tar older than 8 and, for that package, a `tar` from the registry + rather than `tar-stream-shim`. The Install check workflow checks the same on Linux, macOS and + Windows, and that sqlite3 still builds from source. + +When the last of the three overrides is gone, delete `vendor/tar-stream-shim/`, the `.tgz`, this +section, the `COPY vendor/...` line in the Dockerfile, `vendor/` in `.npmignore`, the "Check the +packed shim" step in `.github/workflows/install-check.yml`, and the `tar` entry in +`audit-allowlist-published.json` (the audit says when it matches nothing any more). That entry +has an expiry date so that this gets looked at again even if nobody is watching the three +packages. + +Until then nothing needs doing when tar itself has a new 8.x release: the shim depends on +`tar ^8`, and passes everything but the two calls straight through. A tar 9 would need the two +calls checked again.