vditor 에디터 코드 블럭 내의 내용 htmlpurifier 우회하기
본문
위와 같이 작업하면 우회할 필요없습니다!
안해도 됩니다!
-------------------
우회해야하는 이유
코드 블럭 내의 코드 중에 script 등 사이트 보안을 위협하는 구문이 htmlpurifier에 의해 제거되는 것을 막기 위함입니다.
그누보드 5.4.2.7 기준
/lib/common.lib.php 파일 576번째 줄에 보면
// http://htmlpurifier.org // Standards-Compliant HTML Filtering // Safe : HTML Purifier defeats XSS with an audited whitelist // Clean : HTML Purifier ensures standards-compliant output // Open : HTML Purifier is open-source and highly customizable function html_purifier($html) { $f = file(G5_PLUGIN_PATH.'/htmlpurifier/safeiframe.txt'); $domains = array(); foreach($f as $domain){ // 첫행이 # 이면 주석 처리 if (!preg_match("/^#/", $domain)) { $domain = trim($domain); if ($domain) array_push($domains, $domain); } } // 내 도메인도 추가 array_push($domains, $_SERVER['HTTP_HOST'].'/'); $safeiframe = implode('|', $domains); include_once(G5_PLUGIN_PATH.'/htmlpurifier/HTMLPurifier.standalone.php'); include_once(G5_PLUGIN_PATH.'/htmlpurifier/extend.video.php'); $config = HTMLPurifier_Config::createDefault(); // data/cache 디렉토리에 CSS, HTML, URI 디렉토리 등을 만든다. $config->set('Cache.SerializerPath', G5_DATA_PATH.'/cache'); $config->set('HTML.SafeEmbed', false); $config->set('HTML.SafeObject', false); $config->set('Output.FlashCompat', false); $config->set('HTML.SafeIframe', true); if( (function_exists('check_html_link_nofollow') && check_html_link_nofollow('html_purifier')) ){ $config->set('HTML.Nofollow', true); // rel=nofollow 으로 스팸유입을 줄임 } $config->set('URI.SafeIframeRegexp','%^(https?:)?//('.$safeiframe.')%'); $config->set('Attr.AllowedFrameTargets', array('_blank')); //유튜브, 비메오 전체화면 가능하게 하기 $config->set('Filter.Custom', array(new HTMLPurifier_Filter_Iframevideo())); $purifier = new HTMLPurifier($config); return $purifier->purify($html); }
위와 같은 내용이 있습니다. 해당 내용에 ``` 코드 블럭 안의 내용을 우회하는 부분을 추가할 것입니다.
// http://htmlpurifier.org/ // Standards-Compliant HTML Filtering // Safe : HTML Purifier defeats XSS with an audited whitelist // Clean : HTML Purifier ensures standards-compliant output // Open : HTML Purifier is open-source and highly customizable function html_purifier($html) { $f = file(G5_PLUGIN_PATH.'/htmlpurifier/safeiframe.txt'); $domains = array(); foreach($f as $domain){ // 첫행이 # 이면 주석 처리 if (!preg_match("/^#/", $domain)) { $domain = trim($domain); if ($domain) array_push($domains, $domain); } } // 내 도메인도 추가 array_push($domains, $_SERVER['HTTP_HOST'].'/'); $safeiframe = implode('|', $domains); include_once(G5_PLUGIN_PATH.'/htmlpurifier/HTMLPurifier.standalone.php'); include_once(G5_PLUGIN_PATH.'/htmlpurifier/extend.video.php'); $config = HTMLPurifier_Config::createDefault(); // data/cache 디렉토리에 CSS, HTML, URI 디렉토리 등을 만든다. $config->set('Cache.SerializerPath', G5_DATA_PATH.'/cache'); $config->set('HTML.SafeEmbed', false); $config->set('HTML.SafeObject', false); $config->set('Output.FlashCompat', false); $config->set('HTML.SafeIframe', true); if( (function_exists('check_html_link_nofollow') && check_html_link_nofollow('html_purifier')) ){ $config->set('HTML.Nofollow', true); // rel=nofollow 으로 스팸유입을 줄임 } $config->set('URI.SafeIframeRegexp','%^(https?:)?//('.$safeiframe.')%'); $config->set('Attr.AllowedFrameTargets', array('_blank')); //유튜브, 비메오 전체화면 가능하게 하기 $config->set('Filter.Custom', array(new HTMLPurifier_Filter_Iframevideo())); $purifier = new HTMLPurifier($config); //return $purifier->purify($html); 원본은 여기서 끝 preg_match_all('#```.+?```#s', $html, $matches); // Markdown ```~``` 구간 구하기 $change = []; // 백업↔복구용 foreach ( $matches[0] as $k=>$v ) $change['^[CODE'.($k+1).']^'] = $v; // 내용에 사용되지 않을만한 문자열로 지정 $html = strtr($html, array_flip($change)); // ```코드``` → ^[CODE0]^ $html = $purifier->purify($html); // HTML Purifier 적용 $html = strtr($html, $change); // ^[CODE0]^ → ```코드``` return $html; }
위와 같이 바꾸면 됩니다.
상세 내용은 관련 링크를 참조하세요.
관련자료
-
링크
댓글 0개
등록된 댓글이 없습니다.