logo

Database

Javascript Reflected Xss Protection Disabled

Description

Detects JavaScript code that disables or bypasses XSS protections, allowing reflected cross-site scripting attacks. This vulnerability occurs when user-provided content is rendered without proper sanitization, potentially enabling malicious script injection.

Weakness:

008 - Reflected cross-site scripting (XSS)

Category: Unexpected Injection

Detection Strategy

    Identifies JavaScript code that explicitly disables XSS protections or security controls

    Detects usage of unsafe content rendering functions or properties that can execute unsanitized content

    Flags instances where user input could be directly rendered into the page without proper escaping

    Checks for dangerous JavaScript patterns that bypass built-in XSS mitigation features

Vulnerable code example

import { Router } from "express";
const router = Router();

router.get("/user", (req, res) => {
  const name = req.query.name;
  // Vulnerable: Direct user input interpolation enables XSS
  res.send(`<h1>Welcome ${name}</h1>`);
});...

✅ Secure code example

import { Router } from "express";
const router = Router();

// Validate and sanitize user input to prevent XSS
function validateName(input = "") {
  const s = String(input);
  // Only allow alphanumeric chars, spaces, dots and dashes, limit length
  return /^[\w .-]{1,100}$/.test(s) ? s : "";...