5

I have gone through this link. [How to fix "Improper Neutralization of CRLF Sequences in HTTP Headers ('HTTP Response Splitting')"

But it does not give me the solution.

My code is also giving the error "Improper Neutralization of CRLF Sequences in HTTP Headers ('HTTP Response Splitting') CWE ID 113".

My code snippet is::

Cookie newloginCookie = new Cookie("CMCLoginCookie", userName + ":" + password);
                                newloginCookie.setMaxAge(24 * 60 * 60 * 1000);
                                response.addCookie(newloginCookie);

In veracode scan the error is giving for the last line. Not sure what to do for it.

4

2 に答える 2

2

ESAPI を使用すると、最大 CWE の問題を修正できます。

基本的に、上記の問題は、正規表現または DefaultHTTPUtilities を使用して、ユーザー入力から \r\n 値を削除する必要があります。

于 2015-11-04T10:27:09.353 に答える
1

ユーザー名とパスワードを取得したら、"\r" と "\n" の文字をすべて削除してみてください。Apache StringUtils などを使用すると、次のようになります。

String safeUserName = StringUtils.replaceEach(userName, new String[] {"\n", "\r"}, new String[] {"", ""});
String safePassword = StringUtils.replaceEach(password, new String[] {"\n", "\r"}, new String[] {"", ""});

次に、安全な文字列を使用して Cookie を作成します。

于 2015-02-24T22:02:56.503 に答える