【问题标题】:Sanatize html on server in schema在架构中清理服务器上的 html
【发布时间】:2016-03-28 02:04:08
【问题描述】:

我已经安装了mpowaga:autoform-summernotedjedi:sanitize-html 来尝试清理进入simpleschema 的数据,但是我不确定如何让它工作。我只希望用户能够添加“p”和“a”标签以及粗体和斜体样式。我在这里做错了什么?

description: {
       type: String,  
        optional: true,
        autoform: {             
            afFieldInput: {
                type: 'summernote', 
                class: 'editor',
                settings: {
                    allowedTags: ['p', 'a'],
                    toolbar: [
                        ['style', ['bold', 'italic']],
                        ['para', ['ul', 'ol']]
                      ]
                }
            }
        }
    }

【问题讨论】:

    标签: meteor meteor-autoform simple-schema


    【解决方案1】:

    我也有同样的问题。

    要开始回答您的问题,我认为您不能对您的 SimpleSchema 内部进行消毒(尽管我希望我错了,因为那是最简单的)。据我所知,该设置对象适用于 summer-note's 选项...例如工具栏上将显示什么。我不认为该对象是您可以使用djedi:sanitize-html 功能的地方:

    http://summernote.org/deep-dive/ https://github.com/mpowaga/meteor-autoform-summernote/issues/16

    这个 GitHub 问题似乎表明 sanitize 应该进入某种 before hook:

    https://github.com/mpowaga/meteor-autoform-summernote/issues/13

    但是,我认为 autoform 钩子是客户端的,所以 djedi:sanitize-html 不会在那里工作。有一个客户端版本 (djedi:sanitize-html-client),但我不确定这是否不安全并违背了消毒的目的?

    就我个人而言,我正在使用带有方法调用的自动表单。如果解决了我会反馈的。

    进一步阅读:

    【讨论】:

    • 在autovalue钩子里放一个console语句,看它是否在服务器上运行。几乎可以肯定它确实如此。编辑:误读,自动生成挂钩仅在客户端上运行。自动值简单模式挂钩在客户端和服务器上运行。
    • 你觉得这个@A.com 怎么样?
    【解决方案2】:

    在summernote设置中设置允许的标签只会在客户端起作用,并且不安全。你需要这样的东西来清理服务器。

    description: {
           type: String,  
            optional: true,
            autoValue: function(){
              return Meteor.isServer ? sanitizeHtml( this.value ) : this.value;
            },
            autoform: {             
                afFieldInput: {
                    type: 'summernote', 
                    class: 'editor',
                    settings: ...
                }
            }
        }
    

    【讨论】:

    • 谢谢,jimmiebltr 这看起来很有希望。你如何设置允许的值,例如只允许字体大小 16px 或字体类型

    • 你将很难设置允许的样式,内联样式中的 css 更难清理。尽管npmjs.com/package/sanitize-html 在这里找到其余的文档
    猜你喜欢
    • 2016-11-30
    • 2022-10-14
    • 1970-01-01
    • 2014-06-03
    • 2015-02-24
    • 1970-01-01
    • 2011-10-02
    • 2020-07-07
    • 1970-01-01
    相关资源
    最近更新 更多