12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
ADADADADAD
网络知识 时间:2024-12-04 12:32:17
作者:文/会员上传
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
react防止xss攻击的方法:react在渲染html内容和渲染dom属性时都会将 "'&<>这几个字符进行转义,转义部分源码如下:for(index=match.index;index<str.length;index++){switch
以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。
react防止xss攻击的方法:
react在渲染html内容和渲染dom属性时都会将 "'&<>这几个字符进行转义,转义部分源码如下:
for(index=match.index;index<str.length;index++){
switch(str.charCodeAt(index)){
case34://"
escape='"';
break;
case38://&
escape='&';
break;
case39://'
escape=''';
break;
case60://<
escape='<';
break;
case62://>
escape='>';
break;
default:
continue;
}
}
使用以上方法,恶意代码在渲染到html前都被转成了字符串,例如:
//一段恶意代码
<imgsrc="empty.png"onerror="alert('xss')">
//转义后输出到html中
<imgsrc="empty.png"onerror="alert('xss')">
11-20
11-19
11-20
11-20
11-20
11-19
11-20
11-20
11-19
11-20
11-19
11-19
11-19
11-19
11-19
11-19