Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

fix(config): reject prototype traversal in dotted keys

Rudy Celekli36570a871083
diff --git a/v3/@claude-flow/cli/__tests__/config-prototype-safety.test.ts b/v3/@claude-flow/cli/__tests__/config-prototype-safety.test.ts
new file mode 100644
index 0000000000..bf4af50a9f
--- /dev/null
+++ b/v3/@claude-flow/cli/__tests__/config-prototype-safety.test.ts
@@ -0,0 +1,48 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { join } from 'node:path';
+import { tmpdir } from 'node:os';
+import { ConfigFileManager } from '../src/services/config-file-manager.js';
+
+let cwd: string;
+let file: string;
+beforeEach(() => {
+ cwd = mkdtempSync(join(tmpdir(), 'config-prototype-'));
+ file = join(cwd, 'claude-flow.config.json');
+ writeFileSync(file, '{"custom":{"keep":true}}');
+ vi.stubEnv('CLAUDE_FLOW_CONFIG', '');
+});
+afterEach(() => {
+ delete (Object.prototype as any).configPolluted;
+ vi.unstubAllEnvs();
+ rmSync(cwd, { recursive: true, force: true });
+});
+
+describe('configuration property traversal', () => {
+ it.each(['__proto__.configPolluted', 'custom.__proto__.configPolluted', 'constructor.prototype.configPolluted', 'custom.constructor.prototype.configPolluted', 'custom.prototype.configPolluted', '__proto__'])('rejects unsafe key %s before mutating memory or disk', (key) => {
+ const manager = new ConfigFileManager();
+ manager.load(cwd);
+ const before = readFileSync(file, 'utf8');
+ let error: unknown;
+ try { manager.set(cwd, key, 'tainted'); } catch (caught) { error = caught; }
+ expect(({} as any).configPolluted).toBeUndefined();
+ expect(error).toBeInstanceOf(Error);
+ expect(String(error)).toMatch(/unsafe.*key/i);
+ expect(readFileSync(file, 'utf8')).toBe(before);
+ expect(manager.get(cwd, 'custom.keep')).toBe(true);
+ });
+
+ it('does not read inherited properties as configuration values', () => {
+ const manager = new ConfigFileManager();
+ expect(manager.get(cwd, 'toString')).toBeUndefined();
+ expect(manager.get(cwd, 'custom.constructor')).toBeUndefined();
+ expect(manager.get(cwd, 'custom.__proto__')).toBeUndefined();
+ });
+
+ it('continues to write ordinary nested own properties', () => {
+ const manager = new ConfigFileManager();
+ manager.set(cwd, 'custom.enabled', false);
+ manager.set(cwd, 'custom.count', 0);
+ expect(JSON.parse(readFileSync(file, 'utf8'))).toEqual({ custom: { keep: true, enabled: false, count: 0 } });
+ });
+});
diff --git a/v3/@claude-flow/cli/src/services/config-file-manager.ts b/v3/@claude-flow/cli/src/services/config-file-manager.ts
index d789c4f6e8..6347817410 100644
--- a/v3/@claude-flow/cli/src/services/config-file-manager.ts
+++ b/v3/@claude-flow/cli/src/services/config-file-manager.ts
@@ -110,6 +110,10 @@ export class ConfigFileManager {
/** Set a nested config value by dot-separated key */
set(cwd: string, key: string, value: unknown): void {
+ // Reject the entire path before touching cached config or disk.
+ if (key.split('.').some(part => part === '__proto__' || part === 'constructor' || part === 'prototype')) {
+ throw new Error(`Unsafe configuration key: ${key}`);
+ }
const config = this.getConfig(cwd);
setNestedValue(config, key, value);
this.config = config;
@@ -196,7 +200,7 @@ function getNestedValue(obj: Record<string, unknown>, key: string): unknown {
const parts = key.split('.');
let current: unknown = obj;
for (const part of parts) {
- if (current === null || current === undefined || typeof current !== 'object') {
+ if (current === null || current === undefined || typeof current !== 'object' || !Object.hasOwn(current, part)) {
return undefined;
}
current = (current as Record<string, unknown>)[part];
@@ -210,7 +214,7 @@ function setNestedValue(obj: Record<string, unknown>, key: string, value: unknow
let current: Record<string, unknown> = obj;
for (let i = 0; i < parts.length - 1; i++) {
const part = parts[i];
- if (!(part in current) || typeof current[part] !== 'object' || current[part] === null) {
+ if (!Object.hasOwn(current, part) || typeof current[part] !== 'object' || current[part] === null) {
current[part] = {};
}
current = current[part] as Record<string, unknown>;