当前位置:网站首页>使用标签模板解决用户恶意输入的问题
使用标签模板解决用户恶意输入的问题
2022-07-06 08:53:00 【InfoQ】
什么是恶意输入
<script>
alert("猪痞恶霸yyds")
</script>
alert
标签模板
概念
let str = "猪痞恶霸",
_str = "fzf404";
function add(a, ...b) {
console.log(a);
console.log(b);
}
add`Hello${str}World${_str}`;
// [ 'Hello', 'World', '' ]
// [ '猪痞恶霸', 'fzf404' ]
[ 'Hello', 'World', '' ]
_str
"World"
[ '猪痞恶霸', 'fzf404' ]
使用
str
let str = "<script>alert("猪痞恶霸yyds")</script>"
arguments
String()
replace
<
>
<script>
function SaferHTML(tempalte) {
let s = tempalte[0];
for (let i = 1; i < arguments.length; i++) {
let arg = String(arguments[i]);
// Escape special characters in the substitution.
s += arg.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">");
// Don't escape special characters in the template.
s += tempalte[i];
}
return s;
}
let end = SaferHTML`<p>${str}用户输入${str}</p>`;
参考文献
边栏推荐
- vb. Net changes with the window, scales the size of the control and maintains its relative position
- [sword finger offer] serialized binary tree
- [OC]-<UI入门>--常用控件-UIButton
- What is the role of automated testing frameworks? Shanghai professional third-party software testing company Amway
- Purpose of computer F1-F12
- CSP first week of question brushing
- I-BERT
- Computer graduation design PHP Zhiduo online learning platform
- 目标检测——Pytorch 利用mobilenet系列(v1,v2,v3)搭建yolov4目标检测平台
- Excellent software testers have these abilities
猜你喜欢
Guangzhou will promote the construction of a child friendly city, and will explore the establishment of a safe area 200 meters around the school
[today in history] February 13: the father of transistors was born The 20th anniversary of net; Agile software development manifesto was born
I-BERT
Mobile phones and computers on the same LAN access each other, IIS settings
Indentation of tabs and spaces when writing programs for sublime text
Intel Distiller工具包-量化实现3
Simple use of promise in uniapp
Deep analysis of C language data storage in memory
UML diagram memory skills
Screenshot in win10 system, win+prtsc save location
随机推荐
[MySQL] limit implements paging
数学建模2004B题(输电问题)
Delay initialization and sealing classes
Simple use of promise in uniapp
LeetCode:26. 删除有序数组中的重复项
Marathon envs project environment configuration (strengthen learning and imitate reference actions)
[OC]-<UI入门>--常用控件的学习
MongoDB 的安装和基本操作
Guangzhou will promote the construction of a child friendly city, and will explore the establishment of a safe area 200 meters around the school
Variable length parameter
swagger设置字段required必填
POI add write excel file
Pytorch view tensor memory size
ROS compilation calls the third-party dynamic library (xxx.so)
TP-LINK enterprise router PPTP configuration
Esp8266-rtos IOT development
Hutool gracefully parses URL links and obtains parameters
如何有效地进行自动化测试?
poi追加写EXCEL文件
企微服务商平台收费接口对接教程