2012-06-19 4 views
0

HTMLPURIFIER를 구현하려고하는데 HTML을 반향시킨 후에 정화하고 싶습니다. 표시된 내용의 일부로
<img src="kay.JPG" alt="my picture" />을받는 동시에 그림을 표시합니다. 내가 뭘 잘못하고 있니?htmlpurifier 구현하는 방법

 function readmore_about_cs($row, $id) 

    {  
      $config = HTMLPurifier_Config::createDefault(); 
      // configuration goes here: 
      $config->set('Core.Encoding', 'UTF-8'); 
      $config->set('HTML.Doctype', 'XHTML 1.0 Transitional'); 
      $purifier = new HTMLPurifier($config); 

    if (isset($_GET['readmore'])) { 
    $nomore = ($row['about_church_of_christ_content']); 
    $pure_html = $purifier->purify($nomore); 
    echo htmlspecialchars($pure_html); 
    } 
    else 
    {       
    if (strlen(trim($row['about_church_of_christ_content'])) > 350) 
    { 
    $shortText = substr(trim($row['about_church_of_christ_content']), 0, 650); 
    $shortText .= '..<a href="http://127.0.0.1/church/about_cs.php?id='.$id.'&readmore=1">More</a>'; 
    $pure_html = $purifier->purify($shortText); 
    echo htmlspecialchars($shortText) ; 
    } 
    } 
    }  
+0

사람이 저를 도와주세요. –

답변

0

당신과 함께 일어나는 것은 HTMLPurifier의 기본 동작, 당신은 기본적으로 'SRC'속성을 통해 XSS 공격을 허용하고로 다음과 같은 솔루션은 보안에 구멍을 만들 것이라고 경고한다.

다음은 코드에 추가해야합니다 내용은 다음과 같습니다

// configuration goes here: 
$config->set('HTML.Allowed','img[src], img[alt]');