Skip to content
KitploitKITPLOIT
OutilsExploitsBlog
Log in
Soumettre
OutilsExploitsBlog
Soumettre

Outils de Hacking, PenTest et Cybersécurité pour votre Arsenal de Sécurité !

Kitploit est un répertoire d'outils de hacking, de cybersécurité et de pentesting. Découvrez les dernières mises à jour des projets pour trouver des vulnérabilités, analyser des systèmes, automatiser les tests et renforcer votre sécurité.

FluxContactConfidentialité© 2026 Kitploit

Répertoire d'outils

Catégories

Voir toutes les catégories
Loading categories
js-xss — Sanitize untrusted HTML (to prevent XSS) with a configuration specified by a Whitelist | Kitploit
Outils/GitHubGitHub/leizongmin/js-xss
Defensive ToolsWeb Application ExploitationWeb SecurityUtilities & Frameworks
GitHubleizongmin/js-xss

js-xss

Sanitize untrusted HTML (to prevent XSS) with a configuration specified by a Whitelist

Voir le dépôt
5.3k63024 oct. 2026Vérifié par Kitploit
Site web
Partager
Contenu non disponible dans la langue demandée. Affichage de la version anglaise.

NPM version Node.js CI Test coverage David deps node version npm download npm license

Sanitize untrusted HTML (to prevent XSS) with a configuration specified by a Whitelist.

Greenkeeper badge

xss


xss is a module used to filter input from users to prevent XSS attacks. (What is XSS attack?)

Project Homepage: http://jsxss.com

Try Online: http://jsxss.com/en/try.html

中文版文档


Features

  • Specifies HTML tags and their attributes allowed with whitelist
  • Handle any tags or attributes using custom function.

Reference

  • XSS Filter Evasion Cheat Sheet
  • Data URI scheme
  • XSS with Data URI Scheme

Benchmark (for references only)

  • the xss module: 22.53 MB/s
  • xss() function from module [email protected]: 6.9 MB/s

For test code please refer to benchmark directory.

They are using xss module

  • nodeclub - A Node.js bbs using MongoDB - https://github.com/cnodejs/nodeclub
  • cnpmjs.org - Private npm registry and web for Enterprise - https://github.com/cnpm/cnpmjs.org
  • cocalc.com - Collaborative Calculation and Data Science - https://cocalc.com

Install

NPM

npm install xss

Bower

bower install xss

Or

bower install https://github.com/leizongmin/js-xss.git

Usages

On Node.js

var xss = require("xss");
var html = xss('<script>alert("xss");</script>');
console.log(html);

Get sanitized HTML and removed elements

You can use filterXSSWithResult to get both the sanitized HTML and a list of removed tags/attributes:

var xss = require("xss");
var result = xss.filterXSSWithResult('<script>alert("xss");</script><a href="#" onclick="evil()">click</a>');
console.log(result.html);
// Output: "&lt;script&gt;alert(\"xss\");&lt;/script&gt;<a href=\"#\">click</a>"
console.log(result.removed);
// Output: [
//   { type: "tag", tag: "script", html: "<script>", isClosing: false },
//   { type: "tag", tag: "script", html: "</script>", isClosing: true },
//   { type: "attr", tag: "a", attr: "onclick", value: "evil()" }
// ]

On Browser

Shim mode (reference file test/test.html):

<script src="https://rawgit.com/leizongmin/js-xss/master/dist/xss.js"></script>
<script>
  // apply function filterXSS in the same way
  var html = filterXSS('<script>alert("xss");</scr' + "ipt>");
  alert(html);
</script>

AMD mode - shim:

<script>
  require.config({
    baseUrl: "./",
    paths: {
      xss: "https://rawgit.com/leizongmin/js-xss/master/dist/xss.js",
    },
    shim: {
      xss: { exports: "filterXSS" },
    },
  });
  require(["xss"], function (xss) {
    var html = xss('<script>alert("xss");</scr' + "ipt>");
    alert(html);
  });
</script>

Notes: please don't use the URL https://rawgit.com/leizongmin/js-xss/master/dist/xss.js in production environment.

Command Line Tool

Process File

You can use the xss command line tool to process a file. Usage:

xss -i <input_file> -o <output_file>

Example:

xss -i origin.html -o target.html

Active Test

Run the following command, them you can type HTML code in the command-line, and check the filtered output:

xss -t

For more details, please run $ xss -h to see it.

Custom filter rules

When using the xss() function, the second parameter could be used to specify custom rules:

options = {}; // Custom rules
html = xss('<script>alert("xss");</script>', options);

To avoid passing options every time, you can also do it in a faster way by creating a FilterXSS instance:

options = {}; // Custom rules
myxss = new xss.FilterXSS(options);
// then apply myxss.process()
html = myxss.process('<script>alert("xss");</script>');

Details of parameters in options would be described below.

Whitelist

By specifying a whiteList, e.g. { 'tagName': [ 'attr-1', 'attr-2' ] }. Tags and attributes not in the whitelist would be filter out. For example:

// only tag a and its attributes href, title, target are allowed
var options = {
  whiteList: {
    a: ["href", "title", "target"],
  },
};
// With the configuration specified above, the following HTML:
// <a href="#" onclick="hello()"><i>Hello</i></a>
// would become:
// <a href="#">&lt;i&gt;Hello&lt;/i&gt;</a>

For the default whitelist, please refer xss.whiteList.

allowList is also supported, and has the same function as whiteList.

Customize the handler function for matched tags

By specifying the handler function with onTag:

function onTag(tag, html, options) {
  // tag is the name of current tag, e.g. 'a' for tag <a>
  // html is the HTML of this tag, e.g. '<a>' for tag <a>
  // options is some addition informations:
  //   isWhite    boolean, whether the tag is in whitelist
  //   isClosing  boolean, whether the tag is a closing tag, e.g. true for </a>
  //   position        integer, the position of the tag in output result
  //   sourcePosition  integer, the position of the tag in input HTML source
  // If a string is returned, the current tag would be replaced with the string
  // If return nothing, the default measure would be taken:
  //   If in whitelist: filter attributes using onTagAttr, as described below
  //   If not in whitelist: handle by onIgnoreTag, as described below
}

Customize the handler function for attributes of matched tags

By specifying the handler function with onTagAttr:

function onTagAttr(tag, name, value, isWhiteAttr) {
  // tag is the name of current tag, e.g. 'a' for tag <a>
  // name is the name of current attribute, e.g. 'href' for href="#"
  // isWhiteAttr whether the attribute is in whitelist
  // If a string is returned, the attribute would be replaced with the string
  // If return nothing, the default measure would be taken:
  //   If in whitelist: filter the value using safeAttrValue as described below
  //   If not in whitelist: handle by onIgnoreTagAttr, as described below
}

Customize the handler function for tags not in the whitelist

By specifying the handler function with onIgnoreTag:

function onIgnoreTag(tag, html, options) {
  // Parameters are the same with onTag
  // If a string is returned, the tag would be replaced with the string
  // If return nothing, the default measure would be taken (specifies using
  // escape, as described below)
}

Customize the handler function for attributes not in the whitelist

Télécharger l’outil

Outils similaires

  • wazuh

    Plateforme XDR et SIEM open-source pour la détection des menaces, l'analyse des journaux, la surveillance de l'intégrité des fichiers, l'évaluation des vulnérabilités et la gestion de la conformité sur les points de terminaison et les charges de travail cloud.

  • suricata

    Moteur open-source IDS/IPS/NSM réseau pour l'inspection du trafic en temps réel, la détection et la prévention d'intrusions, l'analyse des protocoles et la chasse aux menaces basée sur des règles.

  • zeek

    Zeek est un puissant framework d'analyse réseau qui est très différent du système IDS typique que vous connaissez peut-être.

Populaires

Voir tout →

Découvrez les outils les plus utilisés par notre communauté.

  • 1

    Callisto

    jetp1ane/callisto

    Outil automatisé d'analyse de vulnérabilités binaires qui décompile des exécutables via Ghidra, analyse du pseudo-code C avec Semgrep, et valide les résultats en utilisant GPT-3.5-Turbo pour réduire les faux positifs.

    2.2k
  • 2

    ghostlock-app

    yukonga/ghostlock-app

    # Application d'exécution en un clic GhostLock (CVE-2026-43499)

    841
  • 3

    DFRoot

    a2333c/dfroot

    Outil de root Android pour Samsung Galaxy S25 Ultra (SM-S938B) qui enchaîne DirtyFrag CVE-2026-43284 et CVE-2026-43499 pour obtenir le root automatiquement au démarrage via KernelSU.

    446
  • 4

    ARTEX

    baarai/artex

    Plateforme autonome de tests d'intrusion multi-agents basée sur des LLM, avec agents planificateur/ouvrier, graphes d'actifs et d'exploration, enregistrement du trafic MITM et retest des vulnérabilités.

    386
  • 5

    OsintHunter

    letox4/osinthunter

    🎯 La boîte à outils OSINT ultime : graphe d'enquête, notation de confiance, familles d'alias, carte, chronologie et rapports. 49 modules, plus de 400 sites, aucune clé API requise.

    350
  • 6

    faraday

    infobyte/faraday

    Outils de cybersécurité open-source et alimentés par l'IA pour la sécurité offensive, la gestion des vulnérabilités et le pentesting autonome. Conçus par des hackers en Amérique latine, utilisés dans le monde entier.

    333

Explorer tous les outils

Parcourez notre collection d'outils

Voir tous les outils →