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(analyze): accept safe Git revision ranges

Rudy Celeklid0d43291606c
diff --git a/v3/@claude-flow/cli/__tests__/security-audit.test.ts b/v3/@claude-flow/cli/__tests__/security-audit.test.ts
index c800b60796..52c3fd2eae 100644
--- a/v3/@claude-flow/cli/__tests__/security-audit.test.ts
+++ b/v3/@claude-flow/cli/__tests__/security-audit.test.ts
@@ -13,6 +13,7 @@
import { describe, it, expect, beforeEach } from 'vitest';
import * as fs from 'fs';
import * as path from 'path';
+import { getGitDiffNumstat, getGitDiffNumstatAsync } from '../src/ruvector/diff-classifier.js';
// ============================================================================
// 1. Path Traversal Prevention in Session Tools
@@ -60,42 +61,35 @@ describe('Path Traversal Prevention', () => {
// 2. Command Injection Prevention in Diff Classifier
// ============================================================================
describe('Command Injection Prevention - Git Ref Validation', () => {
- // Reproduce validateGitRef from diff-classifier.ts:367-382
- function validateGitRef(ref: string): void {
- if (!/^[a-zA-Z0-9_\-./~^@]+$/.test(ref)) {
- throw new Error('Invalid git ref: contains unsafe characters');
- }
- if (ref.includes('..') && !ref.match(/^[a-zA-Z0-9_\-]+\.\.\.?[a-zA-Z0-9_\-]+$/)) {
- if (!/^\w+\.\.[.\w]+$/.test(ref)) {
- throw new Error('Invalid git ref: suspicious pattern');
- }
- }
- if (ref.length > 256) {
- throw new Error('Invalid git ref: too long');
+ it('should allow valid git refs', () => {
+ for (const ref of ['HEAD', 'HEAD~1', 'HEAD^', 'origin/main',
+ 'HEAD~1..', 'HEAD~1..HEAD', 'origin/main..origin/main',
+ 'HEAD~3...origin/main']) {
+ expect(() => getGitDiffNumstat(ref), ref).not.toThrow();
}
- }
+ });
- it('should allow valid git refs', () => {
- expect(() => validateGitRef('HEAD')).not.toThrow();
- expect(() => validateGitRef('main')).not.toThrow();
- expect(() => validateGitRef('feature/my-branch')).not.toThrow();
- expect(() => validateGitRef('v1.0.0')).not.toThrow();
- expect(() => validateGitRef('HEAD~3')).not.toThrow();
- expect(() => validateGitRef('HEAD^')).not.toThrow();
- expect(() => validateGitRef('origin/main')).not.toThrow();
+ it('should allow normal ranges through the async path', async () => {
+ await expect(getGitDiffNumstatAsync('HEAD~1..HEAD')).resolves.toEqual(expect.any(Array));
+ await expect(getGitDiffNumstatAsync('origin/main..origin/main')).resolves.toEqual(expect.any(Array));
});
it('should reject command injection via shell metacharacters', () => {
- expect(() => validateGitRef('HEAD; rm -rf /')).toThrow('unsafe characters');
- expect(() => validateGitRef('HEAD && cat /etc/passwd')).toThrow('unsafe characters');
- expect(() => validateGitRef('HEAD | whoami')).toThrow('unsafe characters');
- expect(() => validateGitRef('$(whoami)')).toThrow('unsafe characters');
- expect(() => validateGitRef('`whoami`')).toThrow('unsafe characters');
+ for (const ref of ['HEAD; rm -rf /', 'HEAD && cat /etc/passwd',
+ 'HEAD | whoami', '$(whoami)', '`whoami`', '--help']) {
+ expect(() => getGitDiffNumstat(ref), ref).toThrow('unsafe characters');
+ }
+ });
+
+ it('should reject traversal and multiple range separators', () => {
+ for (const ref of ['foo/../bar', 'HEAD..../feature', 'main..feature..other']) {
+ expect(() => getGitDiffNumstat(ref), ref).toThrow('suspicious pattern');
+ }
});
it('should reject refs that are too long (DoS prevention)', () => {
const longRef = 'a'.repeat(257);
- expect(() => validateGitRef(longRef)).toThrow('too long');
+ expect(() => getGitDiffNumstat(longRef)).toThrow('too long');
});
});
diff --git a/v3/@claude-flow/cli/src/ruvector/diff-classifier.ts b/v3/@claude-flow/cli/src/ruvector/diff-classifier.ts
index ca71f450ad..c7811175c2 100644
--- a/v3/@claude-flow/cli/src/ruvector/diff-classifier.ts
+++ b/v3/@claude-flow/cli/src/ruvector/diff-classifier.ts
@@ -368,20 +368,24 @@ const CACHE_TTL_MS = 5000; // 5 seconds - short TTL since diffs change frequentl
* Only allows safe characters: alphanumeric, -, _, /, ., ~, ^
*/
function validateGitRef(ref: string): void {
- // Block shell metacharacters and dangerous patterns
- if (!/^[a-zA-Z0-9_\-./~^@]+$/.test(ref)) {
+ if (ref.length > 256) {
+ throw new Error(`Invalid git ref: too long`);
+ }
+ // A ref is passed as one argv element, but still must not be an option or
+ // contain shell metacharacters. A range may omit its right endpoint (HEAD).
+ if (!/^[a-zA-Z0-9_][a-zA-Z0-9_\-./~^@]*$/.test(ref)) {
throw new Error(`Invalid git ref: contains unsafe characters`);
}
- // Block multiple dots (path traversal)
- if (ref.includes('..') && !ref.match(/^[a-zA-Z0-9_\-]+\.\.\.?[a-zA-Z0-9_\-]+$/)) {
- if (!/^\w+\.\.[.\w]+$/.test(ref)) {
+ if (ref.includes('..')) {
+ const range = ref.match(/^(.+?)(\.\.\.?)(.*)$/);
+ // Only one range separator is allowed. In particular, reject traversal
+ // inside either endpoint, while accepting branch paths and ancestry syntax.
+ if (!range || range[1].includes('..') || range[3].includes('..') ||
+ !/^[a-zA-Z0-9_][a-zA-Z0-9_\-./~^@]*$/.test(range[1]) ||
+ (range[3] !== '' && !/^[a-zA-Z0-9_][a-zA-Z0-9_\-./~^@]*$/.test(range[3]))) {
throw new Error(`Invalid git ref: suspicious pattern`);
}
}
- // Max length check
- if (ref.length > 256) {
- throw new Error(`Invalid git ref: too long`);
- }
}
/**