Skip to content

Commit d3595c0

Browse files
author
duanlinzhen
committed
fix: 修复表达式编辑器 XSS 注入漏洞,使用 escapeHtml 转义用户输入
1 parent 1b0517e commit d3595c0

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

packages/amis-editor/src/renderer/textarea-formula/plugin.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import {TextareaFormulaControlProps} from './TextareaFormulaControl';
66
import {FormulaEditor} from 'amis-ui';
7+
import {escapeHtml} from 'amis-core';
78
import type {VariableItem, CodeMirror} from 'amis-ui';
89

910
export function editorFactory(
@@ -232,7 +233,7 @@ export class FormulaPlugin {
232233
true,
233234
false
234235
) || {
235-
html: expression
236+
html: escapeHtml(expression)
236237
};
237238

238239
const wrap = document.createElement('span');

packages/amis-ui/src/components/formula/Editor.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import React from 'react';
55
import {
66
eachTree,
77
resolveVariableAndFilterForAsync,
8-
uncontrollable
8+
uncontrollable,
9+
escapeHtml
910
} from 'amis-core';
1011
import {
1112
parse,
@@ -208,7 +209,8 @@ export class FormulaEditor extends React.Component<
208209
.filter(item => item)
209210
.sort((a, b) => b.length - a.length);
210211

211-
const content = value || '';
212+
// XSS 防护:对用户输入进行转义
213+
const content = escapeHtml(value || '');
212214
let html = '';
213215

214216
// 标记方法调用

0 commit comments

Comments
 (0)