How to HTTP response splitting problem..??

Help me this problem:
How to HTTP response splitting problem: solution and example..i'm using java, Struts framework, MySQL
Who is Participating?
HTTP resposne splitting attack is the injection of %0d%0a into a string that later gets passed into HTTP headers. The attacker can then spoof the page output, set cookies, redirect the user somewhere else, etc.

Here is an article with a pretty good description of this problem in PHP, that could be adapted to Java:

You are only vulnerable to this problem if you somehow take user input that later gets inserted into the headers. For example, websites often have a Next= url passed in via the query string. You'd later use a client-side redirect to send the user to the location specified by Next=. In this case, you want to make sure to filter out any cases of ascii 10 and ascii 13 characters from the URL.

If the URL hasn't been encoded (i.e. it looks like "a b"), you would use:
url.replace('\n', ' ');
url.replace('\r', ' ');

If the URL has been encoded (i.e. it looks like "a%20b"), you would use

url.replace("/%0a/ig", "");
url.replace("/%0d/ig", "");

Hope that helps.
So just what _is_ your question?  What is the "HTTP response splitting problem" you are referring to?
ncsvietnamAuthor Commented:
but i can't understand code php. If have code example login about java.. is better.
Sure, the example above I gave in Java (the url.replace one).

Or, you could simply use Javascript code to redirect the user instead of sending a Location header.  That way you won't be vulnerable to HTTP splitting since you're not sending any custom headers.

<script language="JavaScript">window.location.href="http://newurl"></script>
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.