Bug 60781 - Access Log Valve does not escape the same as mod_log_config
Summary: Access Log Valve does not escape the same as mod_log_config
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 8
Classification: Unclassified
Component: Connectors (show other bugs)
Version: 8.5.11
Hardware: PC All
: P2 normal (vote)
Target Milestone: ----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-27 17:54 UTC by james
Modified: 2020-12-07 17:20 UTC (History)
0 users



Attachments
Escape characters like httpd (13.84 KB, patch)
2017-02-28 19:41 UTC, Felix Schumacher
Details | Diff
Escape characters like httpd (14.14 KB, patch)
2017-02-28 20:00 UTC, Felix Schumacher
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description james 2017-02-27 17:54:22 UTC
It is my understanding that the log format is supposed to match apache2.
However, escaping is not the same.

As a concrete example, if there is a " in the User-Agent and you use the combined format, apache2 gives

    127.0.0.1 - - [27/Feb/2017:14:31:48 +0000] "GET / HTTP/1.1" 401 17277 "-" "Agent \"Test\""

While Tomcat gives

    127.0.0.1 - - [27/Feb/2017:14:31:48 +0000] "GET / HTTP/1.1" 401 17277 "-" "Agent "Test""

The latter cannot be parsed safely.
Comment 1 Felix Schumacher 2017-02-28 19:41:49 UTC
Created attachment 34787 [details]
Escape characters like httpd

I am not sure about the correct handling of chars with values out of the ASCII range. I believe they are double encoded now. 

But quotes and alike should be escaped correctly.

My first thought was to combine this escaping with ExtendedAccessLogValve, but it seems, that the quotes are explicitly coded as "" instead of \".
Comment 2 Felix Schumacher 2017-02-28 20:00:47 UTC
Created attachment 34788 [details]
Escape characters like httpd

Use ISO-8859-1 to decode String into bytes.
Comment 3 Mark Thomas 2020-12-04 19:31:55 UTC
Using Felix's patch as a starting point, I've put together this PR:
https://github.com/apache/tomcat/pull/384
Comment 4 Mark Thomas 2020-12-07 17:20:14 UTC
Fixed in:
- 10.0.x for 10.0.1 onwards
- 9.0.x for 9.0.42 onwards
- 8.5.x for 8.5.62 onwards