
تعقيم HTML غير الموثوق به (لمنع XSS) باستخدام إعدادات محددة عبر قائمة بيضاء

xss هي وحدة تُستخدم لتصفية المدخلات من المستخدمين لمنع هجمات XSS.
(ما هو هجوم XSS؟)
الصفحة الرئيسية للمشروع: http://jsxss.com
جرّبه عبر الإنترنت: http://jsxss.com/en/try.html
xss() من الوحدة [email protected]: 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);
يمكنك استخدام filterXSSWithResult للحصول على كل من HTML المعقّم وقائمة بالوسوم/السمات المحذوفة:
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()" }
// ]
وضع Shim (الملف المرجعي 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 - 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>
ملاحظات: يُرجى عدم استخدام عنوان 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>
بالنسبة للقائمة البيضاء الافتراضية، يُرجى الرجوع إلى xss.whiteList.
يُدعم أيضًا allowList، وله نفس وظيفة whiteList.
عن طريق تحديد دالة المعالج باستخدام 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
}
من خلال تحديد دالة المعالج باستخدام 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:
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)
}
من خلال تحديد دالة المعالج باستخدام onIgnoreTagAttr:

منصة XDR و SIEM مفتوحة المصدر لكشف التهديدات وتحليل السجلات ومراقبة سلامة الملفات وتقييم الثغرات وإدارة الامتثال عبر نقاط النهاية وأعباء العمل السحابية.

محرك شبكة مفتوح المصدر لأنظمة IDS/IPS/NSM لفحص حركة المرور في الوقت الفعلي، واكتشاف ومنع التسلل، وتحليل البروتوكولات، ومطاردة التهديدات المبنية على القواعد.

Zeek هو إطار تحليل شبكات قوي يختلف كثيرًا عن نظام IDS التقليدي الذي قد تعرفه.