]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Use raw urls when sending requests to redirector
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 12 Aug 2017 18:29:02 +0000 (19:29 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 12 Aug 2017 19:26:17 +0000 (20:26 +0100)
src/libserver/url.c
src/libserver/url.h
src/plugins/lua/url_redirector.lua

index cc7c7acbf8e8a255e7f653c4bbce4b6d710b23de..918f7eee33965ac7c49298dcf67b3e2e67a9e3b4 100644 (file)
@@ -1414,6 +1414,7 @@ rspamd_url_shift (struct rspamd_url *uri, gsize nlen,
                memmove (uri->string + uri->protocollen, uri->string + old_shift,
                                uri->urllen - uri->protocollen);
                uri->urllen -= shift;
+               uri->flags |= RSPAMD_URL_FLAG_SCHEMAENCODED;
                break;
        case UF_HOST:
                if (nlen >= uri->hostlen) {
@@ -1428,6 +1429,7 @@ rspamd_url_shift (struct rspamd_url *uri, gsize nlen,
                memmove (uri->host + uri->hostlen, uri->host + old_shift,
                                uri->datalen + uri->querylen + uri->fragmentlen);
                uri->urllen -= shift;
+               uri->flags |= RSPAMD_URL_FLAG_HOSTENCODED;
                break;
        case UF_PATH:
                if (nlen >= uri->datalen) {
@@ -1442,6 +1444,7 @@ rspamd_url_shift (struct rspamd_url *uri, gsize nlen,
                memmove (uri->data + uri->datalen, uri->data + old_shift,
                                uri->querylen + uri->fragmentlen);
                uri->urllen -= shift;
+               uri->flags |= RSPAMD_URL_FLAG_PATHENCODED;
                break;
        case UF_QUERY:
                if (nlen >= uri->querylen) {
@@ -1456,6 +1459,7 @@ rspamd_url_shift (struct rspamd_url *uri, gsize nlen,
                memmove (uri->query + uri->querylen, uri->query + old_shift,
                                uri->fragmentlen);
                uri->urllen -= shift;
+               uri->flags |= RSPAMD_URL_FLAG_QUERYENCODED;
                break;
        case UF_FRAGMENT:
                if (nlen >= uri->fragmentlen) {
@@ -1542,42 +1546,46 @@ rspamd_url_parse (struct rspamd_url *uri, gchar *uristring, gsize len,
        }
 
        if (end > uristring && (guint) (end - uristring) != len) {
-               /* We have extra data at the end of uri, so we are ignoring it for now */
-               p = rspamd_mempool_alloc (pool, end - uristring + 1);
-               rspamd_strlcpy (p, uristring, end - uristring + 1);
                len = end - uristring;
        }
 
+       uri->raw = p;
+       uri->rawlen = len;
+       uri->string = rspamd_mempool_alloc (pool, len + 1);
+       rspamd_strlcpy (uri->string, p, len + 1);
+       uri->urllen = len;
+
        for (i = 0; i < UF_MAX; i++) {
                if (u.field_set & (1 << i)) {
-                       comp = p + u.field_data[i].off;
+                       comp = uri->string + u.field_data[i].off;
                        complen = u.field_data[i].len;
+
                        switch (i) {
-                               case UF_SCHEMA:
-                                       uri->protocollen = u.field_data[i].len;
-                                       break;
-                               case UF_HOST:
-                                       uri->host = comp;
-                                       uri->hostlen = complen;
-                                       break;
-                               case UF_PATH:
-                                       uri->data = comp;
-                                       uri->datalen = complen;
-                                       break;
-                               case UF_QUERY:
-                                       uri->query = comp;
-                                       uri->querylen = complen;
-                                       break;
-                               case UF_FRAGMENT:
-                                       uri->fragment = comp;
-                                       uri->fragmentlen = complen;
-                                       break;
-                               case UF_USERINFO:
-                                       uri->user = comp;
-                                       uri->userlen = complen;
-                                       break;
-                               default:
-                                       break;
+                       case UF_SCHEMA:
+                               uri->protocollen = u.field_data[i].len;
+                               break;
+                       case UF_HOST:
+                               uri->host = comp;
+                               uri->hostlen = complen;
+                               break;
+                       case UF_PATH:
+                               uri->data = comp;
+                               uri->datalen = complen;
+                               break;
+                       case UF_QUERY:
+                               uri->query = comp;
+                               uri->querylen = complen;
+                               break;
+                       case UF_FRAGMENT:
+                               uri->fragment = comp;
+                               uri->fragmentlen = complen;
+                               break;
+                       case UF_USERINFO:
+                               uri->user = comp;
+                               uri->userlen = complen;
+                               break;
+                       default:
+                               break;
                        }
                }
        }
@@ -1592,12 +1600,6 @@ rspamd_url_parse (struct rspamd_url *uri, gchar *uristring, gsize len,
                uri->flags |= RSPAMD_URL_FLAG_OBSCURED;
        }
 
-       uri->raw = p;
-       uri->rawlen = len;
-       uri->string = rspamd_mempool_alloc (pool, len + 1);
-       rspamd_strlcpy (uri->string, p, len + 1);
-       uri->urllen = len;
-
        /* Now decode url symbols */
        unquoted_len = rspamd_url_decode (uri->string,
                        uri->string,
index 48f5acc1295422b3066c483fcac65d866ffaeb1b..a9466c6369b6691972e949d2083681ee42f93e6f 100644 (file)
@@ -17,6 +17,10 @@ enum rspamd_url_flags {
        RSPAMD_URL_FLAG_HTML_DISPLAYED = 1 << 4,
        RSPAMD_URL_FLAG_FROM_TEXT = 1 << 5,
        RSPAMD_URL_FLAG_SUBJECT = 1 << 6,
+       RSPAMD_URL_FLAG_HOSTENCODED = 1 << 7,
+       RSPAMD_URL_FLAG_SCHEMAENCODED = 1 << 8,
+       RSPAMD_URL_FLAG_PATHENCODED = 1 << 9,
+       RSPAMD_URL_FLAG_QUERYENCODED = 1 << 10,
 };
 
 struct rspamd_url_tag {
index 698ed6f8c411340c0d453305159840b3b6a0d7de..a6e7afc11005ec35972ca96fe375bee33622d24b 100644 (file)
@@ -230,7 +230,7 @@ local function resolve_cached(task, orig_url, url, key, param, ntries)
 end
 
 local function url_redirector_handler(task, url, param)
-  local url_str = tostring(url)
+  local url_str = url:get_raw()
   -- 32 base32 characters are roughly 20 bytes of data or 160 bits
   local key = settings.key_prefix .. hash.create(url_str):base32():sub(1, 32)
   resolve_cached(task, url_str, url_str, key, param, 1)