当前位置:网站首页>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
边栏推荐
- Compétences en mémoire des graphiques UML
- 如何有效地进行自动化测试?
- swagger设置字段required必填
- 数学建模2004B题(输电问题)
- UML diagram memory skills
- Problems in loading and saving pytorch trained models
- Navicat Premium 创建MySql 创建存储过程
- 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
- 随手记01
- LeetCode:162. Looking for peak
猜你喜欢
Generator parameters incoming parameters
Swagger setting field required is mandatory
Charging interface docking tutorial of enterprise and micro service provider platform
Marathon envs project environment configuration (strengthen learning and imitate reference actions)
Computer cleaning, deleted system files
多元聚类分析
Sublime text in CONDA environment plt Show cannot pop up the problem of displaying pictures
MYSQL卸载方法与安装方法
[embedded] cortex m4f DSP Library
Guangzhou will promote the construction of a child friendly city, and will explore the establishment of a safe area 200 meters around the school
随机推荐
[MySQL] multi table query
LeetCode:41. Missing first positive number
BMINF的後訓練量化實現
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Computer graduation design PHP Zhiduo online learning platform
Philosophical enlightenment from single point to distributed
Roguelike game into crack the hardest hit areas, how to break the bureau?
注意力机制的一种卷积替代方式
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
LeetCode:劍指 Offer 42. 連續子數組的最大和
Indentation of tabs and spaces when writing programs for sublime text
LeetCode:剑指 Offer 04. 二维数组中的查找
MongoDB 的安装和基本操作
Revit secondary development Hof method calls transaction
多元聚类分析
自定义卷积注意力算子的CUDA实现
如何有效地进行自动化测试?
Marathon envs project environment configuration (strengthen learning and imitate reference actions)
Light of domestic games destroyed by cracking
广州推进儿童友好城市建设,将探索学校周边200米设安全区域