xss filter
1. 함수만
function xss_filter($content){ //xss 필터
$content = preg_replace('/(<)(|\/)(\!|\?|html|head|title|meta|body|script|style|base|noscript|
form|input|select|option|optgroup|textarea|button|label|fieldset|legend|iframe|embed|object|param|
frameset|frame|noframes|basefont|applet| isindex|xmp|plaintext|listing|bgsound|marquee|blink|
noembed|comment|xml)/i', '<$3', $content);
$content = preg_replace_callback("/([^a-z])(o)(n)/i",
create_function('$matches', 'if($matches[2]=="o") $matches[2] = "o";
else $matches[2] = "O"; return $matches[1].$matches[2].$matches[3];'), $content);
//tag 사용안하게 될 경우
//$content = str_replace( "<", "<", $content );
//$content = str_replace( ">", ">", $content );
return $content;
}
2. strip_tags
태그를 제거해버리던가
3. htmlspecialchars
**htmlentities vs htmlspecialchars
는 아래 url에서 체크
http://dance2i.tistory.com/103
주의사항..
DB 에 값을 넣어보고 테스트해볼 가치는 있을 것 같다. 기존 sql_filter랑 어떨런지 잘 모르겠다.
php에서 XSS를 막을 수 있는 가장 기초적인 방법은
htmlspecialchars()을 사용하는 방법입니다.
htmlspecialchars() : < , > , & 정도의 문자를 변경하여 줍니다.
그리고 htmlspecialchars() 외에도 htmlentities() 가 있는데 이 함수는 모든문자를 변경합니다.
그렇다보니 한글의 경우에는 깨져서 보여지게 됩니다.
그럴경우에는 htmlentities( $ ,'UTF-8') 이렇게 사용하시면 됩니다.
(UTF-8외에 EUC-KR은 사용할 수 없습니다.)
htmlspecialchars()의 반대기능인 htmlspecialchars_decode()도 있습니다.