diff --git a/classes/context/Context.class.php b/classes/context/Context.class.php index 6be9ec809..989a3156b 100644 --- a/classes/context/Context.class.php +++ b/classes/context/Context.class.php @@ -1022,17 +1022,10 @@ /** * @brief 내용의 에디터 컴포넌트 코드를 변환 **/ - function _fixQuotation($matches) { - $key = $matches[1]; - $val = $matches[2]; - if(substr($val,0,1)!='"') $val = '"'.$val.'"'; - return sprintf('%s=%s', $key, $val); - } - function transEditorComponent($matches) { // IE에서는 태그의 특성중에서 " 를 빼어 버리는 경우가 있기에 정규표현식으로 추가해줌 $buff = $matches[0]; - $buff = preg_replace_callback('/([^=^"^ ]*)=([^ ^>]*)/i', array($this, _fixQuotation), $buff); + $buff = preg_replace_callback('/([^=^"^ ]*)=([^ ^>]*)/i', fixQuotation, $buff); $buff = str_replace("&","&",$buff); // 에디터 컴포넌트에서 생성된 코드 diff --git a/config/func.inc.php b/config/func.inc.php index f68de7fce..3e2e01f0b 100644 --- a/config/func.inc.php +++ b/config/func.inc.php @@ -416,6 +416,9 @@ // XSS 사용을 위한 이벤트 제거 $content = preg_replace_callback("!<([a-z]+)(.*?)>!is", removeJSEvent, $content); + // 이미지나 동영상등의 태그에서 src에 관리자 세션을 악용하는 코드를 제거 + $content = preg_replace_callback("!<([a-z]+)(.*?)>!is", removeSrcHack, $content); + return $content; } @@ -425,6 +428,45 @@ return preg_replace('/ on([a-z]+)=/i',' _on$1=',$matches[0]); } + function removeSrcHack($matches) { + $tag = $matches[1]; + + $buff = trim(preg_replace('/(\/>|>)/','/>',$matches[0])); + $buff = preg_replace_callback('/([^=^"^ ]*)=([^ ^>]*)/i', fixQuotation, $buff); + + $oXmlParser = new XmlParser(); + $xml_doc = $oXmlParser->parse($buff); + + // src값에 module=admin이라는 값이 입력되어 있으면 이 값을 무효화 시킴 + $src = $xml_doc->{$tag}->attrs->src; + if($src) { + $url_info = parse_url($src); + $query = $url_info['query']; + $queries = explode('&', $query); + $cnt = count($queries); + for($i=0;$i<$cnt;$i++) { + $pos = strpos($queries[$i],'='); + if($pos === false) continue; + $key = strtolower(trim(substr($queries[$i], 0, $pos))); + $val = strtolower(trim(substr($queries[$i] ,$pos+1))); + if(($key == 'module' && $val == 'admin') || $key == 'act' && preg_match('/admin/i',$val)) return sprintf("<%s>",$tag); + } + } + + return $matches[0]; + + } + + /** + * @brief attribute의 value를 " 로 둘러싸도록 처리하는 함수 + **/ + function fixQuotation($matches) { + $key = $matches[1]; + $val = $matches[2]; + if(substr($val,0,1)!='"') $val = '"'.$val.'"'; + return sprintf('%s=%s', $key, $val); + } + // hexa값을 RGB로 변환 if(!function_exists('hexrgb')) { function hexrgb($hexstr) { diff --git a/modules/opage/opage.controller.php b/modules/opage/opage.controller.php index d23bb1528..177b663fb 100644 --- a/modules/opage/opage.controller.php +++ b/modules/opage/opage.controller.php @@ -72,7 +72,7 @@ $this->target_path = $path; // element의 속성중 value에 " 로 안 묶여 있는 것을 검사하여 묶어줌 - $content = preg_replace_callback('/([^=^"^ ]*)=([^ ^>]*)/i', array($this, '_fixQuotation'), $content); + $content = preg_replace_callback('/([^=^"^ ]*)=([^ ^>]*)/i', fixQuotation, $content); // img, input, a, link등의 href, src값 변경 $content = preg_replace_callback('!(script|link|a|img|input)([^>]*)(href|src)=[\'"](.*?)[\'"]!is', array($this, '_replaceSrc'), $content); @@ -104,16 +104,5 @@ $buff = sprintf('url(%s)', $href); return $buff; } - - /** - * @brief 태그의 속성에 " 를 추가 - **/ - function _fixQuotation($matches) { - $key = $matches[1]; - $val = $matches[2]; - if(substr($val,0,1)!='"') $val = '"'.$val.'"'; - return sprintf('%s=%s', $key, $val); - } - } ?>