ExtJS 7.1 Tag字段正在执行XSS标记

yk9xbfzb  于 2022-11-05  发布在  其他
关注(0)|答案(1)|浏览(157)

我在输入〈img src=a onerror=alert('xss!')〉时遇到了一个关于标记域组件的问题。这个标记在输入整个值后执行。我已经尝试过在keyup、keypress、keydown和beforquery事件上阻止标记执行,但它仍然在执行。这个代码块在检测到XSS标记时阻止事件执行。

Ext.application({
    name: 'Fiddle',

    launch: function () {

        var shows = Ext.create('Ext.data.Store', {
            fields: ['id', 'show'],
            data: []
        });

        Ext.create('Ext.form.Panel', {
            renderTo: Ext.getBody(),
            title: 'Sci-Fi Television',
            height: 200,
            width: 500,
            items: [{
                xtype: 'tagfield',
                itemId: 'tagField',
                fieldLabel: 'Select a Show',
                store: shows,
                displayField: 'show',
                valueField: 'id',
                queryMode: 'local',
                filterPickList: false,
                listeners: {
                    beforequery: function () {
                        var editor = Ext.ComponentQuery.query('#tagField')[0];
                        if (editor.inputEl.getValue().search(new RegExp('(<([^>]+)>)')) >= 0) {
                            editor.inputEl.dom.value = '';
                            return false;
                        }
                    },
                    keypress: function (textfield, event) {
                        var editor = Ext.ComponentQuery.query('#tagField')[0];
                        if (editor.inputEl.getValue().search(new RegExp('(<([^>]+)>)')) >= 0) {
                            editor.inputEl.dom.value = '';
                            return false;
                        }
                    },
                    keydown: function (textfield, event) {
                        var editor = Ext.ComponentQuery.query('#tagField')[0];
                        if (editor.inputEl.getValue().search(new RegExp('(<([^>]+)>)')) >= 0) {
                            editor.inputEl.dom.value = '';
                            return false;
                        }
                    },
                }
            }]
        });

    }
});

enter image description here

jk9hmnmh

jk9hmnmh1#

这花了一点时间来寻找,但显然在Ext. form.field.ComboBox中,有一个onFieldMutation处理程序,它确实是所有这些的关键。看看这个Fiddle和负责处理它的代码...我相信这就是你要找的:

Ext.define('ComboOverride', {
  override: 'Ext.form.field.ComboBox',

  onFieldMutation: function (e) {
    var inputDom = this.inputEl.dom;
    if (Ext.String.hasHtmlCharacters(inputDom.value)) {
      inputDom.value = '';
      alert('XSS Detected, Removing');
    }
    return this.callParent(arguments);
  }
});

相关问题