@su-record/vibe 2.9.20 → 2.9.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -280,8 +280,89 @@ describe('pre-tool-guard', () => {
|
|
|
280
280
|
tool_name: 'Bash',
|
|
281
281
|
tool_input: { command: 'DROP TABLE users' },
|
|
282
282
|
});
|
|
283
|
-
// tool_input is stringified — pattern matches against the JSON string
|
|
284
283
|
expect(result.exitCode).toBe(2);
|
|
284
|
+
expect(result.stdout).toContain('Database drop detected');
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
// ══════════════════════════════════════════════════
|
|
289
|
+
// Regression: file content false positives (issue: machine-key.ts blocked)
|
|
290
|
+
// .claude/vibe/regressions/pre-tool-guard-content-false-positive.md
|
|
291
|
+
//
|
|
292
|
+
// 이전 구현은 tool_input 전체를 JSON.stringify해서 패턴 매칭했기 때문에
|
|
293
|
+
// 파일 내용에 '/etc/', '.env', 'secret' 같은 리터럴이 있으면 차단됐음.
|
|
294
|
+
// write/edit 패턴은 file_path만 봐야 한다.
|
|
295
|
+
// ══════════════════════════════════════════════════
|
|
296
|
+
describe('regression: write/edit content must not trigger path patterns', () => {
|
|
297
|
+
it('should ALLOW writing safe path even when content contains "/etc/" literal', () => {
|
|
298
|
+
const result = runGuardWithStdin({
|
|
299
|
+
tool_name: 'Write',
|
|
300
|
+
tool_input: {
|
|
301
|
+
file_path: 'src/machine-key.ts',
|
|
302
|
+
content: "for (const path of ['/etc/machine-id', '/var/lib/dbus/machine-id']) {}",
|
|
303
|
+
},
|
|
304
|
+
});
|
|
305
|
+
expect(result.exitCode).toBe(0);
|
|
306
|
+
expect(result.stdout).not.toContain('Writing to system directory');
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it('should ALLOW writing safe path even when content contains "/usr/" literal', () => {
|
|
310
|
+
const result = runGuardWithStdin({
|
|
311
|
+
tool_name: 'Write',
|
|
312
|
+
tool_input: {
|
|
313
|
+
file_path: 'src/cli-detect.ts',
|
|
314
|
+
content: "const IOREG = '/usr/sbin/ioreg';",
|
|
315
|
+
},
|
|
316
|
+
});
|
|
317
|
+
expect(result.exitCode).toBe(0);
|
|
318
|
+
expect(result.stdout).not.toContain('Writing to system directory');
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it('should ALLOW writing safe path even when content mentions ".env" / "secret"', () => {
|
|
322
|
+
const result = runGuardWithStdin({
|
|
323
|
+
tool_name: 'Write',
|
|
324
|
+
tool_input: {
|
|
325
|
+
file_path: 'src/config.ts',
|
|
326
|
+
content: "// loads from .env, never log secret values",
|
|
327
|
+
},
|
|
328
|
+
});
|
|
329
|
+
expect(result.exitCode).toBe(0);
|
|
330
|
+
expect(result.stdout).not.toContain('Writing to sensitive file');
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it('should ALLOW editing safe path even when new_string contains ".env" literal', () => {
|
|
334
|
+
const result = runGuardWithStdin({
|
|
335
|
+
tool_name: 'Edit',
|
|
336
|
+
tool_input: {
|
|
337
|
+
file_path: 'src/index.ts',
|
|
338
|
+
old_string: 'const x = 1',
|
|
339
|
+
new_string: '// reads .env at startup',
|
|
340
|
+
},
|
|
341
|
+
});
|
|
342
|
+
expect(result.exitCode).toBe(0);
|
|
343
|
+
expect(result.stdout).not.toContain('Editing sensitive file');
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
it('should still BLOCK Write when file_path itself targets /etc/', () => {
|
|
347
|
+
const result = runGuardWithStdin({
|
|
348
|
+
tool_name: 'Write',
|
|
349
|
+
tool_input: { file_path: '/etc/passwd', content: 'root:x:0:0' },
|
|
350
|
+
});
|
|
351
|
+
expect(result.exitCode).toBe(2);
|
|
352
|
+
expect(result.stdout).toContain('Writing to system directory');
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
it('should still WARN Edit when file_path itself is a credentials file', () => {
|
|
356
|
+
const result = runGuardWithStdin({
|
|
357
|
+
tool_name: 'Edit',
|
|
358
|
+
tool_input: {
|
|
359
|
+
file_path: 'config/credentials.json',
|
|
360
|
+
old_string: 'a',
|
|
361
|
+
new_string: 'b',
|
|
362
|
+
},
|
|
363
|
+
});
|
|
364
|
+
expect(result.exitCode).toBe(0);
|
|
365
|
+
expect(result.stdout).toContain('Editing sensitive file');
|
|
285
366
|
});
|
|
286
367
|
});
|
|
287
368
|
});
|
|
@@ -7,26 +7,35 @@
|
|
|
7
7
|
import { VIBE_PATH, PROJECT_DIR } from './utils.js';
|
|
8
8
|
|
|
9
9
|
// 위험한 명령어 패턴
|
|
10
|
+
//
|
|
11
|
+
// 각 엔트리의 `target`은 매칭 대상 필드:
|
|
12
|
+
// - 'command' → tool_input.command (Bash)
|
|
13
|
+
// - 'file_path' → tool_input.file_path (Write, Edit)
|
|
14
|
+
// - 'raw' → 전체 문자열 (스키마 모를 때 폴백)
|
|
15
|
+
//
|
|
16
|
+
// 예전 버전은 항상 stringify된 tool_input 전체에 매칭하여 file content가
|
|
17
|
+
// 패턴(예: /etc/, .env)과 일치하면 false positive로 차단되는 버그가 있었음.
|
|
18
|
+
// 회귀: .claude/vibe/regressions/pre-tool-guard-content-false-positive.md
|
|
10
19
|
const DANGEROUS_PATTERNS = {
|
|
11
20
|
bash: [
|
|
12
|
-
{ pattern: /rm\s+-rf?\s+[\/~]/, severity: 'critical', message: 'Deleting root or home directory' },
|
|
13
|
-
{ pattern: /rm\s+-rf?\s+\*/, severity: 'high', message: 'Wildcard deletion detected' },
|
|
14
|
-
{ pattern: /git\s+push\s+.*--force/, severity: 'high', message: 'Force push detected' },
|
|
15
|
-
{ pattern: /git\s+reset\s+--hard/, severity: 'medium', message: 'Hard reset will discard changes' },
|
|
16
|
-
{ pattern: /drop\s+(table|database)/i, severity: 'critical', message: 'Database drop detected' },
|
|
17
|
-
{ pattern: /truncate\s+table/i, severity: 'high', message: 'Table truncate detected' },
|
|
18
|
-
{ pattern: /:(){ :|:& };:/, severity: 'critical', message: 'Fork bomb detected' },
|
|
19
|
-
{ pattern: /mkfs|fdisk|dd\s+if=/, severity: 'critical', message: 'Disk operation detected' },
|
|
20
|
-
{ pattern: /chmod\s+-R\s+777/, severity: 'medium', message: 'Insecure permission change' },
|
|
21
|
-
{ pattern: /curl.*\|\s*(ba)?sh/, severity: 'high', message: 'Piping curl to shell' },
|
|
21
|
+
{ pattern: /rm\s+-rf?\s+[\/~]/, target: 'command', severity: 'critical', message: 'Deleting root or home directory' },
|
|
22
|
+
{ pattern: /rm\s+-rf?\s+\*/, target: 'command', severity: 'high', message: 'Wildcard deletion detected' },
|
|
23
|
+
{ pattern: /git\s+push\s+.*--force/, target: 'command', severity: 'high', message: 'Force push detected' },
|
|
24
|
+
{ pattern: /git\s+reset\s+--hard/, target: 'command', severity: 'medium', message: 'Hard reset will discard changes' },
|
|
25
|
+
{ pattern: /drop\s+(table|database)/i, target: 'command', severity: 'critical', message: 'Database drop detected' },
|
|
26
|
+
{ pattern: /truncate\s+table/i, target: 'command', severity: 'high', message: 'Table truncate detected' },
|
|
27
|
+
{ pattern: /:(){ :|:& };:/, target: 'command', severity: 'critical', message: 'Fork bomb detected' },
|
|
28
|
+
{ pattern: /mkfs|fdisk|dd\s+if=/, target: 'command', severity: 'critical', message: 'Disk operation detected' },
|
|
29
|
+
{ pattern: /chmod\s+-R\s+777/, target: 'command', severity: 'medium', message: 'Insecure permission change' },
|
|
30
|
+
{ pattern: /curl.*\|\s*(ba)?sh/, target: 'command', severity: 'high', message: 'Piping curl to shell' },
|
|
22
31
|
],
|
|
23
32
|
edit: [
|
|
24
|
-
{ pattern: /\.env|credentials|secret|password|api[_-]?key/i, severity: 'medium', message: 'Editing sensitive file' },
|
|
25
|
-
{ pattern: /package-lock\.json|yarn\.lock|pnpm-lock/, severity: 'low', message: 'Editing lock file directly' },
|
|
33
|
+
{ pattern: /\.env|credentials|secret|password|api[_-]?key/i, target: 'file_path', severity: 'medium', message: 'Editing sensitive file' },
|
|
34
|
+
{ pattern: /package-lock\.json|yarn\.lock|pnpm-lock/, target: 'file_path', severity: 'low', message: 'Editing lock file directly' },
|
|
26
35
|
],
|
|
27
36
|
write: [
|
|
28
|
-
{ pattern: /\.env|credentials|secret/i, severity: 'medium', message: 'Writing to sensitive file' },
|
|
29
|
-
{ pattern: /\/etc\/|\/usr\/|C:\\Windows/i, severity: 'critical', message: 'Writing to system directory' },
|
|
37
|
+
{ pattern: /\.env|credentials|secret/i, target: 'file_path', severity: 'medium', message: 'Writing to sensitive file' },
|
|
38
|
+
{ pattern: /\/etc\/|\/usr\/|C:\\Windows/i, target: 'file_path', severity: 'critical', message: 'Writing to system directory' },
|
|
30
39
|
],
|
|
31
40
|
};
|
|
32
41
|
|
|
@@ -82,10 +91,39 @@ const SAFE_ALTERNATIVES = {
|
|
|
82
91
|
'chmod 777': 'Use specific permissions (e.g., chmod 755 for directories)',
|
|
83
92
|
};
|
|
84
93
|
|
|
94
|
+
/**
|
|
95
|
+
* 패턴 매칭 대상 추출
|
|
96
|
+
*
|
|
97
|
+
* tool_input이 객체이면 target 필드만 뽑아 반환. 객체가 아니거나(레거시 argv 모드)
|
|
98
|
+
* target='raw'이면 입력 전체를 그대로 반환.
|
|
99
|
+
*
|
|
100
|
+
* 핵심: write/edit 패턴은 file_path만 봐야 한다. content에 우연히 들어간
|
|
101
|
+
* 리터럴(예: 코드 안의 '/etc/machine-id' 문자열)이 차단을 일으키지 않도록.
|
|
102
|
+
*/
|
|
103
|
+
function extractTarget(rawInput, target) {
|
|
104
|
+
if (target === 'raw') return typeof rawInput === 'string' ? rawInput : JSON.stringify(rawInput);
|
|
105
|
+
|
|
106
|
+
// 객체로 파싱 시도
|
|
107
|
+
let obj = rawInput;
|
|
108
|
+
if (typeof rawInput === 'string') {
|
|
109
|
+
try {
|
|
110
|
+
obj = JSON.parse(rawInput);
|
|
111
|
+
} catch {
|
|
112
|
+
// JSON 아님 → 레거시 argv 모드. argv[3]은 보통 file_path 또는 command 단일 문자열.
|
|
113
|
+
// 안전하게 그 문자열을 target 값으로 간주.
|
|
114
|
+
return rawInput;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (typeof obj !== 'object' || obj === null) return '';
|
|
119
|
+
const value = obj[target];
|
|
120
|
+
return typeof value === 'string' ? value : '';
|
|
121
|
+
}
|
|
122
|
+
|
|
85
123
|
/**
|
|
86
124
|
* 명령어 검증
|
|
87
125
|
*/
|
|
88
|
-
function validateCommand(toolName,
|
|
126
|
+
function validateCommand(toolName, rawInput) {
|
|
89
127
|
const results = {
|
|
90
128
|
allowed: true,
|
|
91
129
|
severity: 'none',
|
|
@@ -95,8 +133,11 @@ function validateCommand(toolName, input) {
|
|
|
95
133
|
|
|
96
134
|
const patterns = DANGEROUS_PATTERNS[toolName.toLowerCase()] || [];
|
|
97
135
|
|
|
98
|
-
for (const { pattern, severity, message } of patterns) {
|
|
99
|
-
|
|
136
|
+
for (const { pattern, target, severity, message } of patterns) {
|
|
137
|
+
const haystack = extractTarget(rawInput, target || 'raw');
|
|
138
|
+
if (!haystack) continue;
|
|
139
|
+
|
|
140
|
+
if (pattern.test(haystack)) {
|
|
100
141
|
results.warnings.push(`[${severity.toUpperCase()}] ${message}`);
|
|
101
142
|
|
|
102
143
|
// 심각도에 따른 처리
|
|
@@ -109,9 +150,9 @@ function validateCommand(toolName, input) {
|
|
|
109
150
|
results.severity = severity;
|
|
110
151
|
}
|
|
111
152
|
|
|
112
|
-
// 대안 제안
|
|
153
|
+
// 대안 제안 — 매칭된 target 필드에서만 검색
|
|
113
154
|
for (const [dangerous, safe] of Object.entries(SAFE_ALTERNATIVES)) {
|
|
114
|
-
if (
|
|
155
|
+
if (haystack.includes(dangerous)) {
|
|
115
156
|
results.suggestions.push(safe);
|
|
116
157
|
}
|
|
117
158
|
}
|