Skip to main content
Glama

review.security.validate-mapfile

Validate mapfile path and content against security policy to ensure compliance and prevent unauthorized access in Re:VIEW manuscripts.

Instructions

Validate mapfile path and content against security policy

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cwdYes
filepathYes

Implementation Reference

  • Main execution handler for the tool. Loads security configuration, performs path validation, size check, reads and sanitizes the mapfile content, and returns structured validation results.
    case "review.security.validate-mapfile": {
      const config = await loadSecurityConfig(args.cwd as string);
      const pathValidation = validateMapfilePath(args.filepath as string, config);
      
      if (!pathValidation.valid) {
        return {
          content: [
            { 
              type: "text", 
              text: JSON.stringify({ 
                valid: false, 
                reason: pathValidation.reason,
                config: { source: config.source }
              }) 
            }
          ]
        };
      }
    
      const sizeValidation = await validateMapfileSize(
        args.filepath as string,
        args.cwd as string,
        config
      );
    
      if (!sizeValidation.valid) {
        return {
          content: [
            { 
              type: "text", 
              text: JSON.stringify({ 
                valid: false, 
                reason: sizeValidation.reason,
                size: sizeValidation.size,
                config: { source: config.source, maxFileSize: config.maxFileSize }
              }) 
            }
          ]
        };
      }
    
      const fullPath = path.join(args.cwd as string, args.filepath as string);
      try {
        const content = await fs.readFile(fullPath, "utf-8");
        const sanitization = await sanitizeMapfile(content, args.filepath as string, config);
        
        return {
          content: [
            { 
              type: "text", 
              text: JSON.stringify({ 
                valid: sanitization.safe,
                size: sizeValidation.size,
                issues: sanitization.issues,
                config: { source: config.source }
              }) 
            }
          ]
        };
      } catch (error: any) {
        return {
          content: [
            { 
              type: "text", 
              text: JSON.stringify({ 
                valid: false, 
                error: error.message 
              }) 
            }
          ]
        };
      }
    }
  • Tool schema definition including name, description, and input schema requiring 'cwd' and 'filepath'.
    {
      name: "review.security.validate-mapfile",
      description: "Validate mapfile path and content against security policy",
      inputSchema: {
        type: "object",
        properties: {
          cwd: { type: "string" },
          filepath: { type: "string" }
        },
        required: ["cwd", "filepath"]
      }
    },
  • Helper function to validate the filepath against security rules: blocks absolute paths, traversal, invalid extensions, and ensures path is in allowed directories.
    export function validateMapfilePath(
      filepath: string,
      config: SecurityConfig
    ): { valid: boolean; reason?: string } {
      
      if (config.blockAbsolutePaths && path.isAbsolute(filepath)) {
        return { valid: false, reason: "Absolute paths are not allowed" };
      }
    
      if (config.blockTraversal && (filepath.includes("../") || filepath.includes("..\\"))) {
        return { valid: false, reason: "Path traversal is not allowed" };
      }
    
      const ext = path.extname(filepath).toLowerCase();
      if (config.allowedExtensions.length > 0 && !config.allowedExtensions.includes(ext)) {
        return { 
          valid: false, 
          reason: `File extension '${ext}' is not allowed. Allowed: ${config.allowedExtensions.join(", ")}` 
        };
      }
    
      const normalizedPath = filepath.replace(/\\/g, "/");
      const isInAllowedPath = config.allowedPaths.length === 0 || 
        config.allowedPaths.some(allowed => normalizedPath.startsWith(allowed));
      
      if (!isInAllowedPath) {
        return { 
          valid: false, 
          reason: `Path must be within allowed directories: ${config.allowedPaths.join(", ")}` 
        };
      }
    
      return { valid: true };
    }
  • Helper function to check file size against the configured maximum.
    export async function validateMapfileSize(
      filepath: string,
      cwd: string,
      config: SecurityConfig
    ): Promise<{ valid: boolean; reason?: string; size?: number }> {
      
      const fullPath = path.join(cwd, filepath);
      
      try {
        const stats = await fs.stat(fullPath);
        
        if (stats.size > config.maxFileSize) {
          return {
            valid: false,
            reason: `File size (${stats.size} bytes) exceeds maximum allowed size (${config.maxFileSize} bytes)`,
            size: stats.size
          };
        }
        
        return { valid: true, size: stats.size };
      } catch (error: any) {
        return {
          valid: false,
          reason: `Cannot access file: ${error.message}`
        };
      }
    }
  • Helper function to sanitize mapfile content by scanning for suspicious patterns like eval, require, etc.
    export async function sanitizeMapfile(
      content: string,
      filepath: string,
      config: SecurityConfig
    ): Promise<{ safe: boolean; sanitized?: string; issues: string[] }> {
      
      const issues: string[] = [];
      
      const suspiciousPatterns = [
        /eval\s*\(/gi,
        /require\s*\(/gi,
        /import\s+/gi,
        /__import__/gi,
        /exec\s*\(/gi,
        /system\s*\(/gi,
        /`[^`]*`/g
      ];
      
      for (const pattern of suspiciousPatterns) {
        if (pattern.test(content)) {
          issues.push(`Suspicious pattern detected: ${pattern.source}`);
        }
      }
      
      if (issues.length > 0) {
        return { safe: false, issues };
      }
      
      return { safe: true, sanitized: content, issues: [] };
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool validates against security policy but doesn't explain what happens during validation (e.g., returns errors, logs issues, blocks execution) or any constraints (e.g., file size limits, permission requirements). This is inadequate for a tool with potential security implications.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose without unnecessary words. Every part of the sentence ('Validate mapfile path and content against security policy') contributes directly to understanding the tool's function, making it highly concise and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (security validation tool), lack of annotations, no output schema, and low schema coverage, the description is incomplete. It doesn't cover behavioral aspects (e.g., what validation entails, error handling), parameter semantics, or usage context. This leaves significant gaps for an agent to invoke the tool correctly in a security-sensitive scenario.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 2 parameters (cwd, filepath) with 0% description coverage, meaning no parameter details are documented in the schema. The description doesn't add any meaning beyond the parameter names—it doesn't explain what 'cwd' and 'filepath' represent (e.g., current working directory and relative/absolute path) or how they interact. This fails to compensate for the low schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Validate mapfile path and content against security policy.' It specifies the action (validate), target (mapfile path and content), and criteria (security policy). However, it doesn't explicitly distinguish this tool from sibling tools like 'review.security.compare' or 'review.test-mapfile', which might have overlapping validation functions.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites, context (e.g., during code review or deployment), or compare it to siblings like 'review.security.compare' or 'review.test-mapfile'. This leaves the agent guessing about appropriate usage scenarios.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/dsgarage/ReviewMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server