amis icon indicating copy to clipboard operation
amis copied to clipboard

【安去问题】标签预览存在xss漏洞

Open xiahao90 opened this issue 9 months ago • 6 comments

描述问题:

签预览存在xss漏洞

截图或视频:

Image

如何复现(请务必完整填写下面内容):

  1. 你是如何使用 amis 的? sdk6.12.o

  2. amis 版本是什么?请先在最新 beta 版本测试问题是否存在 官网测试过

  3. 粘贴有问题的完整 amis schema 代码:

{
  "type": "page",
  "body": {
    "type": "form",
    "body": [
      {
        "type": "input-tag",
        "name": "tag",
        "label": "标签",
        "placeholder": "请选择标签",
        "options": [
          "Aaron Rodgers",
          "Tom Brady",
          "Charlse Woodson",
          "Aaron Jones",
          "<img src=x onerror=alert(1) />"
        ]
      }
    ]
  }
}
  1. 操作步骤 选择<img后,鼠标移入弹出

xiahao90 avatar Jun 03 '25 10:06 xiahao90

渲染的时候通过 env.filterHtml 下发一个 xss 处理器

import xss, {IFilterXSSOptions, escapeAttrValue} from 'xss';


// ....

filterHtml: (html: string) => {
        return xss(html, {
          onIgnoreTagAttr: (tag: any, name: string, value: any) => {
            if (
              name === 'class' ||
              name === 'style' ||
              name.substring(0, 5) === 'data-'
            ) {
              // escape its value using built-in escapeAttrValue function
              return name + '="' + escapeAttrValue(value) + '"';
            }

            return '';
          }
        });
      }

2betop avatar Jun 03 '25 11:06 2betop

我没看明白呢?我不是做前端开发的,我用的sdk版本,需要怎么使用哦

xiahao90 avatar Jun 04 '25 02:06 xiahao90

@2betop 能提供一下amis schema?

xiahao90 avatar Jun 04 '25 02:06 xiahao90

就是调用 amis 的时候,不是可以传入参数设置 env 吗? env 里面下发 filterHtml 函数,这个是专门来处理 html 渲染的,在这里面处理 xss 问题。如何下发 env ,请参考: https://aisuda.bce.baidu.com/amis/zh-CN/docs/start/getting-started#%E6%8E%A7%E5%88%B6-amis-%E7%9A%84%E8%A1%8C%E4%B8%BA

2betop avatar Jun 05 '25 03:06 2betop

Image 是这样写的吗?

filterHtml(html) { return xss(html, { onIgnoreTagAttr: function(tag, name, value) { if ( name === 'class' || name === 'style' || name.substring(0, 5) === 'data-' ) { return name + '="' + escapeAttrValue(value) + '"'; } return ''; } }); },

xiahao90 avatar Jun 05 '25 10:06 xiahao90

@2betop

xiahao90 avatar Jun 09 '25 02:06 xiahao90