dspld86684 2015-12-19 22:06
浏览 75
已采纳

如何在htmlpurifier中允许转换

********* Updated question **************

So I have tried to implement my own AttrDef to HTMLPurifier but it doesn't "take", and I can't debug using die() either.

Here's what I have:

I created Transform.php in the HTMLPurifier/AttrDef/CSS/ directory. The only contents so far is this (I'm only trying to hook it in for now, I will add validating logics once I see that it is in the loop and thus can test it):

<?php

/**
 * Validates Transform as defined by CSS.
 */
class HTMLPurifier_AttrDef_CSS_Transform extends HTMLPurifier_AttrDef
{
    //basing this off of the color definition so the var is $color for now, may change it to $transform later
    public function validate($color, $config, $context) {
        return $color;
    }
}

I added my file to library/HTMLPurifier.includes.php like this:

require 'HTMLPurifier/AttrDef/CSS/Transform.php';

and to the library/HTMLPurifier.safe-includes.php

require_once $__dir . '/HTMLPurifier/AttrDef/CSS/Transform.php';

(not sure about the difference between these two include files above but all AttrDef files seemed to be in both so I added my file to both as well).

Then I try to make use of this new definition by adding this to library/HTMLPurifier/CSSDefinition.php:

    // transform
    $this->info['transform'] = new HTMLPurifier_AttrDef_CSS_Transform();

It is as if all of my additions were never made, and I can't debug it by putting a die() in my own file either, nothing happens.

So any advice on where I went wrong or how I can debug this is very much appreciated.

*********** addition *******

I also tried a simple bypass by applying the Color-AttrDef to any transform property, in the CSSDefinition.php:

$this->info['transform'] = new HTMLPurifier_AttrDef_CSS_Color();

And I hacked the original Color definition like this:

//TODO: testing ways to bypass
    if (strpos($color, 'rotate(') !== false) {
        return $color;
    }

Not working. Please advice on what I am missing.

  • 写回答

1条回答 默认 最新

  • dttphb59319 2015-12-20 04:22
    关注

    You'll need to define your own AttrDef which knows how to parse and validate such definitions. Color should serve as a decent model, since the rgb syntax is similar to matrix.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题