Benim formları kesmek olabilir

4 Cevap php

Ancak ben XSS karşı önleyici bir ilk satırı olarak bazı JavaScript yazdı ki ben Bugüne geri almak niyetinde, dün bir soru yayınlanmıştır. Benim canlı sunucuda bu test ederken javascript php bölümünü yakalar Ancak ben bazı geçersiz giriş yakalamak. Benim formu yazıyı kullanan ve php (i yazmıştın değil) benim form öğeleri değildir. Bu form eylemi falan toplayıp olabilir mi? Ben, herhangi bir fikir baffeled ediyorum

İşte benim kod, o Gönder düğmesine tetiklenir.

    function validateForBadNess(){

var theShit = new Array("*","^", "$", "(",")","{", "}","[", "]","\\", "|", "'","/","?",",","=",">","gt","lt", "<","script","`","´","php");
var tagName = new Array();

tagName[0] = "input";
tagName[1] = "select";
tagName[2] = "textbox";
tagName[3] = "textarea";

for (ms=0;ms<tagName.length;ms++){

 // loop through  the elements of the form
 var formItems = document.getElementsByTagName(tagName[ms]);

  for (var xs=0;xs<formItems.length;xs++){

   var thisString = formItems[xs].value;

   // loop through bad array
   for (zs in theShit){

    //alert(thisString + " " + thisString.indexOf(theShit[zs]))
    if(thisString.indexOf(theShit[zs]) >= 0){

    alert("Sorry but the following character: " + theShit[zs] + " is not permitted. Please omit it from your input.\nIf this is part of your password please contact us to heave your password reset.")
    return false;

    }

     }



  // loop for formitems 
  }

 // tagName toop
 }
// original condition
}

4 Cevap

Yapmanız saldırılara karşı koruma açısından tamamen gereksiz ve işe yaramaz. Herhangi bir JavaScript tabanlı "koruma" saniye içinde atlatılabilir olacaktır, ve meşru kullanıcılar örneğin $ işaretini kullanmak mümkün mutlu olmayacaktır. Her zaman herhangi bir gelen veri can tahrif edilmiş olduğunu varsayalım.

Sen dikkatli olmak gerektiğinde sunucu tarafında outputting veri. Gelen herhangi bir metin veri htmlspecialchars() kullanın. Gelen HTML varsa, "temizlenmesi" gerekiyor Sarfraz tarafından önerilen HTML temizleyici kullanabilirsiniz.

İlgili SO okuma:

Neden yerine ünlü HTML Purifier kullanmak değil mi?

HTML Purifier is a standards-compliant HTML filter library written in PHP. HTML Purifier will not only remove all malicious code (better known as XSS) with a thoroughly audited,
secure yet permissive whitelist, it will also make sure your documents are standards compliant, something only achievable with a comprehensive knowledge of W3C's specifications.
Tired of using BBCode due to the current landscape of deficient or
insecure HTML filters? Have a
WYSIWYG editor but never been able to use it? Looking for high-quality, standards-compliant, open-source components for that application you're building? HTML Purifier is for you!

Sen sunucuda giriş doğrulama yapmak zorunda. Tamamen tarayıcı ve javascript atlayarak sırasında bir saldırgan, sadece isteği gönderebilirsiniz. Güvenli olmak için, sunucu tarafında yapmak zorunda girişini süzmek.

Bunu yapmak için iyi bir yol php en filter extension kullanmaktır.

Sadece yeniden girişini görüntülemek kullanmak istiyorsanız htmlspecialchars().