Skip to content

Commit a5b517f

Browse files
ywywZhouluofann
authored andcommitted
fix: 使用v-html模板语法时添加安全预防 --bug=119961524
# Reviewed, transaction id: 20003
1 parent 8bf1b75 commit a5b517f

File tree

6 files changed

+29
-7
lines changed

6 files changed

+29
-7
lines changed

frontend/desktop/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
"vue-router": "^3.0.1",
4444
"vuedraggable": "^2.16.0",
4545
"vuex": "^3.0.1",
46-
"xlsx": "^0.15.1"
46+
"xlsx": "^0.15.1",
47+
"xss": "^1.0.15"
4748
},
4849
"devDependencies": {
4950
"@babel/core": "^7.4.5",

frontend/desktop/src/components/common/modal/ErrorCodeModal.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<ErrorCode406 v-if="code === 406"></ErrorCode406>
2929
<ErrorCode407 v-if="code === 407"></ErrorCode407>
3030
<ErrorCode500 v-if="code === 500" :response-text="responseText"></ErrorCode500>
31-
<div class="default-modal" v-if="code === 'default'" v-html="responseText"></div>
31+
<div class="default-modal" v-if="code === 'default'" v-html="filterXSS(responseText)"></div>
3232
</div>
3333
</bk-dialog>
3434
</template>

frontend/desktop/src/main.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import './public-path.js'
1313
import Vue from 'vue'
1414
import VeeValidate, { Validator } from 'vee-validate'
15+
import filterXSS from 'xss'
1516
import router from './routers/index.js'
1617
import store from './store/index.js'
1718
import './directives/index.js'
@@ -211,6 +212,12 @@ Validator.localize({
211212
}
212213
})
213214

215+
Vue.prototype.filterXSS = input => filterXSS(input, {
216+
whiteList: {
217+
a: ['href']
218+
}
219+
})
220+
214221
new Vue({
215222
i18n,
216223
router,

frontend/desktop/src/pages/task/PeriodicList/BootRecordDialog.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,14 @@
150150
return ''
151151
}
152152
if (typeof data === 'string') {
153-
const info = data.replace(/\n/g, '<br>')
153+
// 只渲染a标签,不过滤换行
154+
let info = data.replace(/\n/g, '<br>')
155+
info = this.filterXSS(info, {
156+
whiteList: {
157+
a: ['href'],
158+
br: []
159+
}
160+
})
154161
return info
155162
} else {
156163
return data

frontend/desktop/src/pages/task/TaskExecute/ExecuteInfo.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,14 @@
10091009
return ''
10101010
}
10111011
if (typeof data === 'string') {
1012-
const info = data.replace(/\n/g, '<br>')
1012+
// 只渲染a标签,不过滤换行
1013+
let info = data.replace(/\n/g, '<br>')
1014+
info = this.filterXSS(info, {
1015+
whiteList: {
1016+
a: ['href'],
1017+
br: []
1018+
}
1019+
})
10131020
return info
10141021
} else {
10151022
return data

frontend/desktop/src/pages/task/TaskExecute/ExecuteInfo/OutputParams.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@
113113
if (output.value === 'undefined' || output.value === '') {
114114
return '--'
115115
} else if (!output.preset && this.nodeDetailConfig.component_code === 'job_execute_task') {
116-
return output.value
116+
return this.filterXSS(JSON.stringify(output.value))
117117
} else if (Array.isArray(output.value)) {
118118
if (!output.value.length) return '--'
119119
return output.value.reduce((acc, cur) => {
120-
let str = cur
120+
let str = this.filterXSS(cur)
121121
if (this.isUrl(cur)) {
122122
str = `<a style="color: #3a84ff; word-break: break-all;" target="_blank" href="${cur}">${cur}</a>`
123123
}
@@ -128,7 +128,7 @@
128128
if (this.isUrl(output.value)) {
129129
return `<a style="color: #3a84ff; word-break: break-all;" target="_blank" href="${output.value}">${output.value}</a>`
130130
}
131-
return output.value
131+
return this.filterXSS(JSON.stringify(output.value))
132132
}
133133
}
134134
}

0 commit comments

Comments
 (0)