23f7624596
ADR-166 MCP Bridge Security Lock / Static-source security lock (push) Failing after 0s
ADR-166 MCP Bridge Security Lock / Compose default binds loopback + Mongo has auth (push) Failing after 2s
CodeQL Advanced / Analyze (rust) (push) Failing after 0s
ADR-166 MCP Bridge Security Lock / plugin-agent-federation bindHost default (push) Failing after 1s
ADR-166 MCP Bridge Security Lock / Runtime behavior — 401 + terminal gate + fail-closed (push) Failing after 4s
business-pods-smoke / smoke (push) Failing after 1s
all-plugins-smoke / smoke-all (push) Failing after 2s
CI/CD Pipeline / Security & Code Quality (push) Failing after 1s
CI/CD Pipeline / Test Suite (ubuntu-latest) (push) Failing after 1s
CI/CD Pipeline / Build & Package (macos-latest) (push) Has been skipped
CI/CD Pipeline / Build & Package (ubuntu-latest) (push) Has been skipped
CI/CD Pipeline / Build & Package (windows-latest) (push) Has been skipped
CI/CD Pipeline / Documentation & Examples (push) Failing after 1s
Clone Tracker (14-day rolling) / Snapshot clones for ruflo ecosystem (push) Failing after 1s
CodeQL Advanced / Analyze (actions) (push) Failing after 1s
CodeQL Advanced / Analyze (javascript-typescript) (push) Failing after 1s
federation-peer-rust / stable-noop (push) Failing after 1s
metaharness-ci / score (push) Failing after 1s
metaharness-ci / router-compat (push) Failing after 0s
metaharness-ci / similarity-tests (push) Failing after 0s
no-agentbbs-smoke / smoke-without-agentbbs (push) Failing after 1s
V3 CI/CD Pipeline / Build V3 (windows-latest) (push) Has been skipped
codex-integration-audit / Codex integration audit (push) Failing after 1s
helpers-manifest-guard / guard (push) Failing after 1s
🔗 Cross-Agent Integration Tests / 🤝 Agent Coordination Tests (push) Has been skipped
🔗 Cross-Agent Integration Tests / 🧠 Memory Sharing Integration (push) Has been skipped
🔗 Cross-Agent Integration Tests / 🛡️ Fault Tolerance Tests (push) Has been skipped
🔗 Cross-Agent Integration Tests / ⚡ Performance Integration Tests (push) Has been skipped
metaharness-ci / mcp-scan (push) Failing after 1s
metaharness-ci / eject-dryrun (push) Failing after 1s
metaharness-ci / metaharness-real-data (push) Failing after 0s
no-cli-optdep-bloat-2561 / guard (push) Failing after 1s
no-metaharness-smoke / smoke-without-metaharness (push) Failing after 1s
no-phantom-agentic-flow-subpath / guard (push) Failing after 1s
🔄 Automated Rollback Manager / 🚨 Failure Detection (push) Failing after 1s
V3 CI/CD Pipeline / Plugin hooks smoke / ubuntu-latest / Node 22 (push) Failing after 1s
V3 CI/CD Pipeline / ruflo-graph-intelligence build + test smoke (#2044, ADR-123) (push) Failing after 1s
CVE Audit Gate / Audit root (critical-blocking) (push) Failing after 2s
cost-tracker-smoke / smoke (push) Failing after 3s
oia-audit-weekly / audit (push) Failing after 2s
ruflo-agent-smoke / ruflo-agent structural smoke (push) Failing after 1s
📊 Status Badges Update / 📊 Update Status Badges (push) Failing after 1s
V3 CI/CD Pipeline / Static regression guards (#2267 YAML + (push) Failing after 1s
V3 CI/CD Pipeline / Test V3 Packages (push) Failing after 0s
V3 CI/CD Pipeline / agent_execute provider routing smoke (#2042) (push) Failing after 0s
CVE Audit Gate / Audit v3 (critical-blocking) (push) Failing after 1s
federation-peer-rust / stable-native (push) Failing after 2s
🔗 Cross-Agent Integration Tests / 🚀 Integration Test Setup (push) Failing after 2s
neural-trader-smoke / runtime-smoke (push) Failing after 1s
V3 CI/CD Pipeline / Build V3 (macos-latest) (push) Has been skipped
V3 CI/CD Pipeline / Build V3 (ubuntu-latest) (push) Has been skipped
V3 CI/CD Pipeline / Type Check V3 (push) Failing after 1s
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / ubuntu-latest / Node 24 (push) Failing after 1s
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / ubuntu-latest / Node 22 (push) Failing after 2s
V3 CI/CD Pipeline / browser rvf create flag smoke (#2015) (push) Failing after 0s
V3 CI/CD Pipeline / Dependency review (#2046) (push) Has been skipped
V3 CI/CD Pipeline / Supply-chain audit (#2046) (push) Failing after 0s
V3 CI/CD Pipeline / witness marker drift smoke (#2021) (push) Failing after 1s
V3 CI/CD Pipeline / neural-trader portfolio CG smoke (#2068, ADR-126 Phase 3) (push) Failing after 1s
V3 CI/CD Pipeline / neural-trader backtest signing smoke (#2068, ADR-126 Phase 4) (push) Failing after 1s
V3 CI/CD Pipeline / kg-extract type-import classification smoke (#2049) (push) Failing after 0s
V3 CI/CD Pipeline / witness verify precondition smoke (#1880) (push) Failing after 2s
V3 CI/CD Pipeline / neural-trader pipeline risk-gate smoke (#2068, ADR-126 Phase 5) (push) Failing after 0s
V3 CI/CD Pipeline / neural-trader feature attribution smoke (#2068, ADR-126 Phase 6) (push) Failing after 0s
V3 CI/CD Pipeline / plugin-registry signature verification smoke (#1922, CWE-347) (push) Failing after 4s
V3 CI/CD Pipeline / memory stats legacy-DB smoke (#2120) (push) Failing after 4s
V3 CI/CD Pipeline / github deprecated actions smoke (#2089, ADR-127 Phase 3) (push) Failing after 1s
V3 CI/CD Pipeline / graph query + pathfinder smoke (ADR-130 P2+P5) (push) Has been skipped
V3 CI/CD Pipeline / graph trajectory hooks smoke (ADR-130 P3) (push) Has been skipped
V3 CI/CD Pipeline / graph plugin adapter smoke (ADR-130 P4) (push) Has been skipped
V3 CI/CD Pipeline / graph benchmark (ADR-130 P6) (push) Has been skipped
V3 CI/CD Pipeline / statusline generator delegation smoke (#2195) (push) Failing after 1s
V3 CI/CD Pipeline / wizard init regression guard (#2206 (push) Failing after 1s
V3 CI/CD Pipeline / memory no-stray-db smoke (ADR-125 P7) (push) Failing after 1s
V3 CI/CD Pipeline / github-safe injection smoke (#2089, ADR-127 Phase 1) (push) Failing after 1s
V3 CI/CD Pipeline / github actions pin smoke (#2089, ADR-127 Phase 1) (push) Failing after 1s
V3 CI/CD Pipeline / github attribution opt-in smoke (#2089, ADR-127 Phase 4) (push) Failing after 1s
V3 CI/CD Pipeline / pre-bash hook safety smoke (#2017) (push) Failing after 1s
V3 CI/CD Pipeline / Memory import smoke / ubuntu-latest (push) Failing after 0s
V3 CI/CD Pipeline / MCP protocol smoke / ubuntu-latest (push) Failing after 2s
V3 CI/CD Pipeline / ruvllm WASM auto-init smoke (#2086) (push) Failing after 4s
V3 CI/CD Pipeline / MCP paired-tool round-trip smoke (#1889) (push) Failing after 1s
V3 CI/CD Pipeline / Plugin package install-safety (#1902/#1903/#1904) (push) Failing after 1s
V3 CI/CD Pipeline / Tool description discoverability (ADR-112) (push) Failing after 3s
V3 CI/CD Pipeline / CLI npx-install smoke (#1147 / (22) (push) Failing after 1s
V3 CI/CD Pipeline / CLI npx-install smoke (#1147 / (24) (push) Failing after 1s
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / ubuntu-latest (push) Failing after 2s
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / ubuntu-latest (push) Failing after 1s
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / ubuntu-latest (push) Failing after 1s
V3 CI/CD Pipeline / Vector-index dimension audit (#1947) (push) Failing after 0s
V3 CI/CD Pipeline / Hook-command install safety (#1921) (push) Failing after 1s
V3 CI/CD Pipeline / ToolOutputGuardrail smoke (ADR-131, (push) Failing after 1s
V3 CI/CD Pipeline / init-bundle invariants smoke (#2095, ADR-128 Phase 5) (push) Failing after 1s
V3 CI/CD Pipeline / wasm provider bridge smoke (ADR-129 P1) (push) Failing after 2s
V3 CI/CD Pipeline / wasm gallery CRUD smoke (ADR-129 P3) (push) Failing after 1s
V3 CI/CD Pipeline / wasm plugin bridge smoke (ADR-129 P4) (push) Failing after 0s
V3 CI/CD Pipeline / wasm compose smoke (ADR-129 P2) (push) Failing after 4s
V3 CI/CD Pipeline / graph schema smoke (ADR-130 P1) (push) Failing after 0s
Validate Marketplace / validate (push) Failing after 1s
🔍 Verification Pipeline / 🚀 Setup Verification (push) Failing after 1s
🔍 Verification Pipeline / 🛡️ Security Verification (push) Has been skipped
🔍 Verification Pipeline / 📝 Code Quality (push) Has been skipped
🔍 Verification Pipeline / 🧪 Test Verification (${{ matrix.os }}, Node ${{ matrix.node }}) (push) Has been skipped
🔍 Verification Pipeline / 🏗️ Build Verification (push) Has been skipped
🔍 Verification Pipeline / 📚 Documentation Verification (push) Has been skipped
CVE Audit Gate / High-severity report (warn only) (push) Has been cancelled
🔄 Automated Rollback Manager / 🔄 Execute Rollback (push) Has been cancelled
🔄 Automated Rollback Manager / ✅ Post-Rollback Verification (push) Has been cancelled
🔄 Automated Rollback Manager / 📊 Rollback Monitoring (push) Has been cancelled
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / windows-latest (push) Has been cancelled
🔄 Automated Rollback Manager / ⏳ Manual Rollback Approval (push) Has been cancelled
V3 CI/CD Pipeline / MCP protocol smoke / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Memory import smoke / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / ubuntu-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Publish to npm (alpha) (push) Has been cancelled
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / macos-latest / Node 22 (push) Has been cancelled
V3 CI/CD Pipeline / Plugin hooks smoke / macos-latest / Node 22 (push) Has been cancelled
CI/CD Pipeline / Deploy & Release (push) Has been cancelled
CI/CD Pipeline / CI Status (push) Has been cancelled
🔗 Cross-Agent Integration Tests / 📊 Integration Test Report (push) Has been cancelled
🔄 Automated Rollback Manager / 🔍 Pre-Rollback Validation (push) Has been cancelled
🔍 Verification Pipeline / ⚡ Performance Verification (push) Has been cancelled
🔍 Verification Pipeline / 📊 Verification Report (push) Has been cancelled
199 lines
8.1 KiB
TypeScript
199 lines
8.1 KiB
TypeScript
/**
|
|
* Integration test for ADR-096 Phase 4: memory-initializer DB encryption.
|
|
*
|
|
* Different shape from session/terminal tests because the memory store is
|
|
* a Buffer-only sql.js SQLite blob (not a JSON.stringify of an object).
|
|
* The fs-secure helpers handle Buffer payloads identically — these tests
|
|
* pin that contract end-to-end without spinning up the real sql.js
|
|
* dependency (which has a heavy WASM init path).
|
|
*
|
|
* What's pinned:
|
|
* - writeFileRestricted({encrypt:true}) on a Buffer payload produces
|
|
* the RFE1 wire format when the env gate is on
|
|
* - readFileMaybeEncrypted(path, null) returns a Buffer (not string)
|
|
* and decrypts transparently when the file IS encrypted
|
|
* - Round-trip: write Buffer → read Buffer matches byte-for-byte
|
|
* - Migration: a legacy plaintext SQLite header on disk is still
|
|
* readable after the gate flips on (magic-byte sniff returns false
|
|
* for the SQLite header, so the file passes through unchanged)
|
|
* - Tamper: a flipped byte inside an encrypted DB blob throws on read
|
|
* rather than producing a corrupted Buffer
|
|
*/
|
|
|
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
import { tmpdir } from 'node:os';
|
|
import { join } from 'node:path';
|
|
import { randomBytes } from 'node:crypto';
|
|
|
|
import {
|
|
readFileMaybeEncrypted,
|
|
writeFileRestricted,
|
|
} from '../src/fs-secure.js';
|
|
import { MAGIC, isEncryptedBlob } from '../src/encryption/vault.js';
|
|
|
|
const SAVED_ENV: Record<string, string | undefined> = {};
|
|
function saveEnv(...names: string[]) {
|
|
for (const n of names) SAVED_ENV[n] = process.env[n];
|
|
}
|
|
function restoreEnv() {
|
|
for (const [n, v] of Object.entries(SAVED_ENV)) {
|
|
if (v === undefined) delete process.env[n];
|
|
else process.env[n] = v;
|
|
}
|
|
}
|
|
|
|
// SQLite file format: first 16 bytes are "SQLite format 3\0". memory-initializer
|
|
// writes real sql.js exports (often multi-MB), but the encryption path doesn't
|
|
// care about content — only the Buffer shape. Use a plausible synthetic header
|
|
// + payload that exercises the same code path.
|
|
function makeSyntheticDbBuffer(payloadSize = 4096): Buffer {
|
|
return Buffer.concat([
|
|
Buffer.from('SQLite format 3\0', 'utf-8'),
|
|
randomBytes(payloadSize - 16),
|
|
]);
|
|
}
|
|
|
|
describe('memory-initializer DB encryption (ADR-096 Phase 4)', () => {
|
|
let workdir: string;
|
|
let dbPath: string;
|
|
|
|
beforeEach(() => {
|
|
saveEnv('CLAUDE_FLOW_ENCRYPT_AT_REST', 'CLAUDE_FLOW_ENCRYPTION_KEY');
|
|
workdir = mkdtempSync(join(tmpdir(), 'mem-db-enc-'));
|
|
dbPath = join(workdir, 'memory.db');
|
|
});
|
|
|
|
afterEach(() => {
|
|
rmSync(workdir, { recursive: true, force: true });
|
|
restoreEnv();
|
|
});
|
|
|
|
describe('encryption disabled (legacy plaintext SQLite)', () => {
|
|
beforeEach(() => {
|
|
delete process.env.CLAUDE_FLOW_ENCRYPT_AT_REST;
|
|
delete process.env.CLAUDE_FLOW_ENCRYPTION_KEY;
|
|
});
|
|
|
|
it('writes the SQLite buffer unchanged to disk', () => {
|
|
const db = makeSyntheticDbBuffer();
|
|
writeFileRestricted(dbPath, db, { encrypt: true });
|
|
const onDisk = readFileSync(dbPath);
|
|
expect(onDisk.equals(db)).toBe(true);
|
|
// First 16 bytes are the literal SQLite header
|
|
expect(onDisk.subarray(0, 16).toString('utf-8')).toBe('SQLite format 3\0');
|
|
expect(isEncryptedBlob(onDisk)).toBe(false);
|
|
});
|
|
|
|
it('round-trips a Buffer through readFileMaybeEncrypted(path, null)', () => {
|
|
const db = makeSyntheticDbBuffer();
|
|
writeFileRestricted(dbPath, db, { encrypt: true });
|
|
const round = readFileMaybeEncrypted(dbPath, null);
|
|
expect(Buffer.isBuffer(round)).toBe(true);
|
|
expect(round.equals(db)).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('encryption enabled (RFE1 wire format)', () => {
|
|
beforeEach(() => {
|
|
process.env.CLAUDE_FLOW_ENCRYPT_AT_REST = '1';
|
|
process.env.CLAUDE_FLOW_ENCRYPTION_KEY = randomBytes(32).toString('hex');
|
|
});
|
|
|
|
it('writes a blob that starts with the RFE1 magic, NOT the SQLite header', () => {
|
|
const db = makeSyntheticDbBuffer();
|
|
writeFileRestricted(dbPath, db, { encrypt: true });
|
|
const onDisk = readFileSync(dbPath);
|
|
expect(onDisk.subarray(0, 4)).toEqual(MAGIC);
|
|
// Critical: the SQLite header must NOT appear at offset 0 — the
|
|
// encryption ran and replaced the on-disk bytes.
|
|
expect(onDisk.subarray(0, 16).toString('utf-8')).not.toBe('SQLite format 3\0');
|
|
expect(isEncryptedBlob(onDisk)).toBe(true);
|
|
});
|
|
|
|
it('round-trips a Buffer through write → read with the same key', () => {
|
|
const db = makeSyntheticDbBuffer();
|
|
writeFileRestricted(dbPath, db, { encrypt: true });
|
|
const round = readFileMaybeEncrypted(dbPath, null);
|
|
expect(Buffer.isBuffer(round)).toBe(true);
|
|
expect(round.equals(db)).toBe(true);
|
|
});
|
|
|
|
it('round-trips a megabyte-scale buffer (real-world memory.db size)', () => {
|
|
const db = makeSyntheticDbBuffer(1_048_576); // 1MB
|
|
writeFileRestricted(dbPath, db, { encrypt: true });
|
|
const round = readFileMaybeEncrypted(dbPath, null);
|
|
expect(round.equals(db)).toBe(true);
|
|
});
|
|
|
|
it('does not leak embedding-bytes into the on-disk blob', () => {
|
|
// Plant a recognizable signature inside the synthetic DB and confirm
|
|
// it does not appear in the encrypted bytes.
|
|
const signature = Buffer.from('TOPSECRET-EMBEDDING-VECTOR-AAAA', 'utf-8');
|
|
const db = Buffer.concat([
|
|
Buffer.from('SQLite format 3\0', 'utf-8'),
|
|
signature,
|
|
randomBytes(2048),
|
|
]);
|
|
writeFileRestricted(dbPath, db, { encrypt: true });
|
|
const onDisk = readFileSync(dbPath);
|
|
expect(onDisk.includes(signature)).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('migration: legacy plaintext SQLite still readable', () => {
|
|
it('plaintext SQLite written before the gate flipped on is returned as-is', () => {
|
|
// Step 1: plant a plaintext SQLite blob on disk (no env vars set
|
|
// — direct writeFileSync would normally have done this).
|
|
const db = makeSyntheticDbBuffer();
|
|
writeFileSync(dbPath, db);
|
|
|
|
// Step 2: enable encryption for the read.
|
|
process.env.CLAUDE_FLOW_ENCRYPT_AT_REST = '1';
|
|
process.env.CLAUDE_FLOW_ENCRYPTION_KEY = randomBytes(32).toString('hex');
|
|
|
|
// Step 3: readFileMaybeEncrypted's magic-byte sniff sees no RFE1
|
|
// prefix, so it returns the Buffer unchanged. New SQL.Database()
|
|
// would accept it directly.
|
|
const round = readFileMaybeEncrypted(dbPath, null);
|
|
expect(round.equals(db)).toBe(true);
|
|
expect(round.subarray(0, 16).toString('utf-8')).toBe('SQLite format 3\0');
|
|
});
|
|
});
|
|
|
|
describe('tamper detection on encrypted DB', () => {
|
|
beforeEach(() => {
|
|
process.env.CLAUDE_FLOW_ENCRYPT_AT_REST = '1';
|
|
process.env.CLAUDE_FLOW_ENCRYPTION_KEY = randomBytes(32).toString('hex');
|
|
});
|
|
|
|
it('rejects a flipped ciphertext byte (GCM auth fails)', () => {
|
|
const db = makeSyntheticDbBuffer();
|
|
writeFileRestricted(dbPath, db, { encrypt: true });
|
|
// Flip a byte deep inside the ciphertext region (after magic+iv,
|
|
// before the trailing 16-byte tag)
|
|
const bytes = readFileSync(dbPath);
|
|
bytes[100] ^= 0xff;
|
|
writeFileSync(dbPath, bytes);
|
|
expect(() => readFileMaybeEncrypted(dbPath, null)).toThrow();
|
|
});
|
|
|
|
it('rejects a flipped magic byte (caught early with bad-magic error)', () => {
|
|
const db = makeSyntheticDbBuffer();
|
|
writeFileRestricted(dbPath, db, { encrypt: true });
|
|
const bytes = readFileSync(dbPath);
|
|
bytes[0] = 0x00;
|
|
writeFileSync(dbPath, bytes);
|
|
// The magic-sniff returns false (not RFE1 prefix anymore), so the
|
|
// reader returns the bytes as-is. NB: this is the legacy-plaintext
|
|
// path — the bytes are unreadable as SQLite but won't throw at the
|
|
// fs-secure layer. That's correct: tamper detection on plaintext
|
|
// SQLite is sql.js's job, not ours. The auth failure mode (above)
|
|
// covers the case where the magic IS still RFE1 but content is bad.
|
|
const round = readFileMaybeEncrypted(dbPath, null);
|
|
expect(Buffer.isBuffer(round)).toBe(true);
|
|
expect(round[0]).toBe(0x00); // tampered first byte propagates as-is
|
|
});
|
|
});
|
|
});
|