V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
yangajiujiuwob
V2EX  ›  问与答

purifier XSS 过滤器如何添加 video 白名单呢

  •  
  •   yangajiujiuwob · 2018-08-20 22:12:20 +08:00 · 1119 次点击
    这是一个创建于 2290 天前的主题,其中的信息可能已经有所发展或是发生改变。
    php 小白,折腾大半天也没搞定,sos

    <?php
    /**
    * Ok, glad you are here
    * first we get a config instance, and set the settings
    * $config = HTMLPurifier_Config::createDefault();
    * $config->set('Core.Encoding', $this->config->get('purifier.encoding'));
    * $config->set('Cache.SerializerPath', $this->config->get('purifier.cachePath'));
    * if ( ! $this->config->get('purifier.finalize')) {
    * $config->autoFinalize = false;
    * }
    * $config->loadArray($this->getConfig());
    *
    * You must NOT delete the default settings
    * anything in settings should be compacted with params that needed to instance HTMLPurifier_Config.
    *
    * @link http://htmlpurifier.org/live/configdoc/plain.html
    */

    return [

    'encoding' => 'UTF-8',
    'finalize' => true,
    'cachePath' => storage_path('app/purifier'),
    'settings' => [
    'default' => [
    'HTML.Doctype' => 'XHTML 1.0 Transitional',
    'HTML.Allowed' => 'div,b,font[color|style],strong,i,em,pre,a[href|title|target],ul,ol,li,p[style],br,span[style],img[width|height|alt|src|style|class],table[class|width],td,tr,blockquote,h1,h2,h3,h4,h4,h5,video[width|height|alt|src|style|class]',
    'CSS.AllowedProperties' => 'font,font-size,width,height,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align',
    'Attr.AllowedFrameTargets' =>'_blank',
    'AutoFormat.AutoParagraph' => true,
    'AutoFormat.RemoveEmpty' => true,
    ],
    'test' => [
    'Attr.EnableID' => true
    ],
    "youtube" => [
    "HTML.SafeIframe" => 'true',
    "URI.SafeIframeRegexp" => "%^( http://|https://|//)(www.youtube.com/embed/|player.vimeo.com/video/)%",
    ],
    ],

    ];
    2 条回复    2018-08-21 09:44:37 +08:00
    yangajiujiuwob
        1
    yangajiujiuwob  
    OP
       2018-08-20 22:58:44 +08:00
    0 回复惨案...
    yangajiujiuwob
        2
    yangajiujiuwob  
    OP
       2018-08-21 09:44:37 +08:00
    悲剧啊,居然 0 回复,偌大个 V2EX 竟然没有人知道么
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1058 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 20:35 · PVG 04:35 · LAX 12:35 · JFK 15:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.