Skip to content

Commit

Permalink
fix(iframe): 屏蔽 Base64 方式 XSS 攻击链接
Browse files Browse the repository at this point in the history
  • Loading branch information
bhuh12 committed Nov 28, 2020
1 parent 92b2f3d commit 665b897
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
9 changes: 6 additions & 3 deletions lib/page/Iframe.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ export default {
},
computed: {
// 链接安全过滤,避免执行js
/**
* 链接安全过滤,屏蔽以下方式 XSS 攻击,并返回空白页:
* 1. `javascript:` 执行代码:`javascript:alert(1)`
* 2. `data:` Base64 链接: `'data:text/html;base64,' + window.btoa('<script>alert(1)<\/script>')`
*/
url() {
let src = decodeURIComponent(this.src)
// XSS 攻击链接返回空白页
if (/^javascript:/.test(src)) {
if (/^(javascript|data):/i.test(src)) {
return 'about:blank'
}
Expand Down
27 changes: 19 additions & 8 deletions src/views/IframeOperate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@
<a
class="demo-btn"
title="XSS 跨站链接的 iframe 将展示空白页面"
@click="
$tabs.openIframe(
'javascript:alert(window.parent.document.body.innerHTML)',
'XSS 跨站',
icon
)
"
@click="$tabs.openIframe(xss.js, 'XSS - JS', icon)"
>
XSS 跨站
XSS - JS
</a>

<a
class="demo-btn"
title="XSS 跨站链接的 iframe 将展示空白页面"
@click="$tabs.openIframe(xss.base64, 'XSS - Base64', icon)"
>
XSS - Base64
</a>
</p>

Expand Down Expand Up @@ -75,13 +77,22 @@ export default {
data() {
return {
icon: 'rt-icon-web',
site: {
src: 'https://cn.vuejs.org',
title: 'Vue.js'
},
iframe: {
src: 'https://router.vuejs.org/zh/',
title: 'Vue Router'
},
xss: {
js: 'javascript:alert(1)',
base64:
'data:text/html;base64,' +
window.btoa('<script>alert(1)</s' + 'cript>')
}
}
}
Expand Down

0 comments on commit 665b897

Please sign in to comment.