CI 묻고 답하기

제목 xss_clean 이 멀쩡한 태그를 짤라낼 경우...
글쓴이 작성시각 2011/07/14 17:10:59
댓글 : 2 추천 : 0 스크랩 : 0 조회수 : 18962   RSS
 안녕하세요

$this->load->helper('security');
$html = '<div style="text-align: center;"><img src="http://xxx.com/f9a98d178876ecb953f5c8bc933b9d07.png" width="600"></div>';
 
$html =  xss_clean($html);

이럴 경우 결과는 

<div>img src="http://xxx.com/f9a98d178876ecb953f5c8bc933b9d07.png" width="600"></div>

이렇게 되버리네요
즉 img 태그의 왼쪽 꺽쇠가 없어져 버립니다
style 속성만 들어가면 저러는거 같습니다
2.02 사용했습니다
다른분들도 그런가요?
웹에이터를 바꿔야하는건지 고민중입니다
 다음글 쿼리문 질문 (2)
 이전글 데이터베이스 한글이 출력안되는현상 (3)

댓글

변종원(웅파) / 2011/07/14 22:23:11 / 추천 0
저도 config.php 에서 관련 셋팅을 true로 해서 모든 입력에 적용을 했었는데
웹에디터의 page break 기능을 못 쓰게 되더군요. <p>태크에 style를 추가해서 사용하는데
자동으로 없애버리더군요.

소스를 보니 style 태그를 이용한 xss 공격이 가능하네요. 그래서 막아 놓았구요.
실제 코딩할때 <div class="center"></div> 가 맞겠죠. ^^
좀 귀찮더라도 문제를 유발할 수 있는 방식은 사용하지 않는 것이 좋습니다.

/*
  * Remove Evil HTML Attributes (like evenhandlers and style)
  *
  * It removes the evil attribute and either:
  *  - Everything up until a space
  *  For example, everything between the pipes:
  *  <a |style=[removed]('hello');alert('world');| class=link>
  *  - Everything inside the quotes 
  *  For example, everything between the pipes:
  *  <a |style="[removed]('hello'); alert('world');"| class="link">
  *
  * @param string $str The string to check
  * @param boolean $is_image TRUE if this is an image
  * @return string The string with the evil attributes removed
  */
 protected function _remove_evil_attributes($str, $is_image)
security 코어중 관련 함수 일부입니다.
/ 2011/07/15 13:25:34 / 추천 0
그렇군요
사용중인 웹에디터가  크롬에서는 그런식으로 태그를 생성하는지라 ...
답변 감사합니다.