2077 Posts in 484 Topics- by 821 Members - Latest Member: liricklagu

Pages: [1]   Go Down
  Print  
Author Topic: DisAllow the Malicious Atribute Code  (Read 875 times)
webmaster
Administrator
phpBB Guru
*****
Offline Offline

Posts: 924


hairulazami
View Profile WWW
« on: August 16, 2008, 02:50:30 PM »

DisAllow the Malicious Atribute Code

apa yang gw maksud dengan judul postingan gw ini??

mari belajar bagaimana mendisable menggunakan atribut2 terlarang pada postingan form, misalna aja

Code:
<a href='onMouseOver:javascript.alert(test)'>



gunakan fungsi dibawah ini, dalam bahasa php mudah2an berguna:

Code:
/**
 * tags yg diijinkan
 */
$allowedTags = '<b><strong><i><em><ul><ol><li><pre><blockquote><p><br><img>';

/**
 * attributes/prefix yang tidak diijinkan dalam tags
 */
$stripAttrib = 'javascript:|onclick|ondblclick|onmousedown|onmouseup|onmouseover|'.
               'onmousemove|onmouseout|onkeypress|onkeydown|onkeyup';

/**
 * @return string
 * @param string
 * @desc Strip forbidden tags dan daur ulang tag-source untuk di check oleh fungsi removeEvilAttributes()
 */
function removeEvilTags($source)
{
    global $allowedTags;
    $source = strip_tags($source, $allowedTags);
    return preg_replace('/<(.*?)>/ie', "'<'.removeEvilAttributes('\\1').'>'", $source);
}

/**
 * @return string
 * @param string
 * @desc Strip forbidden attributes, dari sebuah tag
 */
function removeEvilAttributes($tagSource)
{
    global $stripAttrib;
    return stripslashes(preg_replace("/$stripAttrib/i", 'forbidden', $tagSource));
}
« Last Edit: January 01, 1970, 07:00:00 AM by webmaster » Logged


Pages: [1]   Go Up
  Print  
 
Jump to: