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
107 changes: 107 additions & 0 deletions .github/workflows/install-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
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 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 '
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);
});
'

# 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++ <version> 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); })'
5 changes: 3 additions & 2 deletions .github/workflows/pr-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ docs/

# Release and development scripts, and test reports
release.sh
vendor/
changelog-template.md
tsconfig.eslint.json
test-scripts/
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
- 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

### Added

Expand All @@ -18,6 +19,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: the `cache-id` parameter is refused, wherever it is (a parameter, a part, a `$batch-validate-code` validation entry, the query): a 400 (`TX_PARAM_CACHE_ID_WITHDRAWN`) that says to start a cache with `$cache-control` and send its id in the `X-Cache-Id` header. The tx-ecosystem IG withdrew it (servers SHOULD NOT accept it); `$batch-validate-code` ignored it, so a bad cache-id went unnoticed. Clients from before June 2026 that send it already got 404 cache-id-unknown, as the server issues the ids
- tx: a media type (`urn:ietf:bcp:13`) is valid only if it follows the grammar of RFC 9110 section 8.3.1 / RFC 2045: a parameter with no name or no value, an unclosed quoted string, a value that isn't a token or a quoted string (an unquoted URI, say), and whitespace around the `/` or `=` or at the ends are invalid, and the issue says where (`MIMETYPE_INVALID`). A `;` in a quoted value is part of the value (it split the parameter, and broke the normal form)
- tx: `$subsumes` on a code system whose `hierarchyMeaning` is not is-a (part-of, grouped-by, classified-with) is refused (422, `SUBSUMPTION_CS_HIERARCHY_MEANING`), as core's: its hierarchy doesn't describe subsumption. `$closure` finds no subsumption in it
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions audit-allowlist-published.json
Original file line number Diff line number Diff line change
@@ -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"
}]
}
4 changes: 1 addition & 3 deletions audit-allowlist.json
Original file line number Diff line number Diff line change
@@ -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": []
}
Loading
Loading