当前位置:网站首页>使用标签模板解决用户恶意输入的问题
使用标签模板解决用户恶意输入的问题
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' ]使用
strlet str = "<script>alert("猪痞恶霸yyds")</script>"
argumentsString()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>`;
参考文献
边栏推荐
- [embedded] print log using JLINK RTT
- Super efficient! The secret of swagger Yapi
- Shift Operators
- 数学建模2004B题(输电问题)
- LeetCode:498. Diagonal traversal
- Variable length parameter
- Mobile phones and computers on the same LAN access each other, IIS settings
- LeetCode:236. 二叉树的最近公共祖先
- LeetCode:394. 字符串解码
- Purpose of computer F1-F12
猜你喜欢

Problems encountered in connecting the database of the project and their solutions

LeetCode:124. 二叉树中的最大路径和

I-BERT

可变长参数

BMINF的后训练量化实现

Detailed explanation of dynamic planning

LeetCode:236. The nearest common ancestor of binary tree

Simple use of promise in uniapp

LeetCode:221. Largest Square

Intel Distiller工具包-量化实现1
随机推荐
@JsonBackReference和@JsonManagedReference(解决对象中存在双向引用导致的无限递归)
[sword finger offer] serialized binary tree
Target detection - pytorch uses mobilenet series (V1, V2, V3) to build yolov4 target detection platform
LeetCode:214. Shortest palindrome string
[embedded] cortex m4f DSP Library
Computer cleaning, deleted system files
Swagger setting field required is mandatory
To effectively improve the quality of software products, find a third-party software evaluation organization
The harm of game unpacking and the importance of resource encryption
多元聚类分析
自动化测试框架有什么作用?上海专业第三方软件测试公司安利
LeetCode:498. Diagonal traversal
[OC]-<UI入门>--常用控件-UIButton
Tdengine biweekly selection of community issues | phase III
Image, CV2 read the conversion and size resize change of numpy array of pictures
LeetCode:41. 缺失的第一个正数
[MySQL] multi table query
vb. Net changes with the window, scales the size of the control and maintains its relative position
How to conduct interface test? What are the precautions? Nanny level interpretation
UML diagram memory skills