首页 > CMS > PhpCMS > 正文

解决phpcms评论跳转的bug问题

2024-09-10 07:16:13
字体:大 中 小
来源:转载
供稿:网友

phpcms内容页评论有个bug,当发布评论之后,跳转到“完整评论列表”的页面,而不是回到当前评论框的页面,后来phpcms的一次升级修复了这个bug.

这种小问题却非常让人头疼,让我们来分析一下这个bug是怎么产生的?

phpcms是通过iframe一个评论页面到内容页实现评论功能的,这个评论页面的表单,提交到{APP_PATH}index.php?m=comment&c=index&a=post&commentid={$commentid}进行处理.

我们可以到comment模块的index控制器的post方法查看,看到_show_msg()方法,它又调用了showmessage()方法,showmessage()引入了提示模板,代码如下:

  1. function showmessage($msg, $url_forward = 'goback', $ms = 600, $dialog = '') { 
  2. if(defined('IN_ADMIN')) { 
  3. include(admin::admin_tpl('showmessage', 'admin')); 
  4. } else { 
  5. include(template('content', 'message')); 
  6. } 
  7. exit; 
  8. } 

然后我们打开模板下content下的message模板页面,页面的跳转都是它来实现的,代码如下:

<a href="{remove_xss($url_forward)}">如果您的浏览器没有自动跳转,请点击这里</a>

问题就在这里remove_xss(),我们看看remove_xss()方法,代码如下:

  1. $parm1 = Array('javascript', 'vbscript', 'expression', 'applet', 'meta', 'xml', 'blink', 'link', 'script', 'embed', 'object', 'iframe', 'frame', 'frameset', 'ilayer', 'layer', 'bgsound', 'title', 'base'); 
  2.  
  3.  $parm2 = Array('onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavailable', 'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterchange', 'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload');  

这里只是节选,发现它把带有iframe的html给过滤掉了,这样跳转到之前的页面/index.php?m=comment&c=index&a=init&commentid=content_13-20-1&iframe=1,这里的iframe就不见了,再看看init方法,代码如下:

  1. if (isset($_GET['iframe'])) { 
  2.  if (strpos($url,APP_PATH) === 0) { 
  3.   $domain = APP_PATH; 
  4.  } else { www.111cn.net 
  5.   $urls = parse_url($url); 
  6.   $domain = $urls['scheme'].'://'.$urls['host'].(isset($urls['port']) && !emptyempty($urls['port']) ? ":".$urls['port'] : '').'/'; 
  7.  } //开源软件:Vevb.com 
  8.  include template('comment', 'show_list'); 
  9. } else { 
  10.  include template('comment', 'list'); 
  11. } 

恍然大悟了,当iframe存在的时候,就调用show_list页面,否则就是“查看全部评论”的页面.

修改方法:

把message页面提示模板的remove_xss方法改成trim_script()方法,代码如下:

  1. function trim_script($str) { 
  2.  if(is_array($str)){ 
  3.   foreach ($str as $key => $val){ 
  4.    $str[$key] = trim_script($val); 
  5.   } 
  6.   }else{ 
  7.    $str = preg_replace ( '//<([//]?)script([^/>]*?)/>/si', '&lt;//1script//2&gt;', $str ); 
  8.   $str = preg_replace ( '//<([//]?)iframe([^/>]*?)/>/si', '&lt;//1iframe//2&gt;', $str ); 
  9.   $str = preg_replace ( '//<([//]?)frame([^/>]*?)/>/si', '&lt;//1frame//2&gt;', $str ); 
  10.   $str = str_replace ( 'javascript:', 'javascript:', $str ); 
  11.   } 
  12.  return $str; 
  13. }  

用这个方法进行安全过滤.

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表