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
ncsvietnamAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jhanceCommented:
So just what _is_ your question?  What is the "HTTP response splitting problem" you are referring to?
enwhyseeCommented:
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:
http://www.phpfreaks.com/tutorials/132/0.php

Generally:
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ncsvietnamAuthor Commented:
but i can't understand code php. If have code example login about java.. is better.
enwhyseeCommented:
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>
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Security

From novice to tech pro — start learning today.