Skip to content

fall back to utf-8 for invalid content-type charset#3427

Merged
velo merged 1 commit into
OpenFeign:masterfrom
alhudz:content-type-charset-fallback
Jun 19, 2026
Merged

fall back to utf-8 for invalid content-type charset#3427
velo merged 1 commit into
OpenFeign:masterfrom
alhudz:content-type-charset-fallback

Conversation

@alhudz

@alhudz alhudz commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Repro: a server response with Content-Type: text/plain; charset=made-up-99 (or an illegal name such as charset=@) reaches Response.charset(), which is called by every JSON/text decoder (jackson, json, fastjson2, jackson-jr, jackson3) through response.body().asReader(response.charset()).
Expected: charset() returns its documented UTF-8 default.
Actual: UnsupportedCharsetException / IllegalCharsetNameException escapes the decoder on an otherwise valid response.
Cause: Response.charset() hands the charset token parsed out of the header straight to Charset.forName with no guard. feign-form's FormEncoder.getCharset has the same unguarded call on the request Content-Type. FeignException.getResponseCharset already guards the identical parse.
Fix: catch IllegalCharsetNameException/UnsupportedCharsetException in both helpers and fall back to UTF-8. Regression tests cover both an illegal and an unsupported charset name.

Response.charset() and feign-form's FormEncoder.getCharset() passed the parsed charset token straight to Charset.forName, so an unsupported or illegal name from a Content-Type header threw instead of using the documented UTF-8 default. Catch the charset exceptions in both and fall back to UTF-8, as FeignException.getResponseCharset already does.

@velo velo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a focused fix: Response.charset() and FormEncoder now both fall back to UTF-8 for illegal or unsupported charset tokens, and the new tests cover the two failure paths in core and feign-form. I do not see a compatibility or security issue here.

@velo velo merged commit 247fb46 into OpenFeign:master Jun 19, 2026
3 checks passed
@velo velo mentioned this pull request Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants