当前位置:网站首页>Using label template to solve the problem of malicious input by users
Using label template to solve the problem of malicious input by users
2022-07-06 08:55:00 【InfoQ】
What is malicious input
<script>
alert(" Pig ruffian bully yyds")
</script>
alert
The label template
Concept
let str = " Pig ruffian bully ",
_str = "fzf404";
function add(a, ...b) {
console.log(a);
console.log(b);
}
add`Hello${str}World${_str}`;
// [ 'Hello', 'World', '' ]
// [ ' Pig ruffian bully ', 'fzf404' ]
[ 'Hello', 'World', '' ]
_str
"World"
[ ' Pig ruffian bully ', 'fzf404' ]
Use
str
let str = "<script>alert(" Pig ruffian bully 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} User input ${str}</p>`;
reference
边栏推荐
- Notes 01
- 704 binary search
- Leetcode刷题题解2.1.1
- LeetCode:673. Number of longest increasing subsequences
- Screenshot in win10 system, win+prtsc save location
- Compétences en mémoire des graphiques UML
- Image, CV2 read the conversion and size resize change of numpy array of pictures
- LeetCode:39. Combined sum
- LeetCode:41. 缺失的第一个正数
- 有效提高软件产品质量,就找第三方软件测评机构
猜你喜欢
[OC]-<UI入门>--常用控件-UIButton
多元聚类分析
Detailed explanation of dynamic planning
SAP ui5 date type sap ui. model. type. Analysis of the parsing format of date
【剑指offer】序列化二叉树
Problems encountered in connecting the database of the project and their solutions
LeetCode:221. 最大正方形
The harm of game unpacking and the importance of resource encryption
Sublime text using ctrl+b to run another program without closing other runs
TP-LINK 企业路由器 PPTP 配置
随机推荐
【ROS】usb_ Cam camera calibration
[MySQL] multi table query
@JsonBackReference和@JsonManagedReference(解决对象中存在双向引用导致的无限递归)
R language uses the principal function of psych package to perform principal component analysis on the specified data set. PCA performs data dimensionality reduction (input as correlation matrix), cus
UML圖記憶技巧
LeetCode:124. Maximum path sum in binary tree
The harm of game unpacking and the importance of resource encryption
Improved deep embedded clustering with local structure preservation (Idec)
Shift Operators
Computer cleaning, deleted system files
Guangzhou will promote the construction of a child friendly city, and will explore the establishment of a safe area 200 meters around the school
MongoDB 的安装和基本操作
LeetCode:236. 二叉树的最近公共祖先
Charging interface docking tutorial of enterprise and micro service provider platform
自动化测试框架有什么作用?上海专业第三方软件测试公司安利
超高效!Swagger-Yapi的秘密
POI add write excel file
UML图记忆技巧
[sword finger offer] serialized binary tree
Computer graduation design PHP Zhiduo online learning platform