I need to handle the HTTP Response Splitting Issue for a ajax call through the XMLHTTPRequest/Response. I am using a filter for filtering the servlet request and response and have defined inner classes for the wrapper in which the methods are overridden to check for any presence of CR/LF characters. Now I need to do the same for the AJAX request. The filter is configured in the web.xml. so every request and response can be tracked. This implementation is done and working fine. And I need to have the same implementation for this AJAX request and response. But I am not been able to find any java API to implement the same. Can any one have any suggestion or tips for this issue. Any implementation example is welcome. Thanks a lot in advance.
preguntado el 28 de agosto de 12 a las 14:08
This code should help you. you need to have this in your
response = (HttpServletResponse)resp; StringWrapper responseWrapper = new StringWrapper(response); chain.doFilter(request, responseWrapper); String modifiedResponse = cleanUpBadChars(responseWrapper.toString()); PrintWriter out = response.getWriter(); out.write(modifiedResponse);
cleanUpBadChars --> this is a utility function to clean up all the bad chars or whatever characters you do not need.