Skip to main content
Glama

security.test_csp

Test Content Security Policy configurations to identify security vulnerabilities and misconfigurations in web applications.

Instructions

Test Content Security Policy configuration

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesTarget URL

Implementation Reference

  • Handler function that performs CSP testing by fetching the target URL, parsing CSP headers, checking for common misconfigurations like unsafe-inline or unsafe-eval, logging findings if issues detected, and returning results.
    async ({ url }: any): Promise<ToolResult> => {
      try {
        const response = await axios.get(url, {
          validateStatus: () => true,
          timeout: 15000,
        });
    
        const cspHeader = response.headers['content-security-policy'] ||
          response.headers['x-content-security-policy'];
    
        const issues: string[] = [];
        let severity: 'low' | 'medium' | 'high' = 'low';
    
        if (!cspHeader) {
          issues.push('No CSP header found');
          severity = 'medium';
        } else {
          if (!cspHeader.includes("'unsafe-inline'") && cspHeader.includes('script-src')) {
            // Good - no unsafe-inline
          } else if (cspHeader.includes("'unsafe-inline'")) {
            issues.push("CSP allows 'unsafe-inline' in script-src");
            severity = 'high';
          }
    
          if (!cspHeader.includes("'unsafe-eval'") && cspHeader.includes('script-src')) {
            // Good
          } else if (cspHeader.includes("'unsafe-eval'")) {
            issues.push("CSP allows 'unsafe-eval'");
            severity = 'medium';
          }
    
          if (!cspHeader.includes('default-src')) {
            issues.push('No default-src directive');
            severity = 'medium';
          }
        }
    
        if (issues.length > 0 && severity !== 'low') {
          await saveFinding({
            target: url,
            type: 'CSP Misconfiguration',
            severity,
            description: `CSP issues: ${issues.join(', ')}`,
            response: cspHeader || 'No CSP header',
            timestamp: new Date(),
            score: severity === 'high' ? 6 : 4,
          });
        }
    
        return formatToolResult(true, {
          cspHeader: cspHeader || null,
          issues,
          severity,
          secure: issues.length === 0,
        });
      } catch (error: any) {
        return formatToolResult(false, null, error.message);
      }
    }
  • Schema definition for the tool input, requiring a 'url' parameter.
    {
      description: 'Test Content Security Policy configuration',
      inputSchema: {
        type: 'object',
        properties: {
          url: { type: 'string', description: 'Target URL' },
        },
        required: ['url'],
      },
    },
  • Registration of the 'security.test_csp' tool on the MCP server, including name, schema, and handler function.
    // CSP Testing
    server.tool(
      'security.test_csp',
      {
        description: 'Test Content Security Policy configuration',
        inputSchema: {
          type: 'object',
          properties: {
            url: { type: 'string', description: 'Target URL' },
          },
          required: ['url'],
        },
      },
      async ({ url }: any): Promise<ToolResult> => {
        try {
          const response = await axios.get(url, {
            validateStatus: () => true,
            timeout: 15000,
          });
    
          const cspHeader = response.headers['content-security-policy'] ||
            response.headers['x-content-security-policy'];
    
          const issues: string[] = [];
          let severity: 'low' | 'medium' | 'high' = 'low';
    
          if (!cspHeader) {
            issues.push('No CSP header found');
            severity = 'medium';
          } else {
            if (!cspHeader.includes("'unsafe-inline'") && cspHeader.includes('script-src')) {
              // Good - no unsafe-inline
            } else if (cspHeader.includes("'unsafe-inline'")) {
              issues.push("CSP allows 'unsafe-inline' in script-src");
              severity = 'high';
            }
    
            if (!cspHeader.includes("'unsafe-eval'") && cspHeader.includes('script-src')) {
              // Good
            } else if (cspHeader.includes("'unsafe-eval'")) {
              issues.push("CSP allows 'unsafe-eval'");
              severity = 'medium';
            }
    
            if (!cspHeader.includes('default-src')) {
              issues.push('No default-src directive');
              severity = 'medium';
            }
          }
    
          if (issues.length > 0 && severity !== 'low') {
            await saveFinding({
              target: url,
              type: 'CSP Misconfiguration',
              severity,
              description: `CSP issues: ${issues.join(', ')}`,
              response: cspHeader || 'No CSP header',
              timestamp: new Date(),
              score: severity === 'high' ? 6 : 4,
            });
          }
    
          return formatToolResult(true, {
            cspHeader: cspHeader || null,
            issues,
            severity,
            secure: issues.length === 0,
          });
        } catch (error: any) {
          return formatToolResult(false, null, error.message);
        }
      }
    );
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. 'Test' implies a read-only diagnostic operation, but the description doesn't specify whether this is passive scanning, active testing, what permissions are required, what the output format might be, or any rate limits. For a security testing tool, this leaves significant behavioral questions unanswered.

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 phrase that communicates the core purpose without any wasted words. It's appropriately sized for a tool with one simple parameter and gets straight to the point.

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?

For a security testing tool with no annotations and no output schema, the description is insufficient. It doesn't explain what 'testing' entails, what kind of results to expect, whether this modifies the target system, or how it integrates with other security tools in the sibling list. The description leaves too many contextual questions unanswered.

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

Parameters3/5

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

The input schema has 100% description coverage with the 'url' parameter clearly documented as 'Target URL'. The description adds no additional parameter information beyond what's already in the schema. With complete schema coverage, the baseline score of 3 is appropriate.

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 'Test Content Security Policy configuration' clearly states the verb ('Test') and resource ('Content Security Policy configuration'), making the purpose immediately understandable. However, it doesn't distinguish this tool from sibling security testing tools like 'security.test_auth_bypass' or 'security.test_xss' beyond the CSP focus.

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. There's no mention of prerequisites, typical use cases, or how it differs from other security testing tools in the sibling list. The agent must infer usage from the tool name alone.

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/telmon95/VulneraMCP'

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