
Sanitize HTML não confiável (para prevenir XSS) com uma configuração especificada por uma Whitelist

xss é um módulo usado para filtrar a entrada dos usuários e prevenir ataques XSS.
(O que é um ataque XSS?)
Página inicial do projeto: http://jsxss.com
Experimente online: http://jsxss.com/en/try.html
xss() do módulo [email protected]: 6,9 MB/sPara o código de teste, consulte o diretório benchmark.
npm install xss
bower install xss
Ou
bower install https://github.com/leizongmin/js-xss.git
var xss = require("xss");
var html = xss('<script>alert("xss");</script>');
console.log(html);
Você pode usar filterXSSWithResult para obter tanto o HTML sanitizado quanto uma lista de tags/atributos removidos:
var xss = require("xss");
var result = xss.filterXSSWithResult('<script>alert("xss");</script><a href="#" onclick="evil()">click</a>');
console.log(result.html);
// Output: "<script>alert(\"xss\");</script><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()" }
// ]
Modo Shim (arquivo de referência 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>
Modo AMD - 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>
Notas: por favor, não use a URL https://rawgit.com/leizongmin/js-xss/master/dist/xss.js em ambiente de produção.
Você pode usar a ferramenta de linha de comando xss para processar um arquivo. Uso:
xss -i <input_file> -o <output_file>
Exemplo:
xss -i origin.html -o target.html
Execute o seguinte comando, depois você pode digitar código HTML na linha de comando e verificar a saída filtrada:
xss -t
Para mais detalhes, execute $ xss -h para visualizá-lo.
Ao usar a função xss(), o segundo parâmetro pode ser usado para especificar
regras personalizadas:
options = {}; // Custom rules
html = xss('<script>alert("xss");</script>', options);
Para evitar passar options toda vez, você também pode fazer isso de uma forma mais rápida
criando uma instância de FilterXSS:
options = {}; // Custom rules
myxss = new xss.FilterXSS(options);
// then apply myxss.process()
html = myxss.process('<script>alert("xss");</script>');
Os detalhes dos parâmetros em options serão descritos abaixo.
Ao especificar um whiteList, por exemplo { 'tagName': [ 'attr-1', 'attr-2' ] }. Tags
e atributos que não estejam na lista de permissões serão filtrados. Por exemplo:
// 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="#"><i>Hello</i></a>
Para a lista de permissões padrão, consulte xss.whiteList.
allowList também é suportado e tem a mesma função que whiteList.
Ao especificar a função de manipulador com 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
}
Ao especificar a função handler com 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
}
Ao especificar a função de manipulador com onIgnoreTag:

Plataforma XDR e SIEM de código aberto para detecção de ameaças, análise de logs, monitoramento de integridade de arquivos, avaliação de vulnerabilidades e gerenciamento de conformidade em endpoints e cargas de trabalho na nuvem.

Mecanismo open-source de IDS/IPS/NSM de rede para inspeção de tráfego em tempo real, detecção e prevenção de intrusões, análise de protocolos e caça a ameaças baseada em regras.

Zeek é um poderoso framework de análise de rede que é muito diferente do IDS típico que você pode conhecer.