Skip to content

Commit

Permalink
feat: 修复xss漏洞
Browse files Browse the repository at this point in the history
  • Loading branch information
wanchun committed Oct 16, 2024
1 parent eda6fba commit ee9c9a4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/fes-plugin-layout/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"peerDependencies": {
"@fesjs/fes": "^3.1.13",
"@fesjs/fes-design": ">=0.7.0",
"dompurify": "^3.1.7",
"vue": "^3.2.47",
"vue-router": "^4.0.1"
},
Expand Down
4 changes: 3 additions & 1 deletion packages/fes-plugin-layout/src/runtime/helpers/svg.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import DOMPurify from 'dompurify';

const isStr = function (str) {
return typeof str === 'string';
};
Expand Down Expand Up @@ -26,7 +28,7 @@ export function isValid(elm) {

export function validateContent(svgContent) {
const div = document.createElement('div');
div.innerHTML = svgContent;
div.innerHTML = DOMPurify.sanitize(svgContent);

// setup this way to ensure it works on our buddy IE
for (let i = div.childNodes.length - 1; i >= 0; i--) {
Expand Down
12 changes: 7 additions & 5 deletions packages/fes-plugin-layout/src/runtime/views/MenuIcon.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<script lang="jsx">
import { ref, onBeforeMount, isVNode } from 'vue';
// eslint-disable-next-line import/extensions
import { isVNode, onBeforeMount, ref } from 'vue';
import Icons from '../icons';
import { validateContent } from '../helpers/svg';
const urlReg = /^((https?|ftp|file):\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*\/?$/;
const isUrlResource = (name) => urlReg.test(name) || name.includes('.svg');
const isUrlResource = name => urlReg.test(name) || name.includes('.svg');
export default {
props: {
Expand All @@ -25,7 +25,8 @@ export default {
});
}
});
} else {
}
else {
AIconComponent.value = Icons[props.icon];
}
}
Expand All @@ -39,13 +40,14 @@ export default {
return <AIconComponent.value />;
}
if (AText.value) {
return <span class={'fes-layout-icon'} innerHTML={AText.value}></span>;
return <span class="fes-layout-icon" innerHTML={AText.value}></span>;
}
return null;
};
},
};
</script>

<style>
.fes-layout-icon {
display: inline-block;
Expand Down
2 changes: 1 addition & 1 deletion packages/fes-template/src/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const beforeRender = {
const { setRole, getRole } = accessApi;
return new Promise((resolve) => {
setTimeout(() => {
setRole('menuTest');
setRole('admin');
resolve({
userName: '李雷',
});
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ee9c9a4

Please sign in to comment.