Ticket #1356 (new enhancement)

Opened 12 months ago

Extend format string to support regular expression replacements

Reported by: jrabbit Owned by: jan
Priority: normal Milestone:
Component: mod_accesslog Version: 1.5.x-svn
Severity: normal Keywords:
Cc: Blocked By:
Need User Feedback: no Blocking:

Description

It would be useful if the format string syntax allowed regular expresssion search/replace to be applied to a value before it is logged - particularly with information received in the incoming request such as request headers or the query string. This would allow the user to ensure only syntactically valid data or a subset of the data is logged when reading from arbitrary fields.

One purpose I have in mind is to log the client IP address from an X-Forwarded-For, header. I'm not interested in an additional proxy addresses that could appear in the header, and don't want to allow clients to send invalid data (e.g. blackberry's proxy sends 'unknown'). I'm sure there are many more uses though.

A potential syntax is to use characters such as @ (or something else that has no meaning in regular expressions when unescaped) as a delimiter and place the expression and replacement with back-references after the format string character - in the case of request headers "i".

E.g. To extract the first IP address from an X-Forwarded-For header and log it rather than the whole header (regex is simplifed for clarity):

%{X-Forwarded-For}i@^([0-9\.]+)@\1@

You could also allow the usual regular expression control characters for case-sensitivity/line end matching etc. after the 3rd delimiter.

Attachments

Add/Change #1356 (Extend format string to support regular expression replacements)

Author



Change Properties
<Author field>
Action
as new
 
Note: See TracTickets for help on using tickets.