mirror of
https://github.com/DeusData/codebase-memory-mcp.git
synced 2026-12-04 04:37:20 +08:00
Windows shipped a PAIR: a small permanent launcher (codebase-memory-mcp.exe)
plus the real product binary (codebase-memory-mcp.payload.exe). The launcher
existed for exactly one reason — a running .exe cannot replace its own image
on Windows, so an in-process self-update needs a second resident binary to do
the swap.
That stub is statically indistinguishable from a dropper: a small, unsigned,
zero-prevalence PE whose whole job is verify-and-execute another binary.
Defender's ML scored it Trojan:Win32/Wacatac.B!ml and blocked the v0.9.1-rc.1
release at the VirusTotal gate. It is not fixable in our code on x64 —
bcrypt-free, stripped, VERSIONINFO'd, minimal-resource and even
resource-FREE builds on CI's own MSYS2 CLANG64 toolchain were all flagged,
while the product binary scans clean on every platform.
So remove the stub and move self-update OUT of the process into install.ps1,
which runs while cbm is NOT running: Windows' image lock only blocks a
process from replacing ITSELF. now prints the exact PowerShell
command (with the Unblock-File hint for Mark-of-the-Web); install.ps1 is
idempotent, so re-running it IS the update — it stops the daemon, renames the
running binary aside (the one mutation Windows permits on a running image),
publishes the new one, and sweeps retired copies.
Windows now matches Linux and macOS: ONE binary per platform.
* packaging, install.ps1, npm and PyPI wrappers all carry a single binary
* the launcher/payload ABI contract and ~2500 lines of stub state machinery
are deleted
* every daemon start, CLI call and hook fire loses a process spawn, a named
pipe handshake and an stdio relay
* test_windows_bundle_contract.sh is rewritten as an INVERTED contract: it
now asserts no shipped surface can reintroduce a launcher/payload pair,
and that install.ps1 retires the running binary before publishing
Verified: VirusTotal 0/67 on the packaged binary and 0/58 on install.ps1 (no
certificate involved); macOS and Linux full suites green; Windows guards all
green including the new update-handoff contract; npm 10/10; PyPI 3/3.
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
118 lines
3.4 KiB
JavaScript
118 lines
3.4 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const os = require('node:os');
|
|
const path = require('node:path');
|
|
const test = require('node:test');
|
|
|
|
const {
|
|
UNIX_ARCHIVE_NAMES,
|
|
WINDOWS_BINARY_NAME,
|
|
extractExactTarArchive,
|
|
installWindowsBinaryAtomically,
|
|
validateExactTarMemberListing,
|
|
} = require('../install.js');
|
|
|
|
function exactUnixListing(extra = []) {
|
|
return [...UNIX_ARCHIVE_NAMES, ...extra].join('\n') + '\n';
|
|
}
|
|
|
|
test('Unix archive validation rejects traversal and unexpected members', () => {
|
|
assert.throws(
|
|
() => validateExactTarMemberListing(
|
|
exactUnixListing(['../../.ssh/authorized_keys']), UNIX_ARCHIVE_NAMES,
|
|
),
|
|
/unexpected or duplicate/,
|
|
);
|
|
assert.throws(
|
|
() => validateExactTarMemberListing(
|
|
exactUnixListing(['unexpected-root-file']), UNIX_ARCHIVE_NAMES,
|
|
),
|
|
/unexpected or duplicate/,
|
|
);
|
|
});
|
|
|
|
test('Unix extraction requests only the validated root executable', () => {
|
|
const calls = [];
|
|
const runner = (command, args) => {
|
|
calls.push({ command, args: [...args] });
|
|
return calls.length === 1 ? exactUnixListing() : Buffer.alloc(0);
|
|
};
|
|
|
|
extractExactTarArchive(
|
|
'/tmp/release.tar.gz', '/tmp/extract', UNIX_ARCHIVE_NAMES,
|
|
'codebase-memory-mcp', runner,
|
|
);
|
|
|
|
assert.deepEqual(calls[0].args, ['-tzf', '/tmp/release.tar.gz']);
|
|
assert.deepEqual(
|
|
calls[1].args,
|
|
['-xzf', '/tmp/release.tar.gz', '-C', '/tmp/extract', 'codebase-memory-mcp'],
|
|
);
|
|
});
|
|
|
|
function writeBinary(directory, tag) {
|
|
fs.mkdirSync(directory, { recursive: true });
|
|
fs.writeFileSync(path.join(directory, WINDOWS_BINARY_NAME), `binary:${tag}`);
|
|
}
|
|
|
|
function fakeBinaryVerifier(binaryPath) {
|
|
const binary = fs.readFileSync(binaryPath, 'utf8');
|
|
if (!/^binary:(.+)$/.test(binary)) {
|
|
throw new Error('cached Windows binary failed verification');
|
|
}
|
|
}
|
|
|
|
function withBinaryDirectories(callback) {
|
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'cbm-npm-binary-test-'));
|
|
const source = path.join(root, 'source');
|
|
const destination = path.join(root, 'destination');
|
|
fs.mkdirSync(destination);
|
|
try {
|
|
callback({ source, destination });
|
|
} finally {
|
|
fs.rmSync(root, { recursive: true, force: true });
|
|
}
|
|
}
|
|
|
|
function assertBinary(directory, tag) {
|
|
assert.equal(
|
|
fs.readFileSync(path.join(directory, WINDOWS_BINARY_NAME), 'utf8'),
|
|
`binary:${tag}`,
|
|
);
|
|
}
|
|
|
|
test('Windows publication repairs a corrupt cached binary', () => {
|
|
withBinaryDirectories(({ source, destination }) => {
|
|
writeBinary(source, 'candidate');
|
|
writeBinary(destination, 'old');
|
|
fs.writeFileSync(path.join(destination, WINDOWS_BINARY_NAME), 'corrupt');
|
|
|
|
installWindowsBinaryAtomically(source, destination, fakeBinaryVerifier);
|
|
|
|
assertBinary(destination, 'candidate');
|
|
});
|
|
});
|
|
|
|
test('Windows publication installs into an empty cache', () => {
|
|
withBinaryDirectories(({ source, destination }) => {
|
|
writeBinary(source, 'candidate');
|
|
|
|
installWindowsBinaryAtomically(source, destination, fakeBinaryVerifier);
|
|
|
|
assertBinary(destination, 'candidate');
|
|
});
|
|
});
|
|
|
|
test('Windows publication preserves a valid concurrent winner', () => {
|
|
withBinaryDirectories(({ source, destination }) => {
|
|
writeBinary(source, 'loser');
|
|
writeBinary(destination, 'winner');
|
|
|
|
installWindowsBinaryAtomically(source, destination, fakeBinaryVerifier);
|
|
|
|
assertBinary(destination, 'winner');
|
|
});
|
|
});
|