mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-12-04 06:21:59 +09:00
* dream(security): denylist gaps in validateEnv() for git/perl/ruby/java env-var hijack family DENYLISTED_ENV_NAMES (v3/@claude-flow/cli-core/src/mcp-tools/validate-input.ts) covered loader-hijack and the 2026-09-21 search-path-family fix, but missed credential/arbitrary-command vars in the same git family (GIT_ASKPASS, GIT_PROXY_COMMAND), interpreter-flag-injection vars for Perl/Ruby/Java (PERL5OPT/RUBYOPT/JAVA_TOOL_OPTIONS/_JAVA_OPTIONS/JDK_JAVA_OPTIONS), two more search-path vars (PYTHONHOME, CLASSPATH), and git's numbered GIT_CONFIG_KEY_<n>/VALUE_<n>/COUNT runtime-config-injection family (added via a new regex, not a fixed name — strictly broader than any single name). PYTHONSTARTUP included for defense-in-depth with an honest caveat (interactive- REPL-only, not live-exploitable through today's non-interactive execSync path). Researched and explicitly rejected: PYTHONEXECUTABLE (cosmetic, macOS-only), PSModulePath (single-source, Grade C evidence only). 18 new discriminating tests added to validate-input-env.test.ts, matching the file's existing pattern. Stash-isolated: 18/18 fail against baseline, 51/51 pass on candidate. Full @claude-flow/cli suite: byte-identical 60-failure set baseline vs candidate (zero regressions). tsc --noEmit: 0 errors. Co-Authored-By: RuFlo <ruv@ruv.net> Claude-Session: https://claude.ai/code/session_01S1h1otMCeN5gSX8S5gC17H * dream(security): fix-forward post-critique — correct test counts, document GIT_CONFIG_NOSYSTEM/PYTHONSTARTUP caveats Independent adversarial critic caught: (1) an arithmetic error in this session's own evaluation writeup (32 pre-existing tests, not 33; 19 new tests of which 18 discriminate, not 18 flat); (2) GIT_CONFIG_NOSYSTEM's denylist rationale was undocumented despite guidance/mod-sources.ts's git() helper setting that same var defensively elsewhere in this repo; (3) the PYTHONSTARTUP comment overclaimed that execSync's non-interactive child "cannot enter" Python's interactive mode — a caller-supplied `python3 -i` can still trigger it. All three addressed: gist corrected, source comments now document the real rationale for both. Net security conclusion for PYTHONSTARTUP unchanged (defense-in-depth, no new capability — the caller already controls the full command string). Re-verified: 51/51 tests, tsc --noEmit clean. Co-Authored-By: RuFlo <ruv@ruv.net> Claude-Session: https://claude.ai/code/session_01S1h1otMCeN5gSX8S5gC17H * dream(security): update LEDGER.md for 2026-10-16 (#4229/#4230) Appends tonight's row, confirms #4053/#3977 merged via GitHub MCP tools, confirms no run-gap for 10-12..10-15, and flags that 10-11's own PR cited a CVE-2026-25725 that does not resolve in NVD/MITRE. Co-Authored-By: RuFlo <ruv@ruv.net> Claude-Session: https://claude.ai/code/session_01S1h1otMCeN5gSX8S5gC17H * dream(security): fix CI — bump @claude-flow/cli-core 3.7.3->3.7.4 (leaf-package-publish audit) The "Plugin package install-safety" CI check's audit-leaf-package-publish.mjs caught that this PR's source change to v3/@claude-flow/cli-core (not bundled into the release tarballs, resolved from the registry at the version v3/@claude-flow/cli/package.json pins) left the leaf's own package.json version unchanged — per CLAUDE.md's "Publishing Rules" (ruvnet/ruflo#3335, #3390), that means a release would ship the OLD registry copy and this fix would reach nobody. PATCH bump per repo semver policy (bug fix, no API change): 3.7.3 -> 3.7.4. Updated the three places that need to agree: cli-core's own package.json, @claude-flow/cli's dependency pin, and v3/pnpm-lock.yaml's specifier for that workspace link. Re-verified: audit-leaf-package-publish.mjs clean, tsc --noEmit 0 errors, 51/51 tests pass. Co-Authored-By: RuFlo <ruv@ruv.net> Claude-Session: https://claude.ai/code/session_01S1h1otMCeN5gSX8S5gC17H * dream(security): fix CI — bump root claude-flow's @claude-flow/cli-core range 3.7.3->3.7.4 audit-wrapper-dep-ranges.mjs (ruvnet/ruflo#2127) caught that the root claude-flow umbrella's own declared dependency range for the just-bumped @claude-flow/cli-core leaf (3.7.3) no longer includes the workspace's actual version (3.7.4) after the prior commit's bump. package-lock.json's resolved node_modules/@claude-flow/cli-core record intentionally left untouched (still 3.7.3, with its real registry integrity hash) since 3.7.4 has not actually been published yet — see the PR comment on the structural publish blocker. Re-verified all 5 install-safety audit scripts locally: clean. Co-Authored-By: RuFlo <ruv@ruv.net> Claude-Session: https://claude.ai/code/session_01S1h1otMCeN5gSX8S5gC17H * Revert "dream(security): fix CI — bump root claude-flow's @claude-flow/cli-core range 3.7.3->3.7.4" This reverts commit9dae077cb3. * dream(security): resolve CI blocker — @claude-flow/cli-core@3.7.4 is now published A maintainer's 3.57.0 release (main advanced from1882006a0tob93144803while this PR sat open) published @claude-flow/cli-core@3.7.4 to the real npm registry, containing this exact fix (verified via `npm pack` + diff against the source on this branch). That resolves the structural blocker described in this PR's comment: the root claude-flow umbrella's own dependency range can now safely bump to match, since 3.7.4 genuinely exists — unlike three days ago, this no longer breaks root `npm ci`/ `npm install` for the rest of the CI matrix. Re-verified for real this time (not just the static audits): ran `node scripts/smoke-cli-npx-install.mjs` directly — packs the real CLI tarball and does a genuine `npm install` into a scratch project — and it now succeeds end-to-end (previously failed with ETARGET). All 5 install- safety audit scripts clean. 51/51 tests, tsc --noEmit 0 errors. Note: main's own source tree (v3/@claude-flow/cli-core/src/mcp-tools/ validate-input.ts) is still at the pre-fix 3.7.3 content as of this commit — only the npm registry got the fix early, via whatever process published 3.7.4. Merging this PR is what reconciles main's source with what's already shipped to real users. Co-Authored-By: RuFlo <ruv@ruv.net> Claude-Session: https://claude.ai/code/session_01S1h1otMCeN5gSX8S5gC17H --------- Co-authored-by: Claude <noreply@anthropic.com>
170 lines
6.1 KiB
TypeScript
170 lines
6.1 KiB
TypeScript
/**
|
|
* Regression test for audit_1776853149979: terminal_create previously merged
|
|
* caller-supplied env straight into execSync's environment for every command
|
|
* in the session. Setting LD_PRELOAD or NODE_OPTIONS via that path was
|
|
* functionally RCE on the host. validateEnv enforces a denylist + POSIX
|
|
* shape — these tests pin the contract so the denylist can't silently
|
|
* regress.
|
|
*/
|
|
|
|
import { describe, it, expect } from 'vitest';
|
|
import { validateEnv } from '../src/mcp-tools/validate-input.js';
|
|
|
|
describe('validateEnv (audit_1776853149979)', () => {
|
|
describe('happy path', () => {
|
|
it('accepts undefined / null as empty env', () => {
|
|
expect(validateEnv(undefined)).toEqual({ valid: true, sanitized: {} });
|
|
expect(validateEnv(null)).toEqual({ valid: true, sanitized: {} });
|
|
});
|
|
|
|
it('accepts an empty object', () => {
|
|
expect(validateEnv({})).toEqual({ valid: true, sanitized: {} });
|
|
});
|
|
|
|
it('passes through a valid env unchanged', () => {
|
|
const r = validateEnv({ FOO: 'bar', MY_VAR: '1', _UNDERSCORE: 'ok' });
|
|
expect(r.valid).toBe(true);
|
|
expect(r.sanitized).toEqual({ FOO: 'bar', MY_VAR: '1', _UNDERSCORE: 'ok' });
|
|
});
|
|
});
|
|
|
|
describe('loader-hijack denylist', () => {
|
|
// Names that let an attacker hijack a child process before any user code
|
|
// runs. Each MUST be rejected — adding an exemption is a real CVE.
|
|
const denylisted = [
|
|
'LD_PRELOAD',
|
|
'LD_LIBRARY_PATH',
|
|
'LD_AUDIT',
|
|
'DYLD_INSERT_LIBRARIES',
|
|
'DYLD_LIBRARY_PATH',
|
|
'DYLD_FALLBACK_LIBRARY_PATH',
|
|
'DYLD_FORCE_FLAT_NAMESPACE',
|
|
'NODE_OPTIONS',
|
|
'NODE_PATH',
|
|
// dream-cycle 2026-09-21 (CWE-427, Uncontrolled Search Path Element):
|
|
// PATH itself and the equivalent interpreter/VCS search-path vars were
|
|
// missing — a caller could override PATH for every subsequent command
|
|
// in the terminal session.
|
|
'PATH',
|
|
'PYTHONPATH',
|
|
'PERL5LIB',
|
|
'RUBYLIB',
|
|
'GIT_EXTERNAL_DIFF',
|
|
'GIT_SSH_COMMAND',
|
|
'BASH_ENV',
|
|
'IFS',
|
|
// dream-cycle 2026-10-16: 2026-09-21 covered Python/Perl/Ruby/git/shell
|
|
// search-path vars but missed credential vars in the same git family,
|
|
// interpreter-flag-injection vars for Perl/Ruby/Java, and two more
|
|
// search-path vars. See validate-input.ts's denylist comment for the
|
|
// source grading behind each of these.
|
|
'GIT_ASKPASS',
|
|
'GIT_PROXY_COMMAND',
|
|
'GIT_CONFIG_NOSYSTEM',
|
|
'PERL5OPT',
|
|
'RUBYOPT',
|
|
'JAVA_TOOL_OPTIONS',
|
|
'_JAVA_OPTIONS',
|
|
'JDK_JAVA_OPTIONS',
|
|
'PYTHONHOME',
|
|
'CLASSPATH',
|
|
'PYTHONSTARTUP',
|
|
];
|
|
|
|
for (const name of denylisted) {
|
|
it(`rejects ${name}`, () => {
|
|
const r = validateEnv({ [name]: '/tmp/whatever' });
|
|
expect(r.valid).toBe(false);
|
|
expect(r.error).toContain(name);
|
|
expect(r.error).toContain('denylisted');
|
|
expect(r.sanitized).toEqual({});
|
|
});
|
|
}
|
|
|
|
// dream-cycle 2026-09-21 (adversarial critique caveat): Windows env vars
|
|
// are case-insensitive, so `path`/`Path` must be denylisted the same as
|
|
// `PATH` even though they're distinct object keys here.
|
|
describe('case-insensitive denylist match', () => {
|
|
const caseVariants = ['path', 'Path', 'PaTh', 'node_options', 'Node_Options', 'git_askpass', 'Java_Tool_Options'];
|
|
|
|
for (const name of caseVariants) {
|
|
it(`rejects ${name}`, () => {
|
|
const r = validateEnv({ [name]: '/tmp/whatever' });
|
|
expect(r.valid).toBe(false);
|
|
expect(r.error).toContain('denylisted');
|
|
expect(r.sanitized).toEqual({});
|
|
});
|
|
}
|
|
});
|
|
|
|
// dream-cycle 2026-10-16: git's numbered runtime-config-injection family
|
|
// (GIT_CONFIG_COUNT / GIT_CONFIG_KEY_<n> / GIT_CONFIG_VALUE_<n>) lets a
|
|
// caller set arbitrary git config (core.sshCommand, core.hooksPath,
|
|
// http.*, …) at runtime — strictly broader than any single fixed name,
|
|
// so it's matched by pattern rather than exact Set membership.
|
|
describe('GIT_CONFIG_* numbered family (pattern match)', () => {
|
|
const names = ['GIT_CONFIG_COUNT', 'GIT_CONFIG_KEY_0', 'GIT_CONFIG_VALUE_0', 'GIT_CONFIG_KEY_12', 'git_config_key_3'];
|
|
|
|
for (const name of names) {
|
|
it(`rejects ${name}`, () => {
|
|
const r = validateEnv({ [name]: 'x' });
|
|
expect(r.valid).toBe(false);
|
|
expect(r.error).toContain('denylisted');
|
|
expect(r.sanitized).toEqual({});
|
|
});
|
|
}
|
|
|
|
it('does not reject an unrelated GIT_CONFIG-prefixed name', () => {
|
|
const r = validateEnv({ GIT_CONFIGURATION_PROFILE: 'x' });
|
|
expect(r.valid).toBe(true);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('shape validation', () => {
|
|
it('rejects a name containing =', () => {
|
|
const r = validateEnv({ 'A=B': 'x' });
|
|
expect(r.valid).toBe(false);
|
|
expect(r.error).toContain('not a valid POSIX env name');
|
|
});
|
|
|
|
it('rejects a digit-first name', () => {
|
|
const r = validateEnv({ '1FOO': 'x' });
|
|
expect(r.valid).toBe(false);
|
|
expect(r.error).toContain('not a valid POSIX env name');
|
|
});
|
|
|
|
it('rejects a name with whitespace', () => {
|
|
const r = validateEnv({ 'BAD NAME': 'x' });
|
|
expect(r.valid).toBe(false);
|
|
expect(r.error).toContain('not a valid POSIX env name');
|
|
});
|
|
|
|
it('rejects an array (not an object)', () => {
|
|
const r = validateEnv(['FOO', 'BAR'] as unknown);
|
|
expect(r.valid).toBe(false);
|
|
expect(r.error).toContain('object of string→string');
|
|
});
|
|
|
|
it('rejects a non-string value', () => {
|
|
const r = validateEnv({ FOO: 42 });
|
|
expect(r.valid).toBe(false);
|
|
expect(r.error).toContain('FOO');
|
|
expect(r.error).toContain('must be a string');
|
|
});
|
|
|
|
it('rejects a value with a null byte', () => {
|
|
const value = ['a', String.fromCharCode(0), 'b'].join('');
|
|
const r = validateEnv({ FOO: value });
|
|
expect(r.valid).toBe(false);
|
|
expect(r.error).toContain('null byte');
|
|
});
|
|
|
|
it('rejects a value over 32K', () => {
|
|
const r = validateEnv({ FOO: 'x'.repeat(40_000) });
|
|
expect(r.valid).toBe(false);
|
|
expect(r.error).toContain('exceeds 32768');
|
|
});
|
|
});
|
|
});
|