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>
119 lines
3.7 KiB
JavaScript
119 lines
3.7 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const test = require('node:test');
|
|
const vm = require('node:vm');
|
|
|
|
class ExitSignal extends Error {
|
|
constructor(code) {
|
|
super(`process.exit(${code})`);
|
|
this.code = code;
|
|
}
|
|
}
|
|
|
|
function runShim(targetPlatform, arguments_, childStatus) {
|
|
const shimPath = path.join(__dirname, '..', 'bin.js');
|
|
const source = fs.readFileSync(shimPath, 'utf8').replace(/^#![^\n]*\n/, '');
|
|
const calls = [];
|
|
let stderr = '';
|
|
|
|
const fakeProcess = {
|
|
platform: targetPlatform,
|
|
argv: ['node.exe', shimPath, ...arguments_],
|
|
execPath: 'node.exe',
|
|
stderr: { write: (text) => { stderr += String(text); } },
|
|
exit: (code) => { throw new ExitSignal(code); },
|
|
};
|
|
const fakeFs = {
|
|
existsSync: () => true,
|
|
};
|
|
const fakeChildProcess = {
|
|
spawnSync: (executable, args, options) => {
|
|
calls.push({ executable, args, options });
|
|
return { status: calls.length === 1 ? 0 : childStatus };
|
|
},
|
|
};
|
|
const sandbox = {
|
|
__dirname: path.dirname(shimPath),
|
|
__filename: shimPath,
|
|
Buffer,
|
|
clearTimeout,
|
|
console,
|
|
exports: {},
|
|
module: { exports: {} },
|
|
process: fakeProcess,
|
|
require: (specifier) => {
|
|
if (specifier === 'fs') return fakeFs;
|
|
if (specifier === 'child_process') return fakeChildProcess;
|
|
return require(specifier);
|
|
},
|
|
setTimeout,
|
|
};
|
|
|
|
let exitCode = null;
|
|
try {
|
|
vm.runInNewContext(source, sandbox, { filename: shimPath });
|
|
} catch (error) {
|
|
if (!(error instanceof ExitSignal)) throw error;
|
|
exitCode = error.code;
|
|
}
|
|
return { calls, exitCode, stderr };
|
|
}
|
|
|
|
test('Windows npm shim probes and executes the cached launcher', () => {
|
|
const observed = runShim('win32', ['--version'], 0);
|
|
|
|
assert.equal(observed.exitCode, 0);
|
|
assert.equal(observed.calls.length, 2);
|
|
for (const call of observed.calls) {
|
|
assert.equal(path.basename(call.executable), 'codebase-memory-mcp.exe');
|
|
assert.notEqual(
|
|
path.basename(call.executable),
|
|
'codebase-memory-mcp.payload.exe',
|
|
);
|
|
}
|
|
assert.deepEqual(Array.from(observed.calls[1].args), ['--version']);
|
|
assert.equal(observed.calls[1].options.stdio, 'inherit');
|
|
});
|
|
|
|
test('Windows npm shim keeps package-manager guidance after launcher refusal', () => {
|
|
const observed = runShim('win32', ['update'], 1);
|
|
|
|
assert.equal(observed.exitCode, 1);
|
|
assert.equal(path.basename(observed.calls[1].executable), 'codebase-memory-mcp.exe');
|
|
assert.match(observed.stderr, /npm install codebase-memory-mcp@latest/);
|
|
assert.match(observed.stderr, /install --yes/);
|
|
});
|
|
|
|
test('non-Windows npm shim keeps its native payload execution path', () => {
|
|
const observed = runShim('darwin', ['--version'], 0);
|
|
|
|
assert.equal(observed.exitCode, 0);
|
|
assert.equal(observed.calls.length, 1);
|
|
assert.equal(path.basename(observed.calls[0].executable), 'codebase-memory-mcp');
|
|
});
|
|
|
|
test('PowerShell install mutation runs through the downloaded binary', () => {
|
|
const installer = fs.readFileSync(
|
|
path.join(__dirname, '..', '..', '..', 'install.ps1'),
|
|
'utf8',
|
|
);
|
|
|
|
assert.match(
|
|
installer,
|
|
/^\s*\$candidateVersion\s*=\s*&\s*\$DownloadedBinary\s+--version\b/m,
|
|
);
|
|
assert.match(
|
|
installer,
|
|
/^\s*&\s*\$DownloadedBinary\s+@InstallArgs\b/m,
|
|
);
|
|
// One binary ships per platform — no launcher/payload pair to resolve.
|
|
assert.doesNotMatch(installer, /payload/i);
|
|
// A running .exe cannot be overwritten, so an in-place update has to retire
|
|
// the existing binary by renaming it aside first. This script IS the Windows
|
|
// update path, so losing that step would silently break every update.
|
|
assert.match(installer, /Move-Item[\s\S]{0,80}\$Dest[\s\S]{0,40}\$retired/);
|
|
});
|