-const char filters_rcs[] = "$Id: filters.c,v 1.141 2011/03/08 18:32:11 fabiankeil Exp $";
+const char filters_rcs[] = "$Id: filters.c,v 1.147 2011/10/30 16:15:43 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/filters.c,v $
}
if (csp->action->flags & ACTION_REDIRECT)
{
- log_error(LOG_LEVEL_ERROR, "redirect{} overruled by block.");
+ log_error(LOG_LEVEL_ERROR, "redirect{} overruled by block.");
}
/*
* Else, prepare a response
if(csp->action->flags & ACTION_HANDLE_AS_EMPTY_DOCUMENT)
{
/*
- * Send empty document.
+ * Send empty document.
*/
new_content_type = csp->action->string[ACTION_STRING_CONTENT_TYPE];
{
jb_err err;
struct map * exports;
- char *p;
-
- /*
- * Workaround for stupid Netscape bug which prevents
- * pages from being displayed if loading a referenced
- * JavaScript or style sheet fails. So make it appear
- * as if it succeeded.
- */
- if ( NULL != (p = get_header_value(csp->headers, "User-Agent:"))
- && !strncmpic(p, "mozilla", 7) /* Catch Netscape but */
- && !strstr(p, "Gecko") /* save Mozilla, */
- && !strstr(p, "compatible") /* MSIE */
- && !strstr(p, "Opera")) /* and Opera. */
- {
- rsp->status = strdup("200 Request blocked by Privoxy");
- }
- else
- {
- rsp->status = strdup("403 Request blocked by Privoxy");
- }
+ rsp->status = strdup("403 Request blocked by Privoxy");
if (rsp->status == NULL)
{
free_http_response(rsp);
* Export the protocol, host, port, and referrer information
*/
err = map(exports, "hostport", 1, csp->http->hostport, 1);
- if (!err) err = map(exports, "protocol", 1, csp->http->ssl ? "https://" : "http://", 1);
+ if (!err) err = map(exports, "protocol", 1, csp->http->ssl ? "https://" : "http://", 1);
if (!err) err = map(exports, "path", 1, csp->http->path, 1);
if (NULL != (p = get_header_value(csp->headers, "Referer:")))
* 2 : b = The filter list to compile
*
* Returns : NULL in case of errors, otherwise the
- * pcrs job list.
+ * pcrs job list.
*
*********************************************************************/
pcrs_job *compile_dynamic_pcrs_job_list(const struct client_state *csp, const struct re_filterfile_spec *b)
* 2 : pcrs_command = pcrs command formatted as string (s@foo@bar@)
*
*
- * Returns : NULL if the pcrs_command didn't change the url, or
+ * Returns : NULL if the pcrs_command didn't change the url, or
* the result of the modification.
*
*********************************************************************/
*
* Parameters :
* 1 : subject = the string to check
- * 2 : redirect_mode = +fast-redirect{} mode
+ * 2 : redirect_mode = +fast-redirect{} mode
*
* Returns : NULL if no URL was found, or
* the last URL found.
if (0 == strcmpic(redirect_mode, "check-decoded-url"))
{
- log_error(LOG_LEVEL_REDIRECTS, "Decoding \"%s\" if necessary.", subject);
- new_url = url_decode(subject);
- if (new_url != NULL)
+ log_error(LOG_LEVEL_REDIRECTS,
+ "Checking \"%s\" for encoded redirects.", subject);
+ /*
+ * Check each parameter in the URL separately.
+ * Sectionize the URL at "?" and "&",
+ * then URL-decode each component,
+ * and look for a URL in the decoded result.
+ * Keep the last one we spot.
+ */
+ char *found = NULL;
+ char *token = strtok(subject, "?&");
+ while (token)
{
- freez(subject);
- subject = new_url;
+ char *dtoken = url_decode(token);
+ if (!dtoken) continue;
+ char *h1 = strstr(dtoken, "http://");
+ char *h2 = strstr(dtoken, "https://");
+ char *h = (h1 && h2
+ ? (h1 < h2 ? h1 : h2)
+ : (h1 ? h1 : h2));
+ if (h)
+ {
+ freez(found);
+ found = strdup(h);
+ }
+ token = strtok(NULL, "?&");
}
- else
+
+ if (found)
{
- log_error(LOG_LEVEL_ERROR, "Unable to decode \"%s\".", subject);
+ freez(subject);
+ return found;
}
+
+ freez(subject);
+ return NULL;
}
- log_error(LOG_LEVEL_REDIRECTS, "Checking \"%s\" for redirects.", subject);
+ /* Else, just look for a URL inside this one, without decoding anything. */
+
+ log_error(LOG_LEVEL_REDIRECTS,
+ "Checking \"%s\" for unencoded redirects.", subject);
/*
* Find the last URL encoded in the request
))
{
/*
- * Return new URL if we found a redirect
+ * Return new URL if we found a redirect
* or if the subject already was a URL.
*
* The second case makes sure that we can
#endif /* def FEATURE_FAST_REDIRECTS */
csp->action->flags &= ~ACTION_REDIRECT;
- /* Did any redirect action trigger? */
+ /* Did any redirect action trigger? */
if (new_url)
{
if (0 == strcmpic(new_url, csp->http->url))
struct re_filterfile_spec *b;
struct list_entry *filtername;
- /*
+ /*
* Sanity first
*/
if (csp->iob->cur >= csp->iob->eod)
break;
}
}
-
+
/* XXX: Should get its own loglevel. */
log_error(LOG_LEVEL_RE_FILTER, "De-chunking successful. Shrunk from %d to %d", *size, newsize);
/*********************************************************************
*
- * Function : direct_response
+ * Function : direct_response
*
* Description : Check if Max-Forwards == 0 for an OPTIONS or TRACE
* request and if so, return a HTTP 501 to the client.
* requests properly. Still, what we do here is rfc-
* compliant, whereas ignoring or forwarding are not.
*
- * Parameters :
+ * Parameters :
* 1 : csp = Current client state (buffers, headers, etc...)
*
* Returns : http_response if , NULL if nonmatch or handler fail
{
for (p = csp->headers->first; (p != NULL) ; p = p->next)
{
- if (!strncmpic("Max-Forwards:", p->str, 13))
+ if (!strncmpic(p->str, "Max-Forwards:", 13))
{
unsigned int max_forwards;
{
return cgi_error_memory();
}
-
+
if (NULL == (rsp->status = strdup("501 Not Implemented")))
{
free_http_response(rsp);
* Description : Checks whether there are any content filters
* enabled for the current request.
*
- * Parameters :
+ * Parameters :
* 1 : action = Action spec to check.
*
* Returns : TRUE for yes, FALSE otherwise