Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

SEC-1790: URL spring-security-redirect parameters vulnerable to CRLF injection by default. #2014

spring-issuemaster opened this Issue Jul 25, 2011 · 3 comments


None yet
1 participant

David Mas (Migrated from SEC-1790) said:

AbstractAuthenticationTargetUrlRequestHandler#determineTargetUrl(HttpServletRequest, HttpServletResponse) calls URLDecoder.decode, and the result is directly feed to DefaultRedirectStrategy by default, which does not filter line feeds, injecting a custom header after "Location"

by_wvs HTTP/1.1

HTTP/1.1 302 Moved Temporarily
Date: Tue, 19 Jul 2011 15:28:57 GMT
Location: xxxxxxxxxxxxxxx
SomeCustomInjectedHeader: injected_by_wvs
Content-Length: 0
Connection: close
Content-Type: text/plain; charset=UTF-8

You need to restrict CR(0x13) and LF(0x10) from the user input or properly encode the output in order to prevent the injectino of custom HTTP headers.

David Mas said:

I have also made a fix by extending DefaultRedirectStrategy. It would be nice this redirectStrategy is injected instead of the default one.

public class CrlfFilteringRedirectStrategy extends DefaultRedirectStrategy {

 * @see org.springframework.security.web.DefaultRedirectStrategy#sendRedirect(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse, java.lang.String)
public void sendRedirect(final HttpServletRequest request,
        final HttpServletResponse response, final String url)
        throws IOException {
    String filteredUrl = url.replaceAll("\\n|\\r", "");
    super.sendRedirect(request, response, filteredUrl);


Luke Taylor said:

Thanks for the report.

I think this is probably best addressed in a standard response wrapper which is injected into the filter chain by the FilterChainProxy. This will cover all attempts to redirect to an invalid location rather than just those which use the default redirect strategy. In future we should also support pluggable request and response validation strategies (allowing, for example, the use of the ESAPI validator as an option) rather than attempting to provide a generic blacklist.

Also, please use the guidelines at http://www.springsource.com/security if reporting a vulnerability which may put existing users at risk.

Luke Taylor said:

The redirect location is now sanitized in a FirewalledResponse class which wraps the response. Default support for the redirect parameter in logout URLs has also been removed in 3.0.6. In 3.1 it already needs to be enabled explicitly.

@spring-issuemaster spring-issuemaster added this to the 3.1.0.RC3 milestone Feb 5, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment