href和src属性,如果被过滤则返回空值

This commit is contained in:
Zongmin Lei
2014-02-18 14:35:50 +08:00
parent e2272386a1
commit 519f0ed944
3 changed files with 38 additions and 37 deletions

View File

@@ -119,15 +119,16 @@ function safeAttrValue (tag, name, value) {
// 过滤 href 和 src 属性
// 仅允许 http:// | https:// | / 开头的地址
value = value.trim();
if (value === '#') return '#';
if (value && !REGEXP_DEFAULT_ON_TAG_ATTR_1.test(value)) {
return '#';
return '';
}
} else if (name === 'style') {
// 过滤 style 属性 这个xss漏洞较老了可能已经不适用
// javascript:
REGEXP_DEFAULT_ON_TAG_ATTR_3.lastIndex = 0;
if (REGEXP_DEFAULT_ON_TAG_ATTR_3.test(value)) {
return '#';
return '';
}
// /*注释*/
REGEXP_DEFAULT_ON_TAG_ATTR_4.lastIndex = 0;