当前位置:网站首页>使用标签模板解决用户恶意输入的问题
使用标签模板解决用户恶意输入的问题
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>`;
参考文献
边栏推荐
- Super efficient! The secret of swagger Yapi
- [MySQL] multi table query
- MongoDB 的安装和基本操作
- Export IEEE document format using latex
- Leetcode: Jianzhi offer 04 Search in two-dimensional array
- Li Kou daily question 1 (2)
- 超高效!Swagger-Yapi的秘密
- LeetCode:214. 最短回文串
- POI add write excel file
- R language ggplot2 visualization, custom ggplot2 visualization image legend background color of legend
猜你喜欢
[MySQL] limit implements paging
Navicat Premium 创建MySql 创建存储过程
C language double pointer -- classic question type
BMINF的后训练量化实现
Esp8266-rtos IOT development
【剑指offer】序列化二叉树
Fairguard game reinforcement: under the upsurge of game going to sea, game security is facing new challenges
Cesium draw points, lines, and faces
After PCD is converted to ply, it cannot be opened in meshlab, prompting error details: ignored EOF
Export IEEE document format using latex
随机推荐
@JsonBackReference和@JsonManagedReference(解决对象中存在双向引用导致的无限递归)
Revit secondary development Hof method calls transaction
如何正确截取字符串(例:应用报错信息截取入库操作)
Promise 在uniapp的简单使用
The network model established by torch is displayed by torch viz
LeetCode:39. Combined sum
Esp8266-rtos IOT development
LeetCode:387. 字符串中的第一个唯一字符
[embedded] print log using JLINK RTT
LeetCode:124. Maximum path sum in binary tree
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
Problems in loading and saving pytorch trained models
Intel Distiller工具包-量化实现3
Tcp/ip protocol
[Hacker News Weekly] data visualization artifact; Top 10 Web hacker technologies; Postman supports grpc
POI add write excel file
[sword finger offer] serialized binary tree
Sublime text using ctrl+b to run another program without closing other runs
Leetcode: Jianzhi offer 03 Duplicate numbers in array
Using C language to complete a simple calculator (function pointer array and callback function)