Skip to content

Consistent URI/body decoding #1182

New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
snicoll opened this issue Jun 27, 2014 · 9 comments
Closed

Consistent URI/body decoding #1182

snicoll opened this issue Jun 27, 2014 · 9 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@snicoll
Copy link
Member

snicoll commented Jun 27, 2014

Spring MVC defaults to ISO-8859-1 for historical reason and it's not easy to change that value. The decoding of the URI happens at two stages: the container does it (see #542 for what we did for Tomcat since Jetty already defaults to UTF-8) and Spring MVC does it, based on the request encoding or the default if it's not set.

What people usually do is configure the org.springframework.web.filter.CharacterEncodingFilter with the same encoding as the one defined on the container. That way the body and the URI are decoded in a consistent manner.

Long story short: #542 does not fully provide a UTF-8 decoding by default. It would be nice to try to bring that property back at a generic level if we happen to be able to configure jetty: that way we can customize the uriEncoding with the use of a single property.

@snicoll snicoll changed the title Consistent URI decoding Consistent URI/body decoding Jun 30, 2014
@markfisher markfisher added this to the 1.1.4 milestone Jul 3, 2014
@markfisher markfisher reopened this Jul 3, 2014
@philwebb philwebb removed this from the 1.1.4 milestone Jul 3, 2014
@making
Copy link
Member

making commented Sep 18, 2014

Japanese Spring Boot user always configure CharacterEncodingFilter like following

    @Bean
    @Order(Ordered.HIGHEST_PRECEDENCE)
    CharacterEncodingFilter characterEncodingFilter() {
        CharacterEncodingFilter filter = new CharacterEncodingFilter();
        filter.setEncoding("UTF-8");
        filter.setForceEncoding(true);
        return filter;
    }

to handle Japanese in POST request.

Autocofigured CharacterEncodingFilter would be very helpful.

@philwebb philwebb added this to the 1.2.0.M2 milestone Sep 18, 2014
@snicoll
Copy link
Member Author

snicoll commented Sep 19, 2014

Not on a computer right now but a similar issue already exists FYI.

@snicoll
Copy link
Member Author

snicoll commented Nov 4, 2014

Here is another related issue in Spring MVC: SPR-11925

@markfisher
Copy link

I was just going to point out that HTTP specifies ISO-8859-1 as the default charset (see p. 26 here: http://www.w3.org/Protocols/rfc2068/rfc2068.txt), but I noticed that is also mentioned in the SPR-11925 issue that you just referenced.

@rstoyanchev
Copy link
Contributor

Plenty of other such tickets. One just commented on yesterday https://jira.spring.io/browse/SPR-11035.

@rstoyanchev
Copy link
Contributor

RFC 2068 is ancient, made obsolete by 2616 and that's also now "dead". RFC 7231 in Appendix B says default charset ISO-8859-1 has been removed.

I think UTF-8 is a reasonable default these days. Boot should either default to it and/or ideally make it easy to switch.

@snicoll
Copy link
Member Author

snicoll commented Nov 4, 2014

Rossen, let's discuss how best we can achieve that because that's something I want to do for a very long time. Thanks!

@making
Copy link
Member

making commented Nov 4, 2014

I'd like to point out one more thing regarding this topic.

With Spring Security filter, I have had another encoding problem.
Even though I configured CharacterEncodingFilter, it didn't work well.

Strangely it depends on the environment it runs.
For example,
It occurred in AWS Elastic Beanstalk c3.large but didn't in t1.micro and m3.large.
Actually on my local macbook, it works well even though Spring Security is configured.

At that time, I have fixed with the following configuration in extended WebSecurityConfigurerAdapter class:

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // omitted
        CharacterEncodingFilter filter = new CharacterEncodingFilter();
        filter.setEncoding("UTF-8");
        filter.setForceEncoding(true);
        http.addFilterBefore(filter, CsrfFilter.class);
    }

I don't investigate so much yet, but I wonder it is related to the execution order of HIGHEST_PRECEDENCE filters.

I'd appreciate it if Spring Boot encapsulates this :)

@megascus
Copy link

megascus commented Nov 5, 2014

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

6 participants