Lukasz Lenart created WW-5852:
---------------------------------
Summary: REST plugin does not trim Accept header tokens, so "a, b"
never matches b and falls back to the default representation
Key: WW-5852
URL: https://issues.apache.org/jira/browse/WW-5852
Project: Struts 2
Issue Type: Bug
Components: Plugin - REST
Affects Versions: 7.4.0, 6.12.0
Reporter: Lukasz Lenart
{{DefaultContentTypeHandlerManager.getHandlerForResponse}} splits the
{{Accept}} header on {{,}} and looks each token up in {{handlersByContentType}}
as-is. {{findHandler}} trims a token only when it contains a {{;}} parameter
separator. A header written the way most HTTP clients write it, with a space
after each comma ({{application/xml, application/json}}), therefore produces
tokens with a leading space that match nothing, and the request falls back to
the handler for {{struts.rest.defaultExtension}}.
h2. Where
{{plugins/rest/src/main/java/org/apache/struts2/rest/DefaultContentTypeHandlerManager.java}},
the {{acceptHeader.split(",")}} loop in {{getHandlerForResponse}} and the
{{findHandler}} lookup below it. The code is the same on {{main}} and
{{support/struts-6-x-x}}.
h2. Effect
Content negotiation silently returns the default representation instead of the
one the client asked for whenever the client sends more than one media type
separated by comma and space. There is no error and no log entry. Which
serializer runs is not a security control and the fallback is the application's
own configured default, so this is a functional bug.
h2. Fix
Trim each token before the lookup (and keep the existing {{;}} handling for
parameters such as {{charset}}). Add a test to
{{DefaultContentTypeHandlerManagerTest}} with {{application/xml,
application/json}} and with a trailing space, asserting the JSON and XML
handlers are selected, next to the existing untrimmed cases.
h2. Source
Reported publicly on the Full Disclosure list, 2026-10-29:
https://seclists.org/fulldisclosure/2026/Nov/1
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)