Skip to main content
Glama

security.test_xss

Test web applications for Cross-Site Scripting vulnerabilities using non-destructive payloads to identify security weaknesses in target URLs and parameters.

Instructions

Test for XSS vulnerabilities (non-destructive payloads)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesTarget URL
paramsNoParameters to test (key-value pairs)
methodNoHTTP methodGET

Implementation Reference

  • The main async handler function implementing the security.test_xss tool logic. Tests target URL with multiple XSS payloads, checks for reflections in body/headers, determines vulnerability, saves findings to database if detected, and returns formatted ToolResult with test summary.
    async ({ url, params = {}, method = 'GET' }: any): Promise<ToolResult> => {
      try {
        const payloads = [
          '<script>alert(1)</script>',
          '"><img src=x onerror=alert(1)>',
          "'><svg onload=alert(1)>",
          'javascript:alert(1)',
          '<iframe src=javascript:alert(1)>',
        ];
    
        const results: SecurityTestResult[] = [];
    
        for (const payload of payloads) {
          try {
            let response: AxiosResponse;
            const testParams = { ...params, test: payload };
    
            if (method === 'GET') {
              response = await axios.get(url, {
                params: testParams,
                validateStatus: () => true,
                timeout: 15000,
                headers: {
                  'User-Agent': 'Mozilla/5.0',
                },
              });
            } else {
              response = await axios.post(url, testParams, {
                validateStatus: () => true,
                timeout: 15000,
                headers: {
                  'User-Agent': 'Mozilla/5.0',
                  'Content-Type': 'application/x-www-form-urlencoded',
                },
              });
            }
    
            const body = typeof response.data === 'string' ? response.data : JSON.stringify(response.data);
            const reflected = body.includes(payload);
            const inHeaders = JSON.stringify(response.headers).includes(payload);
    
            const result: SecurityTestResult = {
              payload,
              response: {
                status: response.status,
                reflected,
                inHeaders,
                bodyLength: body.length,
              },
            };
    
            if (reflected || inHeaders) {
              result.vulnerability = 'XSS';
              result.severity = 'high';
              
              await saveFinding({
                target: url,
                type: 'XSS',
                severity: 'high',
                description: `Potential XSS vulnerability - payload reflected: ${payload}`,
                payload,
                response: body.substring(0, 1000),
                timestamp: new Date(),
                score: 8,
              });
            }
    
            results.push(result);
          } catch (error: any) {
            results.push({
              payload,
              error: error.message,
            });
          }
        }
    
        const xssScore = results.some((r: any) => r.vulnerable) ? 7 : 3;
        await saveTestResult(url, 'xss_test', true, { results }, undefined, xssScore, JSON.stringify(params), JSON.stringify(results));
    
        return formatToolResult(true, {
          results,
          summary: {
            totalTests: payloads.length,
            potentialVulns: results.filter((r) => r.vulnerability).length,
          },
        });
      } catch (error: any) {
        await saveTestResult(url, 'xss_test', false, null, error.message, 0, undefined, undefined);
        return formatToolResult(false, null, error.message);
      }
    }
  • InputSchema object defining the tool's parameters: url (required string), params (optional object), method (optional string enum GET/POST/PUT with default GET).
      description: 'Test for XSS vulnerabilities (non-destructive payloads)',
      inputSchema: {
        type: 'object',
        properties: {
          url: { type: 'string', description: 'Target URL' },
          params: {
            type: 'object',
            description: 'Parameters to test (key-value pairs)',
          },
          method: {
            type: 'string',
            description: 'HTTP method',
            enum: ['GET', 'POST', 'PUT'],
            default: 'GET',
          },
        },
        required: ['url'],
      },
    },
  • server.tool('security.test_xss', schema, handler) call within registerSecurityTools function, registering the tool on the MCP Server instance.
      'security.test_xss',
      {
        description: 'Test for XSS vulnerabilities (non-destructive payloads)',
        inputSchema: {
          type: 'object',
          properties: {
            url: { type: 'string', description: 'Target URL' },
            params: {
              type: 'object',
              description: 'Parameters to test (key-value pairs)',
            },
            method: {
              type: 'string',
              description: 'HTTP method',
              enum: ['GET', 'POST', 'PUT'],
              default: 'GET',
            },
          },
          required: ['url'],
        },
      },
      async ({ url, params = {}, method = 'GET' }: any): Promise<ToolResult> => {
        try {
          const payloads = [
            '<script>alert(1)</script>',
            '"><img src=x onerror=alert(1)>',
            "'><svg onload=alert(1)>",
            'javascript:alert(1)',
            '<iframe src=javascript:alert(1)>',
          ];
    
          const results: SecurityTestResult[] = [];
    
          for (const payload of payloads) {
            try {
              let response: AxiosResponse;
              const testParams = { ...params, test: payload };
    
              if (method === 'GET') {
                response = await axios.get(url, {
                  params: testParams,
                  validateStatus: () => true,
                  timeout: 15000,
                  headers: {
                    'User-Agent': 'Mozilla/5.0',
                  },
                });
              } else {
                response = await axios.post(url, testParams, {
                  validateStatus: () => true,
                  timeout: 15000,
                  headers: {
                    'User-Agent': 'Mozilla/5.0',
                    'Content-Type': 'application/x-www-form-urlencoded',
                  },
                });
              }
    
              const body = typeof response.data === 'string' ? response.data : JSON.stringify(response.data);
              const reflected = body.includes(payload);
              const inHeaders = JSON.stringify(response.headers).includes(payload);
    
              const result: SecurityTestResult = {
                payload,
                response: {
                  status: response.status,
                  reflected,
                  inHeaders,
                  bodyLength: body.length,
                },
              };
    
              if (reflected || inHeaders) {
                result.vulnerability = 'XSS';
                result.severity = 'high';
                
                await saveFinding({
                  target: url,
                  type: 'XSS',
                  severity: 'high',
                  description: `Potential XSS vulnerability - payload reflected: ${payload}`,
                  payload,
                  response: body.substring(0, 1000),
                  timestamp: new Date(),
                  score: 8,
                });
              }
    
              results.push(result);
            } catch (error: any) {
              results.push({
                payload,
                error: error.message,
              });
            }
          }
    
          const xssScore = results.some((r: any) => r.vulnerable) ? 7 : 3;
          await saveTestResult(url, 'xss_test', true, { results }, undefined, xssScore, JSON.stringify(params), JSON.stringify(results));
    
          return formatToolResult(true, {
            results,
            summary: {
              totalTests: payloads.length,
              potentialVulns: results.filter((r) => r.vulnerability).length,
            },
          });
        } catch (error: any) {
          await saveTestResult(url, 'xss_test', false, null, error.message, 0, undefined, undefined);
          return formatToolResult(false, null, error.message);
        }
      }
    );
  • src/index.ts:37-37 (registration)
    Invocation of registerSecurityTools(server) in main server setup, which registers the security.test_xss tool among others.
    registerSecurityTools(server);
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 mentions 'non-destructive payloads,' which hints at safety but doesn't fully describe behavioral traits like whether it requires authentication, what the output format is, if it has rate limits, or how it handles errors. This leaves significant gaps for an agent to understand how to invoke it effectively.

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: 'Test for XSS vulnerabilities (non-destructive payloads).' It's front-loaded with the core purpose and includes a useful qualifier without unnecessary details. Every word earns its place, making it easy for an agent to parse quickly.

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 of a security testing tool with no annotations and no output schema, the description is incomplete. It lacks details on what the tool returns, how to interpret results, prerequisites, or error handling. While it states the purpose, it doesn't provide enough context for an agent to use it confidently in a security testing workflow.

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?

Schema description coverage is 100%, so the schema already documents all parameters (url, params, method) with descriptions and enums. The description adds no additional parameter semantics beyond what's in the schema, such as explaining the format of 'params' or typical usage patterns. Baseline 3 is appropriate when the schema does the heavy lifting.

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: 'Test for XSS vulnerabilities' with the qualifier 'non-destructive payloads.' It specifies both the action (test) and the resource (XSS vulnerabilities), distinguishing it from other security testing tools like security.test_sqli or security.test_csrf. However, it doesn't explicitly differentiate from security.test_auth_bypass or security.test_idor beyond the vulnerability type.

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 minimal guidance: it implies usage for XSS testing with non-destructive payloads, but offers no explicit when-to-use rules, alternatives, or exclusions. For example, it doesn't clarify if this is for initial reconnaissance vs. deep testing, or when to use this versus other XSS-related tools that might exist in the sibling list.

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