commit 8b66801: [Minor] Try to deal with urls with backslashes in path

Vsevolod Stakhov vsevolod at highsecure.ru
Fri Jul 30 10:28:04 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-07-30 11:20:49 +0100
URL: https://github.com/rspamd/rspamd/commit/8b66801d1a9a82fde251b321945091a153eeadbb

[Minor] Try to deal with urls with backslashes in path

---
 src/libserver/url.c   | 10 +++++-----
 test/lua/unit/url.lua |  6 +++++-
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/libserver/url.c b/src/libserver/url.c
index ce98f0961..139252df4 100644
--- a/src/libserver/url.c
+++ b/src/libserver/url.c
@@ -1165,7 +1165,7 @@ rspamd_web_parse (struct http_parser_url *u, const gchar *str, gsize len,
 					st = parse_port;
 					c = p + 1;
 				}
-				else if (*p == '/') {
+				else if (*p == '/' || *p == '\\') {
 					st = parse_path;
 					c = p + 1;
 				}
@@ -1309,11 +1309,11 @@ rspamd_web_parse (struct http_parser_url *u, const gchar *str, gsize len,
 				/* Too large domain */
 				goto out;
 			}
-			if (t == '/' || t == ':' || t == '?' || t == '#') {
+			if (t == '/' || t == '\\' || t == ':' || t == '?' || t == '#') {
 				if (p - c == 0) {
 					goto out;
 				}
-				if (t == '/') {
+				if (t == '/' || t == '\\') {
 					SET_U (u, UF_HOST);
 					st = parse_suffix_slash;
 				}
@@ -1463,7 +1463,7 @@ rspamd_web_parse (struct http_parser_url *u, const gchar *str, gsize len,
 			}
 			break;
 		case parse_port:
-			if (t == '/') {
+			if (t == '/' || t == '\\') {
 				pt = strtoul (c, NULL, 10);
 				if (pt == 0 || pt > 65535) {
 					goto out;
@@ -1515,7 +1515,7 @@ rspamd_web_parse (struct http_parser_url *u, const gchar *str, gsize len,
 			p++;
 			break;
 		case parse_suffix_slash:
-			if (t != '/') {
+			if (t != '/' && t != '\\') {
 				c = p;
 				st = parse_path;
 			}
diff --git a/test/lua/unit/url.lua b/test/lua/unit/url.lua
index 282d79290..58dfada00 100644
--- a/test/lua/unit/url.lua
+++ b/test/lua/unit/url.lua
@@ -138,7 +138,11 @@ context("URL check functions", function()
     }},
     {"http://@@example.com", true, {
       user = "@", host = "example.com"
-    }}
+    }},
+    {"https://example.com\\_Resources\\ClientImages\\UserData?ol\\o#ololo\\", true, {
+      host = "example.com", path = "_Resources/ClientImages/UserData",
+      query = "ol\\o", fragment = "ololo\\",
+    }},
   }
 
   -- Some cases from https://code.google.com/p/google-url/source/browse/trunk/src/url_canon_unittest.cc


More information about the Commits mailing list