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): flag encryption paths as security-sensitive

Rudy Celekli5d153c6dd9a4
diff --git a/v3/@claude-flow/cli/__tests__/ruvector/diff-classifier.test.ts b/v3/@claude-flow/cli/__tests__/ruvector/diff-classifier.test.ts
index c7c06e4e0a..95c38c0f70 100644
--- a/v3/@claude-flow/cli/__tests__/ruvector/diff-classifier.test.ts
+++ b/v3/@claude-flow/cli/__tests__/ruvector/diff-classifier.test.ts
@@ -5,7 +5,7 @@
*/
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
-import { DiffClassifier, createDiffClassifier, type DiffAnalysis, type FileDiff } from '../../src/ruvector/diff-classifier';
+import { DiffClassifier, assessFileRisk, createDiffClassifier, suggestReviewers, type DiffAnalysis, type DiffFile, type FileDiff } from '../../src/ruvector/diff-classifier';
// Mock the @ruvector/diff module
vi.mock('@ruvector/diff', () => ({
@@ -295,6 +295,36 @@ diff --git a/file2.ts b/file2.ts
const files = classifier.parseDiff(diff);
expect(files[0].classification.impactLevel).toBe('low');
});
+
+ it('treats encryption changes as security-sensitive across diff and file-risk paths', () => {
+ const path = 'packages/encryption/src/bytea.ts';
+ const diff = `diff --git a/${path} b/${path}
+--- a/${path}
++++ b/${path}
+@@ -1 +1 @@
+-old
++new
+`;
+ const classification = classifier.parseDiff(diff)[0].classification;
+ expect(classification.impactLevel).toBe('critical');
+ expect(classification.suggestedReviewers).toContain('security-team');
+ expect(classification.testingStrategy).toContain('security-audit');
+ expect(classification.riskFactors).toContain('Security-sensitive code');
+
+ const file: DiffFile = { path, status: 'modified', additions: 1, deletions: 1 };
+ const risk = assessFileRisk(file);
+ expect(risk).toMatchObject({ risk: 'high', score: 40, reasons: ['Security-sensitive file'] });
+ expect(suggestReviewers([file], [risk])).toContain('security-team');
+ });
+
+ it('does not flag unrelated path tokens as security-sensitive', () => {
+ for (const path of ['src/tokenizer.ts', 'src/author.ts', 'src/cryptic.ts']) {
+ const file: DiffFile = { path, status: 'modified', additions: 1, deletions: 1 };
+ expect(assessFileRisk(file).reasons).not.toContain('Security-sensitive file');
+ const diff = `diff --git a/${path} b/${path}\n--- a/${path}\n+++ b/${path}\n@@ -1 +1 @@\n-old\n+new\n`;
+ expect(classifier.parseDiff(diff)[0].classification.impactLevel).toBe('low');
+ }
+ });
});
describe('reviewer suggestions', () => {
diff --git a/v3/@claude-flow/cli/src/ruvector/diff-classifier.ts b/v3/@claude-flow/cli/src/ruvector/diff-classifier.ts
index ca71f450ad..40782c8f43 100644
--- a/v3/@claude-flow/cli/src/ruvector/diff-classifier.ts
+++ b/v3/@claude-flow/cli/src/ruvector/diff-classifier.ts
@@ -75,10 +75,25 @@ const CLASSIFICATION_PATTERNS: Record<string, RegExp[]> = {
};
const IMPACT_KEYWORDS: Record<string, number> = {
- security: 3, auth: 3, payment: 3, database: 2, api: 2, core: 2,
+ payment: 3, database: 2, api: 2, core: 2,
util: 1, helper: 1, test: 0, mock: 0, fixture: 0,
};
+// Match path terms rather than substrings: `encryption` must trigger review,
+// while unrelated names such as `author` and `tokenizer` must not.
+const SECURITY_PATH_TERMS = new Set([
+ 'security', 'secure', 'auth', 'oauth', 'authenticate', 'authentication',
+ 'authorization', 'authorized', 'authenticator', 'crypto', 'cryptography',
+ 'encrypt', 'encryption', 'encrypted', 'decrypt', 'decryption', 'decrypted',
+ 'cipher', 'secret', 'secrets', 'password', 'passwords', 'token', 'tokens',
+ 'vault', 'kms',
+]);
+
+function isSecuritySensitivePath(path: string): boolean {
+ const terms = path.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase().split(/[^a-z0-9]+/);
+ return terms.some(term => SECURITY_PATH_TERMS.has(term));
+}
+
export class DiffClassifier {
private config: DiffClassifierConfig;
private ruvectorEngine: unknown = null;
@@ -232,6 +247,7 @@ export class DiffClassifier {
let score = 0;
const lowerPath = path.toLowerCase();
for (const [keyword, weight] of Object.entries(IMPACT_KEYWORDS)) { if (lowerPath.includes(keyword)) score = Math.max(score, weight); }
+ if (isSecuritySensitivePath(path)) score = Math.max(score, 3);
const totalChanges = hunks.reduce((sum, h) => sum + h.changes.filter(c => c.type !== 'context').length, 0);
if (totalChanges > 100) score = Math.max(score, 2);
if (totalChanges > 300) score = Math.max(score, 3);
@@ -246,7 +262,7 @@ export class DiffClassifier {
const typeReviewers: Record<string, string[]> = { feature: ['tech-lead', 'product-owner'], bugfix: ['qa-engineer', 'developer'], refactor: ['senior-developer', 'architect'], docs: ['tech-writer', 'developer'], test: ['qa-engineer', 'developer'], config: ['devops', 'tech-lead'], style: ['developer'], unknown: ['developer'] };
reviewers.push(...(typeReviewers[primary] || typeReviewers.unknown));
if (impact === 'critical' || impact === 'high') reviewers.push('security-reviewer');
- if (/security|auth/.test(path)) reviewers.push('security-team');
+ if (isSecuritySensitivePath(path)) reviewers.push('security-team');
if (/database|migration/.test(path)) reviewers.push('dba');
return [...new Set(reviewers)].slice(0, 4);
}
@@ -257,7 +273,7 @@ export class DiffClassifier {
if (primary === 'feature') strategies.push('integration-tests');
if (impact === 'high' || impact === 'critical') { strategies.push('regression-tests'); strategies.push('e2e-tests'); }
if (/api|endpoint|route|handler/.test(path)) strategies.push('api-contract-tests');
- if (/security|auth|crypto/.test(path)) strategies.push('security-audit');
+ if (isSecuritySensitivePath(path)) strategies.push('security-audit');
return strategies.slice(0, 5);
}
@@ -267,7 +283,7 @@ export class DiffClassifier {
if (totalChanges > 200) risks.push('Large change set - increased review time needed');
if (impact === 'critical') risks.push('Critical system component - requires careful review');
if (impact === 'high') risks.push('High-impact area - monitor after deployment');
- if (/security|auth/.test(path)) risks.push('Security-sensitive code');
+ if (isSecuritySensitivePath(path)) risks.push('Security-sensitive code');
if (/database|migration/.test(path)) risks.push('Database changes - ensure backup strategy');
if (/config|env/.test(path)) risks.push('Configuration changes - verify all environments');
const allContent = hunks.flatMap(h => h.changes.map(c => c.content)).join('\n');
@@ -558,7 +574,7 @@ export function assessFileRisk(file: DiffFile): FileRisk {
// Path-based risk
const lowerPath = file.path.toLowerCase();
- if (/security|auth|crypto|password/.test(lowerPath)) {
+ if (isSecuritySensitivePath(file.path)) {
score += 40;
reasons.push('Security-sensitive file');
}
@@ -659,7 +675,7 @@ export function suggestReviewers(files: DiffFile[], fileRisks: FileRisk[]): stri
for (const file of files) {
const lowerPath = file.path.toLowerCase();
- if (/security|auth|crypto/.test(lowerPath)) reviewers.add('security-team');
+ if (isSecuritySensitivePath(file.path)) reviewers.add('security-team');
if (/database|migration/.test(lowerPath)) reviewers.add('dba');
if (/api|endpoint|route/.test(lowerPath)) reviewers.add('api-owner');
if (/test|spec/.test(lowerPath)) reviewers.add('qa-engineer');