You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Endre Stølsvik <En...@Stolsvik.com> on 2006/01/09 23:06:39 UTC

RequestDumperValve screws UTF-8 parameter parsing

Enabling the RequestDumperValve in both 5.5.12 and 5.0.16 (!) messes 
up the parsing of other-than-ISO-8859-1 incoming parameters.

After using a rather huge bunch of hours, this came down as the result: 
when this "debug valve" is turned on, it seems to default to ISO-8859-1 
when it parses and log-outputs the incoming parameters, thus also 
implicitly setting the entire Request-object to this enc, so any subsequnt 
setting to UTF-8 doesn't matter at all. At least this is true for POST 
paramters.

For GET parameters, the situation is a little different. Here an explicit 
setting of URIEncoding to UTF-8 seems to work as it should, while 
useBodyEncodingForURI doesn't - it picks up the wrong already implicitly 
set encoding. (For 5.0.16 I can't seem to get the latter version to work, 
and have to use the explicit setting.)

Sorry if my analysis doesn't hold water, but at least the bug seems to be 
very consistent.

Regards,
Endre.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: RequestDumperValve screws UTF-8 parameter parsing

Posted by Tim Funk <fu...@joedog.org>.
The first thing a servlet (or filter) should do is set the encoding before 
touching the request parameters. Its not intended to be called somewhere late 
in the processing lifecycle. Since a Valve executes before any javax.servlet 
code - all bets are off (for the request encoding) based on the warning 
messages in the Valve.

For GET requests, reparsing might work when a new encoding is requested. But 
for POST requests - doing so would require saving the entire POST body 
somewhere. This can easily cause a memory based DOS attack.

-Tim

Oded Arbel wrote:

> Then why is it at all possible to set the encoding ? it should not be 
> needed and there for should not be possible. The fact that such a call 
> exists suggests to me that calling it repeatedly would have some effect 
> (granted - it will slow the performance, but that is as expected) - I 
> would prefer the request implementation reparse everything when I 
> supply new character set information - taking it sweet time to do it 
> (I'm probably only going to do this once per request) - rather then 
> just ignore me.
> 
> The fact is, if you get at the request too late in the process, where 
> the character set has already been set (wrongly), theres nothing you 
> can do to rescue the data, and many times I've had that problem.
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: RequestDumperValve screws UTF-8 parameter parsing

Posted by Oded Arbel <od...@geek.co.il>.
On Tuesday, 10 בJanuary 2006 11:16, Endre Stølsvik wrote:
> On Tue, 10 Jan 2006, Oded Arbel wrote:
> | AFAIK, the catalina implementation of HttpServletRequest does not
> | allow to set the character set more then once, even though it
> | doesn't do any pre-processing of the input.
> |
> | Maybe that should be fixed instead ?
>
> I think that when you "touch" the servlet request object's parameters
> at all (or even anything else it might seem like), it parses them all
> at once using the then-set (or default) encoding and caches them.
>
> This is most probably according to spec.
>
> I really don't find this that problematic ... the browser
> sends all its parameters using one encoding, and it would be a
> strange setting if it was really needed to change the encoding
> "midways" in your processing.

Then why is it at all possible to set the encoding ? it should not be 
needed and there for should not be possible. The fact that such a call 
exists suggests to me that calling it repeatedly would have some effect 
(granted - it will slow the performance, but that is as expected) - I 
would prefer the request implementation reparse everything when I 
supply new character set information - taking it sweet time to do it 
(I'm probably only going to do this once per request) - rather then 
just ignore me.

The fact is, if you get at the request too late in the process, where 
the character set has already been set (wrongly), theres nothing you 
can do to rescue the data, and many times I've had that problem.

-- 
Oded

::..
-- Members of an avian species of identical plumage congregate.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: RequestDumperValve screws UTF-8 parameter parsing

Posted by Jess Holle <je...@ptc.com>.
Endre Stølsvik wrote:

>On Tue, 10 Jan 2006, Oded Arbel wrote:
>
>| On Tuesday, 10 ÿÿJanuary 2006 00:06, Endre Stølsvik wrote:
>| > Enabling the RequestDumperValve in both 5.5.12 and 5.0.16 (!) messes
>| > up the parsing of other-than-ISO-8859-1 incoming parameters.
>| >
>| > After using a rather huge bunch of hours, this came down as the
>| > result: when this "debug valve" is turned on, it seems to default to
>| > ISO-8859-1 when it parses and log-outputs the incoming parameters,
>| > thus also implicitly setting the entire Request-object to this enc,
>| > so any subsequnt setting to UTF-8 doesn't matter at all. At least
>| > this is true for POST paramters.
>| 
>| AFAIK, the catalina implementation of HttpServletRequest does not allow 
>| to set the character set more then once, even though it doesn't do any 
>| pre-processing of the input.
>| 
>| Maybe that should be fixed instead ?
>
>I think that when you "touch" the servlet request object's parameters at 
>all (or even anything else it might seem like), it parses them all at once 
>using the then-set (or default) encoding and caches them.
>
>This is most probably according to spec.
>  
>
This is most definitely according to the spec.

Then again, valves are below the level of the spec and could do things 
differently.  The  point is that this would be difficult to do 
efficiently at request start and so tradeoffs were clearly made.  This 
may not have been documented right at first (I know I got burned once), 
but the issue has always clearly been there.  I'd suggest living with it 
or writing your own filter.  Doing such output at request end works and 
while I don't think such a filter can provide everything a valve can it 
does allow an awful lot of information to be gathered.

--
Jess Holle

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: RequestDumperValve screws UTF-8 parameter parsing

Posted by Endre Stølsvik <En...@Stolsvik.com>.
On Tue, 10 Jan 2006, Oded Arbel wrote:

| On Tuesday, 10 ��January 2006 00:06, Endre St�lsvik wrote:
| > Enabling the RequestDumperValve in both 5.5.12 and 5.0.16 (!) messes
| > up the parsing of other-than-ISO-8859-1 incoming parameters.
| >
| > After using a rather huge bunch of hours, this came down as the
| > result: when this "debug valve" is turned on, it seems to default to
| > ISO-8859-1 when it parses and log-outputs the incoming parameters,
| > thus also implicitly setting the entire Request-object to this enc,
| > so any subsequnt setting to UTF-8 doesn't matter at all. At least
| > this is true for POST paramters.
| 
| AFAIK, the catalina implementation of HttpServletRequest does not allow 
| to set the character set more then once, even though it doesn't do any 
| pre-processing of the input.
| 
| Maybe that should be fixed instead ?

I think that when you "touch" the servlet request object's parameters at 
all (or even anything else it might seem like), it parses them all at once 
using the then-set (or default) encoding and caches them.

This is most probably according to spec.

I really don't find this that problematic, as it also ensures that you 
code in the most efficient way: Letting you set the encoding (differently) 
multiple times would definately ensure a slower processing, and would also 
most probably simply be a bug: the browser sends all its parameters using 
one encoding, and it would be a strange setting if it was really needed to 
change the encoding "midways" in your processing.

I feel the problem here is a) i18n ignorance, b) bad coding logic, and c) 
bad documentation/commenting of a debugging feature.

Regards,
Endre.

Re: RequestDumperValve screws UTF-8 parameter parsing

Posted by Oded Arbel <od...@geek.co.il>.
On Tuesday, 10 בJanuary 2006 00:06, Endre Stølsvik wrote:
> Enabling the RequestDumperValve in both 5.5.12 and 5.0.16 (!) messes
> up the parsing of other-than-ISO-8859-1 incoming parameters.
>
> After using a rather huge bunch of hours, this came down as the
> result: when this "debug valve" is turned on, it seems to default to
> ISO-8859-1 when it parses and log-outputs the incoming parameters,
> thus also implicitly setting the entire Request-object to this enc,
> so any subsequnt setting to UTF-8 doesn't matter at all. At least
> this is true for POST paramters.

AFAIK, the catalina implementation of HttpServletRequest does not allow 
to set the character set more then once, even though it doesn't do any 
pre-processing of the input.

Maybe that should be fixed instead ?

-- 
Oded

::..
Democracy is also a form of worship.  It is the worship of Jackals by 
Jackasses.
	-- Henry Louis Mencken

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: RequestDumperValve screws UTF-8 parameter parsing

Posted by Jess Holle <je...@ptc.com>.
I've produced my own servlet filter to get around this -- which does not 
dump request parameters until *after* the request has completed.

With almost no additional effort you can then add request elapsed time, 
etc, etc, to this.

Mark Thomas wrote:

>Endre Stølsvik wrote:
>  
>
>>Enabling the RequestDumperValve in both 5.5.12 and 5.0.16 (!) messes up
>>the parsing of other-than-ISO-8859-1 incoming parameters.
>>
>>After using a rather huge bunch of hours, this came down as the result:
>>when this "debug valve" is turned on, it seems to default to ISO-8859-1
>>when it parses and log-outputs the incoming parameters, thus also
>>implicitly setting the entire Request-object to this enc, so any
>>subsequnt setting to UTF-8 doesn't matter at all. At least this is true
>>for POST paramters.
>>
>>For GET parameters, the situation is a little different. Here an
>>explicit setting of URIEncoding to UTF-8 seems to work as it should,
>>while useBodyEncodingForURI doesn't - it picks up the wrong already
>>implicitly set encoding. (For 5.0.16 I can't seem to get the latter
>>version to work, and have to use the explicit setting.)
>>
>>Sorry if my analysis doesn't hold water, but at least the bug seems to
>>be very consistent.
>>
>>Regards,
>>Endre.
>>    
>>
>
>Which is why the following text appears in the docs for this valve:
>
><doc-quote>
>WARNING: Using this valve has side-effects. The output from this valve
>includes any parameters included with the request. The parameters will
>be decoded using the default platform encoding. Any subsequent calls
>to request.setCharacterEncoding() within the web application will have
>no effect.
></doc-quote>
>
>Mark
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>For additional commands, e-mail: users-help@tomcat.apache.org
>  
>

Re: RequestDumperValve screws UTF-8 parameter parsing

Posted by Endre Stølsvik <En...@Stolsvik.com>.
On Mon, 9 Jan 2006, Mark Thomas wrote:

| Endre St�lsvik wrote:
| > Enabling the RequestDumperValve in both 5.5.12 and 5.0.16 (!) messes up
| > the parsing of other-than-ISO-8859-1 incoming parameters.
| > 
| > After using a rather huge bunch of hours, this came down as the result:
| > when this "debug valve" is turned on, it seems to default to ISO-8859-1
| > when it parses and log-outputs the incoming parameters, thus also
| > implicitly setting the entire Request-object to this enc, so any
| > subsequnt setting to UTF-8 doesn't matter at all. At least this is true
| > for POST paramters.
| > 
| > For GET parameters, the situation is a little different. Here an
| > explicit setting of URIEncoding to UTF-8 seems to work as it should,
| > while useBodyEncodingForURI doesn't - it picks up the wrong already
| > implicitly set encoding. (For 5.0.16 I can't seem to get the latter
| > version to work, and have to use the explicit setting.)
| > 
| > Sorry if my analysis doesn't hold water, but at least the bug seems to
| > be very consistent.
| > 
| > Regards,
| > Endre.
| 
| Which is why the following text appears in the docs for this valve:

When was this added? See, I have a hunch that this comment wasn't there in 
the beginning.

Why isn't this slightly important point put in a clearly visible place 
within the server.xml file then?! Or the code just fixed, or rather just 
deleted off of the face of the earth until some code who haven't got his 
head totally up a ASCII-speaking place makes a usable version of it?

Tomcat 5.5.12's server.xml:

      <!-- The request dumper valve dumps useful debugging information about
           the request headers and cookies that were received, and the response
           headers and cookies that were sent, for all requests received by
           this instance of Tomcat.  If you care only about requests to a
           particular virtual host, or a particular application, nest this
           element inside the corresponding <Host> or <Context> entry instead.

           For a similar mechanism that is portable to all Servlet 2.4
           containers, check out the "RequestDumperFilter" Filter in the
           example application (the source for this filter may be found in
           "$CATALINA_HOME/webapps/examples/WEB-INF/classes/filters").

           Request dumping is disabled by default.  Uncomment the following
           element to enable it. -->
      <!--
      <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
      -->

Putting some high risk debugging feature within the default example 
server.xml file as "yeah, this is fucking cool, just uncomment this to 
debug your problems" without in the same breath pointing out that this 
will increase the exact problems you're trying to fix, is rather 
provocative after using 7 hours of debugging time on a I18N problem where 
my bleedin' parameters including something as simple as my three extra 
scandinavian characters "���" won't get through correctly.

Really, how can a "request dumper feature" that cannot handle any other 
charsets than the default Locale's the user running the JVM has, still be 
present in the default example config of the powerful and one-would-assume 
better-than-this Tomcat??

Anyways, thanks for answering, Thomas. If you have commit access (or any 
other reading this), then maybe you'd care to shove in a line at the top 
of the quoted comment, AND the bottom within the comment-out part of the 
definition, along the lines of:

"EXTREME WARNING / ERROR: Enabling this will most definately mess up all 
your parameter handling unless you live in USofA or England (and won't 
test for I18N anyways), or if mercury's third moon happens to be aligned 
with mars."

(and/or simply delete the damn class)

.. then maybe the next poor bastard hitting some I18N problems won't get 
caught using a debugging feature that will _ensure_ that his problems 
won't _ever_ go away.

Kind regards,
Endre.

Re: RequestDumperValve screws UTF-8 parameter parsing

Posted by Mark Thomas <ma...@apache.org>.
Endre Stølsvik wrote:
> Enabling the RequestDumperValve in both 5.5.12 and 5.0.16 (!) messes up
> the parsing of other-than-ISO-8859-1 incoming parameters.
> 
> After using a rather huge bunch of hours, this came down as the result:
> when this "debug valve" is turned on, it seems to default to ISO-8859-1
> when it parses and log-outputs the incoming parameters, thus also
> implicitly setting the entire Request-object to this enc, so any
> subsequnt setting to UTF-8 doesn't matter at all. At least this is true
> for POST paramters.
> 
> For GET parameters, the situation is a little different. Here an
> explicit setting of URIEncoding to UTF-8 seems to work as it should,
> while useBodyEncodingForURI doesn't - it picks up the wrong already
> implicitly set encoding. (For 5.0.16 I can't seem to get the latter
> version to work, and have to use the explicit setting.)
> 
> Sorry if my analysis doesn't hold water, but at least the bug seems to
> be very consistent.
> 
> Regards,
> Endre.

Which is why the following text appears in the docs for this valve:

<doc-quote>
WARNING: Using this valve has side-effects. The output from this valve
includes any parameters included with the request. The parameters will
be decoded using the default platform encoding. Any subsequent calls
to request.setCharacterEncoding() within the web application will have
no effect.
</doc-quote>

Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org