Php nodejs过滤输入
在PHP中,我使用函数过滤输入数据 htmlspecialchars和mysql\u real\u escape\u字符串。nodejs中有类似的函数吗 我需要检查我的rounter函数中的所有输入,以防止像xss这样的黑客攻击。Php nodejs过滤输入,php,node.js,filtering,Php,Node.js,Filtering,在PHP中,我使用函数过滤输入数据 htmlspecialchars和mysql\u real\u escape\u字符串。nodejs中有类似的函数吗 我需要检查我的rounter函数中的所有输入,以防止像xss这样的黑客攻击。 谢谢 有一个用于的NodeJS包。或者您使用提供的答案: 函数escapeHtml(不安全){ 不安全返回 .替换(/&/g,“&;”) .replace(//g,“”) .替换(/“/g,”) .替换(/'/g,';); } 对于SQL,这取决于您使
谢谢 有一个用于的NodeJS包。或者您使用提供的答案:
函数escapeHtml(不安全){
不安全返回
.替换(/&/g,“&;”)
.replace(//g,“”)
.替换(/“/g,”)
.替换(/'/g,';);
}
对于SQL,这取决于您使用的库,但大多数库都会避开参数化查询。是这方面的完美库,它具有许多验证和卫生/过滤功能,例如:
entityDecode() //Decode HTML entities
entityEncode()
xss() //Remove common XSS attack vectors from text (default)
xss(true) //Remove common XSS attack vectors from images
或
谢谢该库中是否有类似php的strip_tags函数?我没有看到它,但这里是
函数strip_tags(oldString){return oldString.replace(/(]+)>)/ig,”;}
entityDecode() //Decode HTML entities
entityEncode()
xss() //Remove common XSS attack vectors from text (default)
xss(true) //Remove common XSS attack vectors from images
contains(str)
notContains(str)
regex(pattern, modifiers) //Usage: regex(/[a-z]/i) or regex('[a-z]','i')
notRegex(pattern, modifiers)
len(min, max) //max is optional
isUUID(version) //Version can be 3 or 4 or empty, see http://en.wikipedia.org/wiki/Universally_unique_identifier
isDate() //Uses Date.parse() - regex is probably a better choice
isAfter(date) //Argument is optional and defaults to today
isBefore(date) //Argument is optional and defaults to today
isIn(options) //Accepts an array or string