Jump to content






Photo - - - - -

Preventing Xss In Jsp



Havent been on in a while, figured i was over due. In this article i am going to tell you a really simple way to prevent basic xss injections on your jsp websites. Here we go:

After you have created a basic form for your main page, generally it will either be sent to a servlet, or to another jsp page. The preoblem is by default without using a bean, or any other method of validation the pages are wide open to xss. There is a single line of code that can be used for sanitation. First grab the post data as usual
String name = request.getParameter("username").toString();
Now add this line to your function:
name = name.replaceAll("(?i)<script.*?>.*?</script.*?>", " Xss Is Not Allowed");
Voila, script tags are not allowed, you can use this string for all other injection types as well like so
name = name.replaceAll("(?i)<script.*?>.*?</script.*?>", " Xss Is Not Allowed");
name = name.replaceAll("(?i)<iframe.*?>.*?</iframe.*?>", " Iframes Are Not Allowed");
name = name.replaceAll("(?i)<anything else you can think of.*?>.*?</anything else you can think of.*?>", " Stuff Is Not Allowed");



February 2012

M T W T F S S
  12345
6789 10 1112
13141516171819
20212223242526
272829    

Recent Entries

Recent Comments

Random Album Image

social_engineering_a_final.jpg

Tags

    Search My Blog

    Categories

    Latest Visitors

    Twitter

    Digg