
व्हाइटलिस्ट द्वारा निर्दिष्ट कॉन्फ़िगरेशन के साथ अविश्वसनीय HTML को सैनिटाइज़ करें (XSS को रोकने के लिए)

xss एक मॉड्यूल है जिसका उपयोग XSS हमलों को रोकने के लिए उपयोगकर्ताओं से इनपुट को फ़िल्टर करने के लिए किया जाता है।
(XSS हमला क्या है?)
प्रोजेक्ट होमपेज: http://jsxss.com
ऑनलाइन आज़माएँ: http://jsxss.com/en/try.html
[email protected] से xss() फ़ंक्शन: 6.9 MB/sपरीक्षण कोड के लिए कृपया benchmark निर्देशिका देखें।
npm install xss
bower install xss
या
bower install https://github.com/leizongmin/js-xss.git
var xss = require("xss");
var html = xss('<script>alert("xss");</script>');
console.log(html);
आप सैनिटाइज़ किया गया HTML और हटाए गए टैग/विशेषताओं की सूची दोनों प्राप्त करने के लिए filterXSSWithResult का उपयोग कर सकते हैं:
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()" }
// ]
शिम मोड (संदर्भ फ़ाइल 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 मोड - शिम:
<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>
नोट: कृपया उत्पादन परिवेश में URL https://rawgit.com/leizongmin/js-xss/master/dist/xss.js का उपयोग न करें।
आप फ़ाइल को प्रोसेस करने के लिए xss कमांड लाइन टूल का उपयोग कर सकते हैं। उपयोग:
xss -i <input_file> -o <output_file>
उदाहरण:
xss -i origin.html -o target.html
निम्नलिखित कमांड चलाएँ, फिर आप कमांड-लाइन में HTML कोड टाइप कर सकते हैं, और फ़िल्टर किए गए आउटपुट की जाँच कर सकते हैं:
xss -t
अधिक जानकारी के लिए, कृपया इसे देखने के लिए $ xss -h चलाएँ।
xss() फ़ंक्शन का उपयोग करते समय, दूसरे पैरामीटर का उपयोग कस्टम नियम निर्दिष्ट करने के लिए किया जा सकता है:
options = {}; // Custom rules
html = xss('<script>alert("xss");</script>', options);
हर बार options पास करने से बचने के लिए, आप एक FilterXSS इंस्टेंस बनाकर इसे तेज़ तरीके से भी कर सकते हैं:
options = {}; // Custom rules
myxss = new xss.FilterXSS(options);
// then apply myxss.process()
html = myxss.process('<script>alert("xss");</script>');
options में पैरामीटर का विवरण नीचे वर्णित किया जाएगा।
whiteList निर्दिष्ट करके, उदा. { 'tagName': [ 'attr-1', 'attr-2' ] }। श्वेतसूची में न होने वाले टैग
और विशेषताएँ फ़िल्टर कर दी जाएँगी। उदाहरण के लिए:
// 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>
डिफ़ॉल्ट whitelist के लिए, कृपया xss.whiteList देखें।
allowList भी समर्थित है, और इसका कार्य whiteList के समान है।
onTag के साथ handler फ़ंक्शन निर्दिष्ट करके:
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
}
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
}
onIgnoreTag के साथ हैंडलर फ़ंक्शन निर्दिष्ट करके:

ओपन-सोर्स XDR और SIEM प्लेटफ़ॉर्म जो एंडपॉइंट और क्लाउड वर्कलोड पर खतरे का पता लगाने, लॉग विश्लेषण, फ़ाइल अखंडता निगरानी, कमजोरियों का आकलन और अनुपालन प्रबंधन के लिए है।

रीयल-टाइम ट्रैफ़िक निरीक्षण, घुसपैठ का पता लगाने और रोकथाम, प्रोटोकॉल विश्लेषण, और नियम-आधारित खतरे की खोज के लिए ओपन-सोर्स नेटवर्क IDS/IPS/NSM इंजन।

Zeek एक शक्तिशाली नेटवर्क विश्लेषण ढांचा है जो आपके परिचित सामान्य IDS से काफी अलग है।