النتائج 1 إلى 2 من 2

الموضوع: دالة حماية بالمواصفات التالية قابلة للربط مع wysiwyg

  1. #1
    عضو نشيط
    تاريخ التسجيل
    Jun 2008
    المشاركات
    54

    دالة حماية بالمواصفات التالية قابلة للربط مع wysiwyg



    السلام عليكم
    لى طلب وارجو أن لا تخذلونى
    أريد
    لغة البرمجة : ........php .................
    الاستفسار : .............................
    أريد دالة حماية تقوم بالحماية من أكواد Html ولكن تسمح ببعضها بمعنى
    أننى أريد أن اربط محرر wysiwyg ببرنامجى
    والمحرر يبعث الأأكواد بصيغة Html
    وهنا المشكلة ، أنا أريد أن أسمح بعض الأاكواد ولكن ليس كلها
    توجد دالة stri_tags ولكن لا اظن انها تكفى للحماية من أخطار xss
    فما الحل ؟
    أنا قمت بتجميع دالة وأريد رأيكم ان كانت تنفع أم لا


    كود PHP:
     
    function CleanXSS($str){
        
    // One of the easiest way to do XSS is to use one of the on* attributes, like onclick or onload. 
        // With this you can easily execute a script, without the user even having to do something (with onload, etc) 
        // or just having to click or hover over something. We just remove them all with 
        
    $str preg_replace('#(<[^>]+[\s\r\n\"\'])(on|xmlns)[^>]*>#iU',"$1>",$str); 
     
        
    // As you certainly know, can you use javascript: and vbscript: as protocol handlers instead of http:// and others. 
        // Something like <a href="javascript:alert('foobar')">lll</a> executes just nicely if a user clicks on it. 
        // We of course remove that as well. IE as also the strange behaviour that something like "java script :" is also valid, 
        // so we have to check for a whitespace between every character. 
        
    $str preg_replace('#([a-z]*)[\x00-\x20]*=[\x00-\x20]*([\`\'\"]*)[\\x00-\x20]*j[\x00-\x20]*a[\x00-\x20]*v[\x00-\x20]*a[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iU','$1=$2nojavascript...',$str); 
        
    $str preg_replace('#([a-z]*)[\x00-\x20]*=([\'\"]*)[\x00-\x20]*v[\x00-\x20]*b[\x00-\x20]*s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i[\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:#iU','$1=$2novbscript...',$str); 
     
        
    // We removed all namespace declarations above, here we remove all elements, which have a prefix, they are not needed in HTML.. 
        
    $str preg_replace('#</*\w+:\w[^>]*>#i','',$str); 
     
        
    // There are quite some elements in HTML, which you definitively don't want in something like user comments. 
        // The reason for the while loop is, that stuff like 
        // <sc<script>ript>alert('hello')</sc</script>ript> 
        // We remove them with: 
        
    do { 
            
    $oldstr $str
            
    $str preg_replace('#</*(\?xml|applet|meta|xml|blink|link|style|script|object|iframe|frame|frameset|ilayer|layer|bgsound|title|base)[^>]*>#i',"",$str); 
        } while (
    $oldstr != $str); 
     
        return 
    $str

     
    $text='""<img src="iii.pic" alt="gfgfgfgfgfgfgfgfgfgfgfgfgfgfg"  onclick="alert(1);"  />';
    $text=CleanXSS($text);
    $text strip_tags($text,'<font>,<b>,<title>,<i>,<u>,<p>,</p>,</font>,</b>,<hl>,<ul>,<li>,<ol>,</li>,</ol>,<a>,<img>,<hr />,<br>,<br />,<sub>,<span>,</span>,<h2>,<h3>,<h4>,<h5>,<h6>,<pref>,</pref>,<address>,<hr>');
     
     
    echo 
    $text
    مثال توضيحي : ............................
    اضافات اخرى : ............................
    أرجو الحل
    وشكرااا







  2. #2
    عضو نشيط
    تاريخ التسجيل
    Jun 2008
    المشاركات
    54


    هل تكفى هذه الدالة للحماية من ثغرات xss










ضوابط المشاركة

  • لا تستطيع إضافة مواضيع جديدة
  • لا تستطيع الرد على المواضيع
  • لا تستطيع إرفاق ملفات
  • لا تستطيع تعديل مشاركاتك
  •  

أضف موقعك هنا| اخبار السيارات | حراج | شقق للايجار في الكويت | بيوت للبيع في الكويت | دليل الكويت العقاري | مقروء | شركة كشف تسربات المياه | شركة عزل اسطح بالرياض | عزل فوم بالرياض| عزل اسطح بالرياض | كشف تسربات المياة بالرياض | شركة عزل اسطح بالرياض