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 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大