[squid-users] Hacking X-Forwarded-For

From: David Neudorfer <davidneudorfer@dont-contact.us>
Date: Tue, 16 May 2006 14:30:29 -0700

I want to customize the X-Forwarded-For header. Building Squid from
the source files go to line 962 in /src/http.c you will see

  /* append X-Forwarded-For */
strFwd = httpHeaderGetList(hdr_in, HDR_X_FORWARDED_FOR);
strListAdd(&strFwd,
(((orig_request->client_addr.s_addr != no_addr.s_addr) &&
opt_forwarded_for) ?
inet_ntoa(orig_request->client_addr) : "unknown"), ',');
httpHeaderPutStr(hdr_out, HDR_X_FORWARDED_FOR, strBuf(strFwd));
stringClean(&strFwd);

pay close attention to

  inet_ntoa(orig_request->client_addr) : "unknown"), ',');

You can change the "unknown" value to whatever you like and it will
send that value with the x-forwarded-for header.

After changing the file, ./configure, make, and make install. You’ll
need to edit your squid.conf and turn the “forwarded_for” value off
in order for the hack to function.

Now that we know we can send custom data in the x-forwarded-for
header, instead of arbitrary data I want to send the subdomain from
which the client is connecting to.

Example: User 123456 is proxied through 123456.mydomain.com. Like
apache I want to set squid to pickup the fact that this user is
connecting to 123456.mydomain.com and not 654321.mydomain.com and
then forward this data in the header. Anyone have any ideas how this
might be done?

David Neudorfer
Received on Tue May 16 2006 - 15:30:42 MDT

This archive was generated by hypermail pre-2.1.9 : Thu Jun 01 2006 - 12:00:02 MDT