rspamd icon indicating copy to clipboard operation
rspamd copied to clipboard

[BUG] Strange/Unexpected task:get_urls combined with get_raw() behavior.

Open noud-github opened this issue 7 months ago • 3 comments

Prerequisites

  • [X] Put an X between the brackets on this line if you have done all of the following:
    • Read about bug reporting in general: https://rspamd.com/doc/faq.html#how-to-report-bugs-found-in-rspamd
    • Enabled relevant debugging logs: https://rspamd.com/doc/faq.html#how-to-debug-some-module-in-rspamd
    • Checked the FAQs about Core files in case of fatal crash: https://rspamd.com/doc/faq.html#how-to-figure-out-why-rspamd-process-crashed
    • Tried ASAN package and obtained the ASAN report (if possible): https://rspamd.com/doc/faq.html#asan-builds
    • Checked that your issue isn't already filed: https://github.com/issues?utf8=%E2%9C%93&q=is%3Aissue+user%3Arspamd
    • Checked that there is not already an experimental package or master branch

Describe the bug Two emails with differ in that one uses the same url in the html and plain parts and the other only in the plain part. return different results when using task:get_urls() and get_raw() The urls differ in that the | \ @ : are no longer escaped compared to the original email text. when that url occurs two times

Steps to Reproduce

  1. create file /etc/rspamd/lua.local.d/test.lua with this content:
local rspamd_logger = require "rspamd_logger"

local function echo_urls(task)
	local url_list  = task:get_urls({'https', 'http'})

    if url_list  then
		for _,raw_url in ipairs(url_list ) do
			local url = tostring(raw_url:get_raw())

			rspamd_logger.infox(task, "Echo url %s ",  url)
		end
	end
end

rspamd_config:register_symbol({
  name = 'TEST',
  type = 'prefilter',
  priority = 10,
  callback = function(task)
	echo_urls(task)
  end
})
  1. create file test1.eml
Content-Type: multipart/alternative; boundary="boundary-string"

--boundary-string
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit

Hello,
This is the plain text part.
Visit our site: https://safelinks.example.com/?url=https%3A%2F%2Flink.example.com%2Fdc%2Fv7r50z9-dmTEo3N1RYy3-AXPRx3hxnUb4GZZXFg4U7DoLhanHsFtxsDk8QaAXKH3Dk46-hCqGBX6kouwHNGgQsxRHkXu3ToVFFRrDYWH1jgUUO8HYduKIRVXO7ayWzpV9dCG-lBeWspOayiBD3cBUrrwbvCvq0qdhmfiG2aLfTXIf-WXI3bXedNmNfGBBCJ28s4FBTsxw658Ec8rJ4YV5kIpZvLIIsQgedYG8s_-U84%3D%2FODcwLUxCRy0zMTIAAAGgpMw5cg_IP7_zmrHWU9djRozSxe3kLPyrNwj3XNW2PIFapk8IOL2VsMgte_p_mX7aFRn3z3c%3D&data=05%7C02%7Cmail%40example.com%7Cb7e93dc506bf4fb3093008de85a996af%7C084578d9400d4a5aa7c7e76ca47af400%7C1%7C0%7C639095160630598763%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=sHLvBnhjdlCTBHBtHsP22UUXkx8RPwo9Y3yhrqSv6kM%3D&reserved=0

--boundary-string
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: 7bit

<html>
  <body>
    <h1>Security Test</h1>
    <p>Please click the link below to verify your account:</p>
    <p>
      Test 1 <a href="https://safelinks.example.com/?url=https%3A%2F%2Flink.example.com%2Fdc%2Fv7r50z9-dmTEo3N1RYy3-AXPRx3hxnUb4GZZXFg4U7DoLhanHsFtxsDk8QaAXKH3Dk46-hCqGBX6kouwHNGgQsxRHkXu3ToVFFRrDYWH1jgUUO8HYduKIRVXO7ayWzpV9dCG-lBeWspOayiBD3cBUrrwbvCvq0qdhmfiG2aLfTXIf-WXI3bXedNmNfGBBCJ28s4FBTsxw658Ec8rJ4YV5kIpZvLIIsQgedYG8s_-U84%3D%2FODcwLUxCRy0zMTIAAAGgpMw5cg_IP7_zmrHWU9djRozSxe3kLPyrNwj3XNW2PIFapk8IOL2VsMgte_p_mX7aFRn3z3c%3D&data=05%7C02%7Cmail%40example.com%7Cb7e93dc506bf4fb3093008de85a996af%7C084578d9400d4a5aa7c7e76ca47af400%7C1%7C0%7C639095160630598763%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=sHLvBnhjdlCTBHBtHsP22UUXkx8RPwo9Y3yhrqSv6kM%3D&reserved=0">Verify Account</a>
    </p>
    <p>
      Test 2 <a href="https://link.example.com/dc/v7r50z9-dmTEo3N1RYy3-AXPRx3hxnUb4GZZXFg4U7DoLhanHsFtxsDk8QaAXKH3Dk46-hCqGBX6kouwHNGgQsxRHkXu3ToVFFRrDYWH1jgUUO8HYduKIRVXO7ayWzpV9dCG-lBeWspOayiBD3cBUrrwbvCvq0qdhmfiG2aLfTXIf-WXI3bXedNmNfGBBCJ28s4FBTsxw658Ec8rJ4YV5kIpZvLIIsQgedYG8s_-U84=/ODcwLUxCRy0zMTIAAAGgpMw5cg_IP7_zmrHWU9djRozSxe3kLPyrNwj3XNW2PIFapk8IOL2VsMgte_p_mX7aFRn3z3c=">Verify Account</a>
    </p>
    <p>Or click this image:</p>
    <a href="https://www.original-link.com/tracking">
      <img src="https://via.placeholder.com/150" alt="Click Me">
    </a>
  </body>
</html>

--boundary-string--
  1. create file test2.eml
Content-Type: multipart/alternative; boundary="boundary-string"

--boundary-string
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit

Hello,
This is the plain text part.
Visit our site: https://safelinks.example.com/?url=https%3A%2F%2Flink.example.com%2Fdc%2Fv7r50z9-dmTEo3N1RYy3-AXPRx3hxnUb4GZZXFg4U7DoLhanHsFtxsDk8QaAXKH3Dk46-hCqGBX6kouwHNGgQsxRHkXu3ToVFFRrDYWH1jgUUO8HYduKIRVXO7ayWzpV9dCG-lBeWspOayiBD3cBUrrwbvCvq0qdhmfiG2aLfTXIf-WXI3bXedNmNfGBBCJ28s4FBTsxw658Ec8rJ4YV5kIpZvLIIsQgedYG8s_-U84%3D%2FODcwLUxCRy0zMTIAAAGgpMw5cg_IP7_zmrHWU9djRozSxe3kLPyrNwj3XNW2PIFapk8IOL2VsMgte_p_mX7aFRn3z3c%3D&data=05%7C02%7Cmail%40example.com%7Cb7e93dc506bf4fb3093008de85a996af%7C084578d9400d4a5aa7c7e76ca47af400%7C1%7C0%7C639095160630598763%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=sHLvBnhjdlCTBHBtHsP22UUXkx8RPwo9Y3yhrqSv6kM%3D&reserved=0

--boundary-string
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: 7bit

<html>
  <body>
    <h1>Security Test</h1>
    <p>Please click the link below to verify your account:</p>
    <p>
      Test 2 <a href="https://link.example.com/dc/v7r50z9-dmTEo3N1RYy3-AXPRx3hxnUb4GZZXFg4U7DoLhanHsFtxsDk8QaAXKH3Dk46-hCqGBX6kouwHNGgQsxRHkXu3ToVFFRrDYWH1jgUUO8HYduKIRVXO7ayWzpV9dCG-lBeWspOayiBD3cBUrrwbvCvq0qdhmfiG2aLfTXIf-WXI3bXedNmNfGBBCJ28s4FBTsxw658Ec8rJ4YV5kIpZvLIIsQgedYG8s_-U84=/ODcwLUxCRy0zMTIAAAGgpMw5cg_IP7_zmrHWU9djRozSxe3kLPyrNwj3XNW2PIFapk8IOL2VsMgte_p_mX7aFRn3z3c=">Verify Account</a>
    </p>
    <p>Or click this image:</p>
    <a href="https://www.original-link.com/tracking">
      <img src="https://via.placeholder.com/150" alt="Click Me">
    </a>
  </body>
</html>

--boundary-string--
  1. restart rspamd
  2. run rspamc test1.eml
  3. run rspamc test2.eml
  4. view log cat /var/log/rspamd/rspamd.log | grep 'lua; test.lua:11:' | grep safelinks
  5. expected behavior, both found urls starting with https://safelinks.example.com/ to be identical

Versions

ubuntu 24.04 rspamd 4.0.1 & 3.14.3

Additional Information

noud-github avatar Apr 15 '26 09:04 noud-github

view log cat /var/log/rspamd/rspamd.log | grep 'lua; test.lua:11:' | grep safelinks

what is the output of this, can you paste that here?

miekg avatar Apr 16 '26 09:04 miekg

2026-04-15 09:47:50 #96004(controller) <85c424>; lua; test.lua:11: Echo url https://safelinks.example.com/?url=https://link.example.com/dc/v7r50z9-dmTEo3N1RYy3-AXPRx3hxnUb4GZZXFg4U7DoLhanHsFtxsDk8QaAXKH3Dk46-hCqGBX6kouwHNGgQsxRHkXu3ToVFFRrDYWH1jgUUO8HYduKIRVXO7ayWzpV9dCG-lBeWspOayiBD3cBUrrwbvCvq0qdhmfiG2aLfTXIf-WXI3bXedNmNfGBBCJ28s4FBTsxw658Ec8rJ4YV5kIpZvLIIsQgedYG8s_-U84%3D/ODcwLUxCRy0zMTIAAAGgpMw5cg_IP7_zmrHWU9djRozSxe3kLPyrNwj3XNW2PIFapk8IOL2VsMgte_p_mX7aFRn3z3c%3D&data=05|02|[email protected]|b7e93dc506bf4fb3093008de85a996af|084578d9400d4a5aa7c7e76ca47af400|1|0|639095160630598763|Unknown|TWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D|0|||&sdata=sHLvBnhjdlCTBHBtHsP22UUXkx8RPwo9Y3yhrqSv6kM%3D&reserved=0 2026-04-15 09:47:56 #96004(controller) <84360d>; lua; test.lua:11: Echo url https://safelinks.example.com/?url=https%3A%2F%2Flink.example.com%2Fdc%2Fv7r50z9-dmTEo3N1RYy3-AXPRx3hxnUb4GZZXFg4U7DoLhanHsFtxsDk8QaAXKH3Dk46-hCqGBX6kouwHNGgQsxRHkXu3ToVFFRrDYWH1jgUUO8HYduKIRVXO7ayWzpV9dCG-lBeWspOayiBD3cBUrrwbvCvq0qdhmfiG2aLfTXIf-WXI3bXedNmNfGBBCJ28s4FBTsxw658Ec8rJ4YV5kIpZvLIIsQgedYG8s_-U84%3D%2FODcwLUxCRy0zMTIAAAGgpMw5cg_IP7_zmrHWU9djRozSxe3kLPyrNwj3XNW2PIFapk8IOL2VsMgte_p_mX7aFRn3z3c%3D&data=05%7C02%7Cmail%40example.com%7Cb7e93dc506bf4fb3093008de85a996af%7C084578d9400d4a5aa7c7e76ca47af400%7C1%7C0%7C639095160630598763%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=sHLvBnhjdlCTBHBtHsP22UUXkx8RPwo9Y3yhrqSv6kM%3D&reserved=0

noud-github avatar Apr 16 '26 09:04 noud-github

I can also make a email with two of the same urls not affected:

test3.eml

Content-Type: multipart/alternative; boundary="boundary-string"

--boundary-string
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit

Hello,
This is the plain text part.
Visit our site: http://localhost:8080/?url=https%3a%2f%2fwww%2eoriginal%2dlink%2ecom%2fpage%3fid%3d123&amp;to=a%2email%40examlpe%2ecom&amp;gen=v1&amp;sig=6436f8d5be0f4da3593d3b215afea1eeeb978768


--boundary-string
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: 7bit

<html>
  <body>
    <h1>Security Test</h1>
    <p>Please click the link below to verify your account:</p>
    <p>
      <a href="http://localhost:8080/?url=https%3a%2f%2fwww%2eoriginal%2dlink%2ecom%2fpage%3fid%3d123&amp;to=a%2email%40examlpe%2ecom&amp;gen=v1&amp;sig=6436f8d5be0f4da3593d3b215afea1eeeb978768">Verify Account</a>
    </p>
  </body>
</html>

--boundary-string--

noud-github avatar Apr 16 '26 09:04 noud-github