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
2 changes: 2 additions & 0 deletions .github/workflows/npm-pack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ jobs:
- run: node npm/fake-engines.mjs "$RUNNER_TEMP/engines"
- run: node npm/build.mjs --engines "$RUNNER_TEMP/engines" --out npm/dist
- run: node npm/publish.mjs --out npm/dist --dry-run --pack-dir npm/packed
- name: The installed engine still matches its built-in digest (npm drops symlinks)
run: node npm/verify-packed.mjs npm/packed
- name: Every tarball has what it should (and no source, tests or scripts)
run: |
set -e
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to sqlguardllm are documented here. The format follows [Keep

## [Unreleased]

### Fixed
- **npm: the macOS engine packages could not run.** npm does not keep symlinks in packages, and the macOS engine (Python.framework) has four, so after `npm install` its digest no longer matched the built-in one and the client refused to start it (`engine_digest_mismatch`). The packages now carry real copies instead of symlinks, and CI unpacks every packed platform package and checks the digest of the installed engine, which a file list cannot show. Affects 0.5.0-alpha.5 and 0.5.0-alpha.6 on macOS (Linux and Windows were not affected).


## [0.5.0a6] - 2026-11-27

The NuGet package now carries the engine for five runtimes and the integrations package is published with it; Node and .NET local mode are tested on Linux, macOS and Windows.
Expand Down
21 changes: 19 additions & 2 deletions clients/node/npm/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// at publish time so the development lockfile does not need packages that are not on the registry yet.
// Node.js standard library only.
import { createHash } from "node:crypto";
import { cpSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, readlinkSync, rmSync, writeFileSync } from "node:fs";
import { copyFileSync, cpSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, readlinkSync, rmSync, statSync, writeFileSync } from "node:fs";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";

Expand Down Expand Up @@ -38,6 +38,23 @@ export function digestTree(dir) {
return sha(lines.join(""));
}

/**
* Copy a folder, turning every symlink into a real copy of what it points to. npm packs files, not
* symlinks: one would vanish on install and the engine digest would no longer match. The macOS engine
* (PyInstaller, Python.framework) has some. (fs.cpSync({dereference}) still kept them in Node 24.)
*/
export function copyResolved(from, to) {
mkdirSync(to, { recursive: true });
for (const name of readdirSync(from)) {
const src = join(from, name);
const dst = join(to, name);
const st = statSync(src); // follows symlinks
if (st.isDirectory()) copyResolved(src, dst);
else if (st.isFile()) copyFileSync(src, dst);
else throw new Error(`special file in the engine: ${src}`);
}
}

export function platformManifest(key, version, repository) {
const p = platforms[key];
return {
Expand Down Expand Up @@ -73,7 +90,7 @@ function run(argv) {
}
const target = join(out, key);
mkdirSync(target, { recursive: true });
cpSync(join(unpacked, folder), join(target, "engine"), { recursive: true, verbatimSymlinks: true });
copyResolved(join(unpacked, folder), join(target, "engine"));
cpSync(join(root, "LICENSE"), join(target, "LICENSE"));
writeFileSync(join(target, "package.json"), JSON.stringify(platformManifest(key, pkg.version, pkg.repository), null, 2) + "\n");
digests.platforms[key] = digestTree(join(target, "engine"));
Expand Down
11 changes: 10 additions & 1 deletion clients/node/npm/fake-engines.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// node npm/fake-engines.mjs <dir>
// Writes <dir>/<platform>/sqlguardllm-engine-<platform>/ in the layout scripts/fetch-engine.py unpacks,
// so npm/build.mjs and npm/publish.mjs --dry-run can be exercised on every PR. They are never published.
import { chmodSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { chmodSync, mkdirSync, readFileSync, symlinkSync, writeFileSync } from "node:fs";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";

Expand All @@ -16,4 +16,13 @@ for (const [key, p] of Object.entries(platforms)) {
writeFileSync(join(folder, p.executable), `placeholder engine for ${key}\n`);
chmodSync(join(folder, p.executable), 0o755);
writeFileSync(join(folder, "_internal", "lib.bin"), "placeholder\n");
if (p.os === "darwin") {
// The real macOS engine has symlinks (Python.framework): npm drops them, so the build must not keep them.
const fw = join(folder, "_internal", "Python.framework");
mkdirSync(join(fw, "Versions", "3.12"), { recursive: true });
writeFileSync(join(fw, "Versions", "3.12", "Python"), "placeholder dylib\n");
symlinkSync("3.12", join(fw, "Versions", "Current"));
symlinkSync("Versions/Current/Python", join(fw, "Python"));
symlinkSync("Python.framework/Versions/3.12/Python", join(folder, "_internal", "Python"));
}
}
34 changes: 34 additions & 0 deletions clients/node/npm/verify-packed.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env node
// Install check for the packed platform packages: unpack each tarball the way `npm install` does and
// compare the digest of its engine folder with the one built into the main package.
// node npm/verify-packed.mjs npm/packed
// This catches what a file list cannot: things npm drops on the way (symlinks, empty folders), which
// would make the client refuse the installed engine.
import { execFileSync } from "node:child_process";
import { mkdtempSync, readdirSync, readFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { digestTree } from "./build.mjs";

const here = dirname(fileURLToPath(import.meta.url));
const dir = resolve(process.argv[2] ?? join(here, "packed"));
const digests = JSON.parse(readFileSync(join(here, "..", "src", "engine-digests.json"), "utf8"));
const platforms = JSON.parse(readFileSync(join(here, "platforms.json"), "utf8"));
let failed = 0;
for (const [key, p] of Object.entries(platforms)) {
const tgz = readdirSync(dir).find((n) => n.startsWith(`${p.package}-`) && n.endsWith(".tgz"));
if (!tgz) { console.error(`missing tarball for ${p.package}`); failed++; continue; }
const tmp = mkdtempSync(join(tmpdir(), "sqlguard-verify-"));
try {
execFileSync("tar", ["-xzf", join(dir, tgz), "-C", tmp]);
const actual = digestTree(join(tmp, "package", "engine"));
if (actual !== digests.platforms[key]) {
console.error(`${p.package}: installed engine digest ${actual} != built-in ${digests.platforms[key]}`);
failed++;
} else console.log(`${p.package}: installed engine matches the built-in digest`);
} finally {
rmSync(tmp, { recursive: true, force: true });
}
}
process.exit(failed ? 1 : 0);
12 changes: 10 additions & 2 deletions tests/test_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,18 @@ def test_redacted_removes_literals_and_context_values_never_appear(tmp_path: Pat
guard = Guard(standard_policy(), audit=AuditLog(path))
sql = f"SELECT id FROM invoices WHERE note = '{EMAIL}' AND customer_id = 48213 -- {EMAIL}"
assert guard.check(sql, {"user": {"branches": [7771, 7772], "name": "Zoe"}}).ok
text = path.read_text(encoding="utf-8")
(event,) = _events(path)
# Hex digests, ids, timestamps and durations are random-looking digits: a short number like
# 7772 can appear in them by chance, so the leak check looks only at fields that carry data.
readable = {
k: v
for k, v in event.items()
if k
not in {"policy_fingerprint", "sql_fingerprint", "event_id", "timestamp", "duration_ms"}
}
text = json.dumps(readable)
for secret in (EMAIL, "48213", "7771", "7772", "Zoe"):
assert secret not in text
(event,) = _events(path)
assert event["sql"] == "SELECT id FROM invoices WHERE note = ? AND customer_id = ?"
assert event["context_keys"] == ["user.branches", "user.name"]

Expand Down
Loading