Created
April 25, 2012 20:41
-
-
Save justinwiley/2493198 to your computer and use it in GitHub Desktop.
A truly terrible way to prevent SQL injection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//validation for entering query | |
var notAllowed = ['select','SELECT','*','SeLeCt','sElEcT','{','}','(',')']; | |
for(var i = 0; i < notAllowed.length; i++){ | |
if(document.frmSurvey.txtComments.value.indexOf(notAllowed[i]) != -1){ | |
alert('The word "' + notAllowed[i] + '" is not allowed'); | |
document.frmSurvey.txtComments.value = document.frmSurvey.txtComments.value.substr(0, document.frmSurvey.txtComments.value.indexOf(notAllowed[i])); | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
'select','SELECT','*','SeLeCt','sElEcT' ?
So… use SELECt ! :)
More seriously, the javascript does not prevent requests server side, it will only prevent the user to put parentheses or write "select"
This script is useless, and you would could use "strtolower" ...