nicedit - 它安全吗?它是否受到网站 CSS 的影响?

发布于 2024-11-24 14:40:21 字数 304 浏览 0 评论 0原文

我正在考虑在我的网站上使用 nicedit (http://nicedit.com/)。

我假设 nicedit 只是使用按钮创建简单的 html,并且当用户保存该 html 时发送该 html。

  1. 推荐吗?有人还在研究吗?
  2. 假设我稍后在我的网站某处显示此 HTML,由于用户能够植入恶意 JavaScript,这不是很危险吗?如果不是,nicedit 如何防止这种情况发生?
  3. 另外,当我稍后显示这个HTML时,它会受到我的CSS的影响吗?如果是这样,我该如何防止这种情况发生?

谢谢。

I'm considering using nicedit (http://nicedit.com/) for my site.

I assume that nicedit simply creates simple html using the buttons, and that html gets sent when the user saves it.

  1. Is it recommended? Is someone still working on it?
  2. Assuming I'm later displaying this HTML in my site somewhere, isn't it dangerous due to the user being able to plant malicious javascript? If not, how does nicedit prevents this?
  3. Also, when I display this HTML later, will it be affected by my css? If so, how can I prevent this?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

递刀给你 2024-12-01 14:40:21

这就是我所使用的,它就像一个魅力,可以在放入数据库之前清理 nicedit 实例的内容

function cleanFromEditor($text) { 

    //try to decode html before we clean it then we submit to database
    $text = stripslashes(html_entity_decode($text));

    //clean out tags that we don't want in the text
    $text = strip_tags($text,'<p><div><strong><em><ul><ol><li><u><blockquote><br><sub><img><a><h1><h2><h3><span><b>');

    //conversion elements
    $conversion = array(
        '<br>'=>'<br />',
        '<b>'=>'<strong>',
        '</b>'=>'</strong>',
        '<i>'=>'<em>',
        '</i>'=>'</em>'
    );

    //clean up the old html with new
    foreach($conversion as $old=>$new){
        $text = str_replace($old, $new, $text);
    }   

    return htmlentities(mysql_real_escape_string($text));
} 

This is what I use it works like a charm for cleaning out the content of the nicedit instance before chucking into the database

function cleanFromEditor($text) { 

    //try to decode html before we clean it then we submit to database
    $text = stripslashes(html_entity_decode($text));

    //clean out tags that we don't want in the text
    $text = strip_tags($text,'<p><div><strong><em><ul><ol><li><u><blockquote><br><sub><img><a><h1><h2><h3><span><b>');

    //conversion elements
    $conversion = array(
        '<br>'=>'<br />',
        '<b>'=>'<strong>',
        '</b>'=>'</strong>',
        '<i>'=>'<em>',
        '</i>'=>'</em>'
    );

    //clean up the old html with new
    foreach($conversion as $old=>$new){
        $text = str_replace($old, $new, $text);
    }   

    return htmlentities(mysql_real_escape_string($text));
} 
司马昭之心 2024-12-01 14:40:21
  1. 它似乎不再被维护。但我已经将它用于我只需要一个简单/轻量级所见即所得编辑器的用途。如果您正在寻找不断获得核心更新或附加功能的东西,我不会指望它。我终于崩溃了,写了很多我自己的功能,比如表格和 YouTube 视频。

  2. 是的,黑客可以使用它在您的网站上发布客户端和/或服务器漏洞。但这是任何编辑都可能面临的威胁。您需要过滤两种方法的代码。

您需要通过清理 post 变量来防止 SQL 注入。我总是把它放在脚本的开头来清理它们,并使用 $input['whateveryouarepassing'] 而不是 $_POST['whateveryouarepassing'] 调用它们。编辑 $mysqli->real_escape_string() 部分以使用您的数据库对象。使用 MySQLi 或 PDO 以及准备好的语句来帮助强化攻击。

$input = array();

if(isset($_POST)) {

    foreach ($_POST as $key => $value) {

        if (@get_magic_quotes_gpc()) {

            $key = stripslashes($key);

            $value = stripslashes($value);

        }

        $key = $mysqli->real_escape_string($key);

        $value = $mysqli->real_escape_string($value);

        $input[$key] = $value;

    }

}

然后我喜欢用这个函数来清理它,多年来我用各种方法来清理坏代码。如果可以设置,请改用 HTML Purifier。如果没有的话,这就是这个坏男孩。使用 cleanHTML($input['whateveryouarepassing']); 调用它。

function cleanHTML($string) {

    $string = preg_replace('#(&\#*\w+)[\x00-\x20]+;#u', "$1;", $string);

    $string = preg_replace('#(&\#x*)([0-9A-F]+);*#iu', "$1$2;", $string);

    $string = html_entity_decode($string, ENT_COMPAT, "UTF-8");

    $string = preg_replace('#(<[^>]+[\x00-\x20\"\'\/])(on|xmlns)[^>]*>#iUu', "$1>", $string);

    $string = preg_replace('#([a-z]*)[\x00-\x20\/]*=[\x00-\x20\/]*([\`\'\"]*)[\x00-\x20\/]*j[\x00-\x20]*a[\x00-\x20]*v[\x00-\x20]*a[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iUu', '$1=$2nojavascript...', $string);

    $string = preg_replace('#([a-z]*)[\x00-\x20\/]*=[\x00-\x20\/]*([\`\'\"]*)[\x00-\x20\/]*v[\x00-\x20]*b[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iUu', '$1=$2novbscript...', $string);

    $string = preg_replace('#([a-z]*)[\x00-\x20\/]*=[\x00-\x20\/]*([\`\'\"]*)[\x00-\x20\/]*-moz-binding[\x00-\x20]*:#Uu', '$1=$2nomozbinding...', $string);

    $string = preg_replace('#([a-z]*)[\x00-\x20\/]*=[\x00-\x20\/]*([\`\'\"]*)[\x00-\x20\/]*data[\x00-\x20]*:#Uu', '$1=$2nodata...', $string);

    $string = preg_replace('#(<[^>]+[\x00-\x20\"\'\/])style[^>]*>#iUu', "$1>", $string);

    $string = preg_replace('#</*\w+:\w[^>]*>#i', "", $string);

    $string = preg_replace('/^<\?php(.*)(\?>)?$/s', '$1', $string);

    $string = preg_replace('#</*(applet|meta|xml|blink|link|script|embed|object|frame|iframe|frameset|ilayer|layer|bgsound|title|base)[^>]*>#i', "", $string);

    return $string;

}
  1. HTML在编辑和显示时会受到CSS的影响。如果这是一个问题,您将需要编写额外的 CSS 规则。如果问题是在编辑时移动到基于 iframe 的编辑器,并防止 css 在 iframe 中显示 html 内容。

  2. 如果您需要其他建议,elRTE 是我这些天的首选编辑。更高级一点,但一旦您了解了代码库和 API,就完全值得了。您将像任何编辑一样面临与上述相同的问题。编辑期间的 CSS 除外,因为 elRTE 是基于框架的,您可以指定样式表。 elRTE 主页

编辑:我发布此内容假设您使用的是 PHP。如果没有,抱歉。

  1. It doesn't appear to be maintained anymore. But I have used it for purposes where I needed just a simple/lightweight WYSIWYG editor. If you are looking for something that gets constant core updates or additional features I wouldn't count on it. I finally broke down and wrote a lot of my own features like tables and YouTube videos.

  2. Yes, a hacker could use it to post an client and/or server exploit on your site. But this is a threat you can face with any editor. You need to filter the code for two methods.

You need to prevent SQL injection by sanitizing your post variables. I always put this at the beginning of my scripts to clean them and call them with $input['whateveryouarepassing']instead of $_POST['whateveryouarepassing']. Edit the $mysqli->real_escape_string() parts to work with your database object. Use MySQLi or PDO with prepared statements to help harden the attack.

$input = array();

if(isset($_POST)) {

    foreach ($_POST as $key => $value) {

        if (@get_magic_quotes_gpc()) {

            $key = stripslashes($key);

            $value = stripslashes($value);

        }

        $key = $mysqli->real_escape_string($key);

        $value = $mysqli->real_escape_string($value);

        $input[$key] = $value;

    }

}

Then I like to clean it with this function I put together over the years with various methods of cleaning out bad code. Use HTML Purifier instead if you can set it up. If not, here is this bad boy. Call it with cleanHTML($input['whateveryouarepassing']);.

function cleanHTML($string) {

    $string = preg_replace('#(&\#*\w+)[\x00-\x20]+;#u', "$1;", $string);

    $string = preg_replace('#(&\#x*)([0-9A-F]+);*#iu', "$1$2;", $string);

    $string = html_entity_decode($string, ENT_COMPAT, "UTF-8");

    $string = preg_replace('#(<[^>]+[\x00-\x20\"\'\/])(on|xmlns)[^>]*>#iUu', "$1>", $string);

    $string = preg_replace('#([a-z]*)[\x00-\x20\/]*=[\x00-\x20\/]*([\`\'\"]*)[\x00-\x20\/]*j[\x00-\x20]*a[\x00-\x20]*v[\x00-\x20]*a[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iUu', '$1=$2nojavascript...', $string);

    $string = preg_replace('#([a-z]*)[\x00-\x20\/]*=[\x00-\x20\/]*([\`\'\"]*)[\x00-\x20\/]*v[\x00-\x20]*b[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iUu', '$1=$2novbscript...', $string);

    $string = preg_replace('#([a-z]*)[\x00-\x20\/]*=[\x00-\x20\/]*([\`\'\"]*)[\x00-\x20\/]*-moz-binding[\x00-\x20]*:#Uu', '$1=$2nomozbinding...', $string);

    $string = preg_replace('#([a-z]*)[\x00-\x20\/]*=[\x00-\x20\/]*([\`\'\"]*)[\x00-\x20\/]*data[\x00-\x20]*:#Uu', '$1=$2nodata...', $string);

    $string = preg_replace('#(<[^>]+[\x00-\x20\"\'\/])style[^>]*>#iUu', "$1>", $string);

    $string = preg_replace('#</*\w+:\w[^>]*>#i', "", $string);

    $string = preg_replace('/^<\?php(.*)(\?>)?$/s', '$1', $string);

    $string = preg_replace('#</*(applet|meta|xml|blink|link|script|embed|object|frame|iframe|frameset|ilayer|layer|bgsound|title|base)[^>]*>#i', "", $string);

    return $string;

}
  1. The HTML will be affected by your CSS when editing and displayed. You will need code additional CSS rules if this is an issue. If the issue is when editing move to a iframe based editor and to prevent the css display the html content in an iframe.

  2. If you want another suggestion elRTE is my goto editor these days. A little more advanced but totally worth it once you get to know the code base and API. You will face the same issues as above as will any editor. Except the CSS during editing since elRTE is framebased and you can specify stylesheets. elRTE Homepage

Edit: I posted this assuming you were using PHP. Apologies if not.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文