update README

This commit is contained in:
Zongmin Lei
2014-02-14 10:06:09 +08:00
parent 6dabc1b1d6
commit 3eba6dbf53
2 changed files with 31 additions and 3 deletions

View File

@@ -24,7 +24,7 @@ XSS代码过滤
+ [XSS with Data URI Scheme](http://hi.baidu.com/badzzzz/item/bdbafe83144619c199255f7b)
## 使用
## 使用方法
### 在Node.js中使用
@@ -117,7 +117,7 @@ function onTagAttr (tag, name, value, isWhiteAttr) {
// isWhiteAttr是否为白名单上的属性
// 如果返回一个字符串,则当前属性值将被替换为该字符串
// 如果不返回任何值,则使用默认的处理方法
// 在白名单上: 输出该属性
// 在白名单上: 调用safeAttrValue来过滤属性值并输出该属性详见下文
// 不在白名单上通过onIgnoreTagAttr指定详见下文
}
```
@@ -176,6 +176,20 @@ function safeAttrValue (tag, name, value) {
+ `true`:(默认),去掉不在白名单上的标签
+ `false`:使用配置的`escape`函数对该标签进行转义
示例:
当设置 `stripIgnoreTag = true`时,以下代码
```HTML
code:<script>alert(/xss/);</script>
```
过滤后将输出
```HTML
code:alert(/xss/);
```
#### 去掉不在白名单上的标签及标签体
通过 `stripIgnoreTagBody` 来设置:
@@ -184,6 +198,20 @@ function safeAttrValue (tag, name, value) {
+ `'*'|true`:去掉所有不在白名单上的标签
+ `['tag1', 'tag2']`:仅去掉指定的不在白名单上的标签
示例:
当设置 `stripIgnoreTagBody = ['script']`时,以下代码
```HTML
code:<script>alert(/xss/);</script>
```
过滤后将输出
```HTML
code:
```
## 应用实例

View File

@@ -128,7 +128,7 @@ FilterXSS.prototype.process = function (html) {
// 默认的属性处理方法
if (isWhiteAttr) {
// 白名单属性,调用onIgnoreTagAttr过滤属性值
// 白名单属性,调用safeAttrValue过滤属性值
value = safeAttrValue(tag, name, value);
if (value) {
return name + '="' + value + '"';