当前位置:网站首页>使用标签模板解决用户恶意输入的问题
使用标签模板解决用户恶意输入的问题
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
- Indentation of tabs and spaces when writing programs for sublime text
- LeetCode:26. Remove duplicates from an ordered array
- LeetCode:劍指 Offer 42. 連續子數組的最大和
- LeetCode:214. 最短回文串
- LeetCode:剑指 Offer 42. 连续子数组的最大和
- LeetCode:41. Missing first positive number
- [OC]-<UI入门>--常用控件-UIButton
- ant-design的走马灯(Carousel)组件在TS(typescript)环境中调用prev以及next方法
- R language ggplot2 visualization: place the title of the visualization image in the upper left corner of the image (customize Title position in top left of ggplot2 graph)
猜你喜欢
![[OC-Foundation框架]-<字符串And日期与时间>](/img/75/e20064fd0066810135771a01f54360.png)
[OC-Foundation框架]-<字符串And日期与时间>

LeetCode:498. 对角线遍历

Detailed explanation of dynamic planning

Compétences en mémoire des graphiques UML
![[OC]-<UI入门>--常用控件的学习](/img/2c/d317166e90e1efb142b11d4ed9acb7.png)
[OC]-<UI入门>--常用控件的学习

View computer devices in LAN

Unsupported operation exception
![[MySQL] limit implements paging](/img/94/2e84a3878e10636460aa0fe0adef67.jpg)
[MySQL] limit implements paging

LeetCode:498. Diagonal traversal

Visual implementation and inspection of visdom
随机推荐
Light of domestic games destroyed by cracking
Excellent software testers have these abilities
Marathon envs project environment configuration (strengthen learning and imitate reference actions)
LeetCode:236. 二叉树的最近公共祖先
Problems in loading and saving pytorch trained models
LeetCode:214. Shortest palindrome string
LeetCode:34. Find the first and last positions of elements in a sorted array
[embedded] cortex m4f DSP Library
ant-design的走马灯(Carousel)组件在TS(typescript)环境中调用prev以及next方法
Nacos 的安装与服务的注册
Intel Distiller工具包-量化实现3
Computer graduation design PHP Zhiduo online learning platform
pytorch查看张量占用内存大小
Variable length parameter
LeetCode:162. Looking for peak
LeetCode:124. 二叉树中的最大路径和
JVM quick start
LeetCode:124. Maximum path sum in binary tree
Unsupported operation exception
View computer devices in LAN