]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Fix XML detection overriding HTML in content type detection
authorVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 18 Feb 2026 19:01:23 +0000 (19:01 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 18 Feb 2026 19:01:23 +0000 (19:01 +0000)
HTML parts containing an embedded <?xml?> prolog (e.g. inside the body)
were misdetected as application/xml. Since xml type has no_text=true,
this excluded the HTML part from text_parts entirely, causing
has_only_html_part() to return false and MIME_HTML_ONLY to not fire.

- Remove xml binary pattern from patterns.lua (it preempted the text
  heuristic which correctly prioritises HTML)
- Guard xml text pattern so it cannot override HTML when HTML markers
  are also present
- Raise xml text pattern weight to 40 to preserve pure XML detection

lualib/lua_magic/heuristics.lua
lualib/lua_magic/patterns.lua

index 8b5b9c52daac51f0838efe8d285c8ec858e2d3f2..6acbbbf8d00f4d158a452713b45e3eb798b104bd 100644 (file)
@@ -84,7 +84,7 @@ local txt_patterns = {
     { [[^BEGIN:VCARD\r?\n]], 40 },
   },
   xml = {
-    { [[<\?xml\b.+\?>]], 31 },
+    { [[<\?xml\b.+\?>]], 40 },
   }
 }
 
@@ -530,6 +530,11 @@ exports.text_part_heuristic = function(part, log_obj, _)
           return 'html', res.html
         end
 
+        -- XML prolog can appear inside HTML; do not let xml override html
+        if res.xml and res.html then
+          res.xml = nil
+        end
+
         local ext, weight = process_top_detected(res)
 
         if weight then
index 2bbf4e258ded4586eb70c13289003de349edcd32..630025202baf535f98e2deba635fd8497ceb9a9d 100644 (file)
@@ -462,16 +462,6 @@ local patterns = {
       },
     }
   },
-  xml = {
-    matches = {
-      {
-        -- XML prolog
-        string = [[<\?xml\b.+\?>]],
-        position = { '>=', 0 },
-        weight = 30,
-      },
-    }
-  },
   -- Other
   pgp = {
     matches = {