修正 issue #41 href默认允许#开头

This commit is contained in:
Zongmin Lei
2015-12-01 21:53:59 +08:00
parent e32c2676dc
commit 4ff066f0f6
2 changed files with 3 additions and 1 deletions

3
dist/xss.js vendored
View File

@@ -151,12 +151,13 @@ function safeAttrValue (tag, name, value, cssFilter) {
if (name === 'href' || name === 'src') {
// 过滤 href 和 src 属性
// 仅允许 http:// | https:// | mailto: | / 开头的地址
// 仅允许 http:// | https:// | mailto: | / | # 开头的地址
value = _.trim(value);
if (value === '#') return '#';
if (!(value.substr(0, 7) === 'http://' ||
value.substr(0, 8) === 'https://' ||
value.substr(0, 7) === 'mailto:' ||
value[0] === '#' ||
value[0] === '/')) {
return '';
}