I am fixing some old defects and as part of one defect, I need to make sure that some requests are being only POST to the JSP page instead of a GET request. The application have a form which submits data to another JSP page (I know its wrong and against MVC but too late to fix it), since it is a JSP page, so we can POST the request or else we can GET the request. In case of a malicious user, can read the form and send the request as a GET from the browser like http://host:80/somejsp.jsp?param=value¶m=value etc. In that case, it becomes a violation. I need to make sure that such GET requests are not processed. One way to do is to perform the below steps in the jsp page –
if (request.getMethod().equals("GET")) {
// reroute the user as it is not a valid req
}
Is there any other way to do it?
Two solutions:
Add a
<security-constraint>with an empty<auth-constraint>on an<url-pattern>of*.jspand<http-method>ofGETwhich will blockGETrequests on JSP files to everyone (as suggested by McDowell):Create a
Filterwhich listens on an<url-pattern>of*.jspand does basically the following in thedoFilter()method.No need to copypaste the same over all JSP pages which would only be prone to
IllegalStateException: response already committederrors.