diff --git a/src/index.ts b/src/index.ts index d23fd3c..7113938 100644 --- a/src/index.ts +++ b/src/index.ts @@ -192,8 +192,10 @@ Args: - read (string[]): Allowed read paths - write (string[]): Allowed write paths - net (string[]): Allowed network hosts - - skipDangerousPatternCheck (boolean): Skip dangerous pattern validation (optional, default: false) - Can be overridden by CODE_EXECUTOR_SKIP_DANGEROUS_PATTERNS env var or config file + - skipDangerousPatternCheck (boolean): Accepted for backward compatibility but IGNORED (issue #56) + Per-call skipping is intentionally disabled so a caller cannot bypass the check. + Validation can only be disabled SERVER-SIDE via the CODE_EXECUTOR_SKIP_DANGEROUS_PATTERNS + env var (=true) or the security.skipDangerousPatternCheck config option (operator decision). NOTE: Dangerous pattern validation is defense-in-depth only, NOT a security boundary Real security comes from sandbox permissions, resource limits, and process isolation @@ -222,7 +224,7 @@ Example: write: z.array(z.string()).optional(), net: z.array(z.string()).optional(), }).default({}).describe('Deno sandbox permissions'), - skipDangerousPatternCheck: z.boolean().optional().describe('Skip dangerous pattern validation (defense-in-depth only)'), + skipDangerousPatternCheck: z.boolean().optional().describe('Accepted but IGNORED for security (issue #56): per-call skipping is disabled. Validation can only be disabled server-side via the CODE_EXECUTOR_SKIP_DANGEROUS_PATTERNS env var or security.skipDangerousPatternCheck config option.'), enableSampling: z.boolean().optional().default(false).describe('Enable LLM sampling (llm.ask/llm.think helpers)'), maxSamplingRounds: z.number().int().min(1).max(100).optional().default(10).describe('Max sampling rounds'), maxSamplingTokens: z.number().int().min(100).max(100000).optional().default(10000).describe('Max sampling tokens'), @@ -453,8 +455,10 @@ Args: Example: ['mcp__zen__codereview', 'mcp__filesystem__read_file'] - timeoutMs (number): Execution timeout in milliseconds (default: 30000) - permissions (object): Subprocess permissions (limited to temp directory and localhost) - - skipDangerousPatternCheck (boolean): Skip dangerous pattern validation (optional, default: false) - Can be overridden by CODE_EXECUTOR_SKIP_DANGEROUS_PATTERNS env var or config file + - skipDangerousPatternCheck (boolean): Accepted for backward compatibility but IGNORED (issue #56) + Per-call skipping is intentionally disabled so a caller cannot bypass the check. + Validation can only be disabled SERVER-SIDE via the CODE_EXECUTOR_SKIP_DANGEROUS_PATTERNS + env var (=true) or the security.skipDangerousPatternCheck config option (operator decision). NOTE: Dangerous pattern validation is defense-in-depth only, NOT a security boundary Real security comes from sandbox permissions, resource limits, and process isolation @@ -483,7 +487,7 @@ Example: write: z.array(z.string()).optional(), net: z.array(z.string()).optional(), }).default({}).describe('Subprocess permissions'), - skipDangerousPatternCheck: z.boolean().optional().describe('Skip dangerous pattern validation (defense-in-depth only)'), + skipDangerousPatternCheck: z.boolean().optional().describe('Accepted but IGNORED for security (issue #56): per-call skipping is disabled. Validation can only be disabled server-side via the CODE_EXECUTOR_SKIP_DANGEROUS_PATTERNS env var or security.skipDangerousPatternCheck config option.'), enableSampling: z.boolean().optional().default(false).describe('Enable LLM sampling (llm.ask/llm.think helpers)'), maxSamplingRounds: z.number().int().min(1).max(100).optional().default(10).describe('Max sampling rounds'), maxSamplingTokens: z.number().int().min(100).max(100000).optional().default(10000).describe('Max sampling tokens'), diff --git a/src/validation/security-validator.ts b/src/validation/security-validator.ts index b1ce183..921ccd1 100644 --- a/src/validation/security-validator.ts +++ b/src/validation/security-validator.ts @@ -172,10 +172,23 @@ export class SecurityValidator { if (!skipDangerousPatternCheck) { for (const pattern of DANGEROUS_PATTERNS) { if (pattern.test(code)) { - // SECURITY: Use generic error message to avoid revealing exact pattern + // SECURITY: Use generic message — never reveal which pattern matched. + // The message states the block is TERMINAL and names the working + // server-side bypass, so callers stop retry-looping reworded variants + // on a non-retryable refusal (see issue #7). Note: the per-call + // skipDangerousPatternCheck request param is intentionally ignored + // (issue #56) — only the env var / config option can disable this. errors.push( - `Code contains potentially dangerous pattern. ` + - `This pattern is blocked as defense-in-depth protection.` + `Code contains a potentially dangerous pattern and was blocked as ` + + `defense-in-depth protection. This is a terminal validation result, ` + + `not a transient error — do not retry with reworded code, as the ` + + `block will recur. If the token appears only as text or data (e.g. ` + + `inside a string, comment, or documentation) and the call is ` + + `legitimate, an operator can disable this server-side check by ` + + `setting the CODE_EXECUTOR_SKIP_DANGEROUS_PATTERNS=true environment ` + + `variable (or the security.skipDangerousPatternCheck config option). ` + + `The per-call skipDangerousPatternCheck request parameter is ` + + `intentionally ignored for security and cannot bypass this check.` ); } } diff --git a/tests/security/pattern-bypass.test.ts b/tests/security/pattern-bypass.test.ts index e8a32ef..8a0aa00 100644 --- a/tests/security/pattern-bypass.test.ts +++ b/tests/security/pattern-bypass.test.ts @@ -9,7 +9,7 @@ */ import { describe, it, expect, beforeEach } from 'vitest'; -import { SecurityValidator } from '../../src/security.js'; +import { SecurityValidator } from '../../src/validation/security-validator.js'; describe('Dangerous Pattern Validation Bypass Attacks (P0 Security)', () => { let validator: SecurityValidator; @@ -253,4 +253,40 @@ describe('Dangerous Pattern Validation Bypass Attacks (P0 Security)', () => { expect(result.errors.length).toBe(0); }); }); + + describe('Terminal refusal message guidance (Issue #7)', () => { + // The refusal must tell the caller the block is TERMINAL (not a transient + // error) and name the working server-level bypass, so agents stop + // retry-looping reworded variants on a non-retryable refusal. + function firstError(code: string): string { + const result = validator.validateCode(code); + expect(result.valid).toBe(false); + expect(result.errors.length).toBeGreaterThan(0); + return result.errors[0]; + } + + it('should_keep_dangerousPattern_phrase_for_backCompat', () => { + // Existing consumers assert on this substring — must be preserved. + expect(firstError('eval("x")')).toContain('dangerous pattern'); + }); + + it('should_state_refusal_is_terminal', () => { + const msg = firstError('eval("x")'); + expect(msg).toMatch(/terminal/i); + expect(msg).toMatch(/do not retry/i); + }); + + it('should_name_working_serverLevel_bypass_envVar', () => { + expect(firstError('eval("x")')).toContain('CODE_EXECUTOR_SKIP_DANGEROUS_PATTERNS'); + }); + + it('should_clarify_perCall_param_is_ignored', () => { + // The per-call skipDangerousPatternCheck request param is intentionally + // ignored (Issue #56). The message must not mislead callers into retrying + // with it. + const msg = firstError('eval("x")'); + expect(msg).toMatch(/skipDangerousPatternCheck/); + expect(msg).toMatch(/ignored/i); + }); + }); });