logo

Database

Javascript Reflected Xss Protection Header

Description

This detector identifies TypeScript code that lacks proper XSS protection headers, making web applications vulnerable to cross-site scripting attacks. Missing or misconfigured XSS protection headers allow malicious scripts to be executed in users' browsers.

Weakness:

135 - Insecure or unset HTTP headers - X-XSS Protection

Category: Protocol Manipulation

Detection Strategy

    • Analyzes JavaScript source code files for HTTP response header configurations

    • Identifies missing or improperly configured X-XSS-Protection headers in web application frameworks

    • Flags code that handles HTTP responses without setting appropriate XSS protection mechanisms

    • Reports vulnerabilities when JavaScript applications fail to implement reflected XSS protection headers

Vulnerable code example

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

router.get("test", function (req, res) {
  var user = req.params["user"];
  res.setHeader("X-XSS-Protection", "1");
  res.send(`
    <!DOCTYPE html>...

✅ Secure code example

import { Router } from "express";
import he from "he"; // HTML entity encoding library
var router = Router();

router.get("test", function (req, res) {
  var user = req.params["user"];
  res.setHeader("Content-Security-Policy", "default-src 'self'"); // Modern XSS protection
  res.send(`...