그누보드 5에는 xss/csrf를 막기 위해서 html purifier가 적용되어 있습니다.
lib/common.lib.php의 conv_content 함수의 복잡한 로직이 간결하게 html purifier로 줄어져 있구요.
그누5의 html purifier를 적용하는 방법은 다음과 같습니다.
lib/common.lib.php의 conv_content 함수를 아래의 것으로 교체 합니다.
// 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)
{
global $g4;
$f = file($g4['path'].'/plugin/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($g4['path'].'/plugin/htmlpurifier/HTMLPurifier.standalone.php');
$config = HTMLPurifier_Config::createDefault();
// data/cache 디렉토리에 CSS, HTML, URI 디렉토리 등을 만든다.
$config->set('Cache.SerializerPath', $g4[data_path].'/cache');
$config->set('HTML.SafeEmbed', false);
$config->set('HTML.SafeObject', false);
$config->set('Output.FlashCompat', false);
$config->set('HTML.SafeIframe', true);
$config->set('URI.SafeIframeRegexp','%^(https?:)?//('.$safeiframe.')%');
$config->set('Attr.AllowedFrameTargets', array('_blank'));
// 불당팩 커스터마이징 -- 여기서부터
// 문자셋을 지정해 줍니다.
$config->set('Core.Encoding', $g4['charset']);
// <p> </p> 같은 코드가 정상으로 출력되게 합니다.
// http://stackoverflow.com/questions/7104689/html-purifier-clears-p-tag
$config->set('Core.EscapeNonASCIICharacters', true);
// 인터넷 주소를 자동으로 링크로 바꿔주는 기능
$config->set('AutoFormat.Linkify', true);
// 이미지 크기 제한 해제 (한국에서 많이 쓰는 웹툰이나 짤방과 호환성 유지를 위해)
$config->set('HTML.MaxImgLength', null);
$config->set('CSS.MaxImgLength', null);
$purifier = new HTMLPurifier($config);
return $purifier->purify($html);
}
그누5의 plugin/htmlpurifier/ 디렉토리의 내용물을 plug/htmlpurifier/ 디렉토리에 업로드 합니다.
data/cache 디렉토리를 만듭니다. 권한은 잘 줘야죠.
그러면 잘~!!! 동작 합니다.
ij ϸ Դϴ.
ij ϸ ram disk ϸ .