当前位置 : 主页 > 编程语言 > java >

防止xxs攻击,input表单中不能输入script标签

来源:互联网 收集:自由互联 发布时间:2022-09-02
在web网页中,所有的项目中。input表单中不能让用户输入script这些敏感性的。 一旦出现提示用户非正常输入。然后立刻将值清空 el-input style="width:350px" @blur="blurHandler" placeholder="请输入内
在web网页中,所有的项目中。input表单中不能让用户输入script这些敏感性的。
一旦出现提示用户非正常输入。然后立刻将值清空 <el-input
style="width:350px"
@blur="blurHandler"
placeholder="请输入内容"
v-model="input10"
clearable>
</el-input>methods: {
blurHandler(){
var part = new RegExp('<script>','ig');
console.log("是否含有<script>",part.test(this.input10)); //含有返回true

var partend=new RegExp('<\/script>','ig');
console.log("是否含有<\/script>",partend.test(this.input10)); //含有返回true

}
}在使用<script>嵌入JavaScript代码时,记住不要在代码中的任何地方出现"</script>"字符串。
包括注释都不能哈。不能出现"</script>"
可以通过转义符可以解决这个问题,

<script type="text/javascript">
function hello() {
console.log("<\/script>");
}
</script>

遇见问题,这是你成长的机会,如果你能够解决,这就是收获。


作者:​​晚来南风晚相识​​​

上一篇:&&运算提高代码质量
下一篇:没有了
网友评论