Skip to content

Instantly share code, notes, and snippets.

@justinwiley
Created April 25, 2012 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinwiley/2493198 to your computer and use it in GitHub Desktop.
Save justinwiley/2493198 to your computer and use it in GitHub Desktop.
A truly terrible way to prevent SQL injection
//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;
}
}
Copy link

ghost commented Aug 13, 2012

'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" ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment