BACKGROUND
- Application based on : Spring MVC
- Java8
- Mostly filter requests out by using interceptors.
PROBLEM
I tested my application and every user inputs are vulnerable to HTML/Script injection attacks. I'm using a certain methods to prevent them on my client side, but if I manipulated the form values before they're posted up to the server, the injections were successfully made and corrupted my website. So what's my top priority becomes having the same detection methods in server side as well. I should have done this eariler, but there's some reason anyway...
WHAT I'M THINKING OF
is to check every parameters in an interceptor. The interceptor will validate all the parameters wherever the page provides user inputs and forms to submit.
SOMETHING LIKE THIS
public class ParameterFilteringInterceptor {
// 1. get all request parameters..
// 2. check every values..
// 3. if illegal characters exist in one of them,
// converting or escaping them will start and change them to acceptable values.
// Getting and setting on request parameters is going to occur frequently.
// If good to go, return true
// Or return false with a proper error message.
}
SETUP LIKE THIS
<interceptor>
<mapping path="/addform" />
<mapping path="/editform" />
<mapping path="/post" />
<mapping path="/newarticle" />
<mapping path="/newcomment" />
.
.
.
<!-- Depend on the volume of a web application,
these mapping paths could be sooooooooo many. -->
<beans:bean class="com.company.web.interceptor.AuthenticatingInterceptor"></beans:bean>
</interceptor>
So.. what I want to ask is.. "IS IT A GOOD IDEA TO DO SOMETHING LIKE ABOVE?"