944,116 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 3036
  • Java RSS
Nov 2nd, 2004
0

filtering bad user input

Expand Post »
I am trying to set up a jsp page which takes input from any form and filters out user input which may pose a security risk. I am using the following function to try to do this:
Java Syntax (Toggle Plain Text)
  1.  
  2. <%!
  3. private String checkInput(String test){
  4. String bad_input = "";
  5. boolean someBadInput = false;
  6. char[] bad_characters = {'<','>','\'','\"','*','#','=','&','\\',';',':'};
  7. int number_of_bad_characters = 11;
  8. int i;
  9. for(i=0; i<number_of_bad_characters; i++){
  10. if(test.indexOf(bad_characters[i]) != -1){
  11. if(!someBadInput){
  12. bad_input += bad_characters[i];
  13. someBadInput = true;
  14. }else{
  15. if(i < (number_of_bad_characters-1)){
  16. bad_input += ", "+ bad_characters[i];
  17. }else{
  18. bad_input += ", and "+ bad_characters[i];
  19. }
  20. }
  21. }
  22. }
  23. if(someBadInput){
  24. return bad_input;
  25. }else{
  26. return "good";
  27. }
  28. }
  29. %>
I get a null pointer from the following line:
Java Syntax (Toggle Plain Text)
  1. if(test.indexOf(bad_characters[i]) != -1){
Been working at the computer for too long and going kinda bugeyed - so any other eyes that check this out are much appreciated!

Thanks in advance,
Dave.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Dave G. is offline Offline
7 posts
since Mar 2004
Nov 2nd, 2004
0

Re: filtering bad user input

Wow, this is embarassing - the form I was submitting to the page had a spelling mistake inthe name of a field - so the page was trying to "request.getParameter("non_existant_parameter");" and passing a null pointer into the function. Sometimes you just need some sleep and or do something else for awhile....

Thanks to everyone who looked at the code. Sorry for the inconvienance.

Dave.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Dave G. is offline Offline
7 posts
since Mar 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: help? trying to compare input with symbol.
Next Thread in Java Forum Timeline: Entering through mulitple Textfields





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC