]> source.dussan.org Git - rspamd.git/commitdiff
[PATCH] Encode constructed path to be URL safe.
authorTarmo Oja <tarmo.oja@cyber.ee>
Thu, 22 Aug 2024 09:57:06 +0000 (12:57 +0300)
committerTarmo Oja <tarmo.oja@cyber.ee>
Thu, 22 Aug 2024 09:57:06 +0000 (12:57 +0300)
fix #4643

lualib/lua_scanners/icap.lua
lualib/lua_util.lua

index 682562d858df7c879133a67dd1b5f9d44606b996..2e3ced0344ab5fecf35d961343358d3364098bdd 100644 (file)
@@ -245,7 +245,7 @@ local function icap_check(task, content, digest, rule, maybe_part)
         local req_hlen = 2
         if maybe_part then
           table.insert(req_headers,
-              string.format('GET http://%s/%s HTTP/1.0\r\n', in_client_ip, maybe_part:get_filename()))
+              string.format('GET http://%s/%s HTTP/1.0\r\n', in_client_ip, lua_util.url_encode_string(maybe_part:get_filename())))
           if rule.use_specific_content_type then
             table.insert(http_headers, string.format('Content-Type: %s/%s\r\n', maybe_part:get_detected_type()))
             --else
index a64f8abc9ab4147c33b4dbd9c40d979138fb4c37..8f44e25f20c4c47aed9b5c9d35336c0024d704c7 100644 (file)
@@ -1687,6 +1687,24 @@ local function join_path(...)
 end
 exports.join_path = join_path
 
+---[[[
+-- @function lua_util.url_encode_string(str)
+-- URL encodes a string
+--
+-- @param {string} str string to encode
+-- @return {string} URL encoded string
+--
+---]]]
+local function url_encode_string(str)
+  str = string.gsub(str, "([^%w _%%%-%.~])",
+      function(c)
+        return string.format("%%%02X", string.byte(c))
+      end)
+  str = string.gsub(str, " ", "+")
+  return str
+end
+exports.url_encode_string = url_encode_string
+
 -- Short unit test for sanity
 if path_sep == '/' then
   assert(join_path('/path', 'to', 'file') == '/path/to/file')