Skip to content

Commit

Permalink
fix(SPA): 过滤 XSS
Browse files Browse the repository at this point in the history
  • Loading branch information
mutoe committed Jan 26, 2019
1 parent 8965728 commit bed1606
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
3 changes: 2 additions & 1 deletion resources/spa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"vue": "^2.5.17",
"vue-router": "^3.0.1",
"vuex": "^3.0.1",
"weixin-js-sdk": "^1.3.3"
"weixin-js-sdk": "^1.3.3",
"xss": "^1.0.3"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^3.2.0",
Expand Down
17 changes: 3 additions & 14 deletions resources/spa/src/filters.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import plueMessageBundle from 'plus-message-bundle'
import xss from 'xss'

/**
* ThinkSNS Plus 消息解析器,获取顶部消息.
Expand All @@ -21,20 +22,8 @@ export function plusMessageFirst (message, defaultMessage) {
* @returns {string}
*/
export function escapeHTML (value) {
if (typeof value !== 'string') {
return value
}
return value.replace(/[&<>`"'/]/g, function (result) {
return {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'`': '&#x60;',
'"': '&quot;',
"'": '&#x27;',
'/': '&#x2f;',
}[result]
})
const options = {}
return xss(value, options)
}

/**
Expand Down

0 comments on commit bed1606

Please sign in to comment.