You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CookieLocaleResolver may disturb error rendering when locale cookie has a malformed value [SPR-15182] #19748
This issue is on a similar theme to #19744 and #19745.
DispatcherServlet calls its LocaleResolver as part of an error dispatch. If a CookieLocaleResolver is configured and the locale cookie is malformed, this leads to an exception being thrown during error processing which disturbs error rendering.
A workaround is to override resolveLocaleContext(HttpServletRequest) and skip parsing the cookie's value when it's an error dispatch:
@Override
public LocaleContext resolveLocaleContext(HttpServletRequest request) {
if (request.getAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE) != null) {
return new TimeZoneAwareLocaleContext() {
@Override
public Locale getLocale() {
return (Locale) request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME);
}
@Override
public TimeZone getTimeZone() {
return (TimeZone) request.getAttribute(TIME_ZONE_REQUEST_ATTRIBUTE_NAME);
}
};
}
return super.resolveLocaleContext(request);
}
I guess we could also defensively try to parse the cookies, swallowing an IllegalArgumentException in case of an error dispatch. And when propagated, I'd like to turn the util-level IllegalArgumentException into something more meaningful at the dispatcher level.
We're swallowing parse exceptions in an error dispatch now, and otherwise turn them into an IllegalStateException containing the cookie name and value etc.
Activity
spring-projects-issues commentedon Jan 24, 2017
Juergen Hoeller commented
I guess we could also defensively try to parse the cookies, swallowing an
IllegalArgumentExceptionin case of an error dispatch. And when propagated, I'd like to turn the util-levelIllegalArgumentExceptioninto something more meaningful at the dispatcher level.spring-projects-issues commentedon Jan 24, 2017
Juergen Hoeller commented
We're swallowing parse exceptions in an error dispatch now, and otherwise turn them into an
IllegalStateExceptioncontaining the cookie name and value etc.