From 1874e12a0343cc86935d5ce3b544b4b32359d703 Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Sun, 20 Mar 2011 11:50:28 +0000 Subject: [PATCH] In server_content_encoding(), mark the content as taboo for filtering if SDCH compression is used If SDCH was combined with a supported compression algorithm, we'd previously try to decompress it, when successful apply the enabled filters and ditch the Content-Encoding header even though the SDCH compression wasn't removed. Reported by zebul666 in #3225863. I get the impression that filtering SDCH-compressed content actually isn't guaranteed to cause problems as long as the client still gets a "Content-Encoding: sdch" header, so we should probably eventually allow users who want to risk it to do so by explicitly enforcing filtering. While at it, mark a bunch of other, partly-related, problems in server_content_encoding() that should be addressed someday. --- parsers.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/parsers.c b/parsers.c index e34d6250..940f45cd 100644 --- a/parsers.c +++ b/parsers.c @@ -1,4 +1,4 @@ -const char parsers_rcs[] = "$Id: parsers.c,v 1.217 2011/01/22 12:30:22 fabiankeil Exp $"; +const char parsers_rcs[] = "$Id: parsers.c,v 1.218 2011/02/14 16:11:34 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/parsers.c,v $ @@ -2127,6 +2127,12 @@ static jb_err server_transfer_coding(struct client_state *csp, char **header) * The second run is used to remove the Content-Encoding * header if the decompression was successful. * + * XXX: Doesn't properly deal with multiple or with + * unsupported but unknown encodings. + * Is case-sensitive but shouldn't be. + * The second run should be factored out into + * a different function. + * * Parameters : * 1 : csp = Current client state (buffers, headers, etc...) * 2 : header = On input, pointer to header to modify. @@ -2155,6 +2161,26 @@ static jb_err server_content_encoding(struct client_state *csp, char **header) log_error(LOG_LEVEL_HEADER, "Crunching: %s", *header); freez(*header); } + else if (strstr(*header, "sdch")) + { + /* + * Shared Dictionary Compression over HTTP isn't supported, + * filtering it anyway is pretty much guaranteed to mess up + * the encoding. + */ + csp->content_type |= CT_TABOO; + + /* + * Log a warning if the user expects the content to be filtered. + */ + if ((csp->rlist != NULL) && + (!list_is_empty(csp->action->multi[ACTION_MULTI_FILTER]))) + { + log_error(LOG_LEVEL_INFO, + "SDCH-compressed content detected, content filtering disabled. " + "Consider suppressing SDCH offers made by the client."); + } + } else if (strstr(*header, "gzip")) { /* Mark for gzip decompression */ @@ -2174,7 +2200,16 @@ static jb_err server_content_encoding(struct client_state *csp, char **header) csp->content_type |= CT_TABOO; } #else /* !defined(FEATURE_ZLIB) */ - if (strstr(*header, "gzip") || strstr(*header, "compress") || strstr(*header, "deflate")) + /* + * XXX: Using a black list here isn't the right approach. + * + * In case of SDCH, building with zlib support isn't + * going to help. + */ + if (strstr(*header, "gzip") || + strstr(*header, "compress") || + strstr(*header, "deflate") || + strstr(*header, "sdch")) { /* * Body is compressed, turn off pcrs and gif filtering. -- 2.39.2