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.
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(`...Search for vulnerabilities in your apps for free with Fluid Attacks' automated security testing! Start your 21-day free trial and discover the benefits of the Continuous Hacking Essential plan. If you prefer the Advanced plan, which includes the expertise of Fluid Attacks' hacking team, fill out this contact form.