Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. --[[
  2. Copyright (c) 2022, Vsevolod Stakhov <vsevolod@rspamd.com>
  3. Copyright (c) 2016, Steve Freegard <steve@freegard.name>
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. ]]--
  14. local rspamd_util = require "rspamd_util"
  15. local function mid_check_func(task)
  16. local mid = task:get_header('Message-ID')
  17. if not mid then return false end
  18. -- Check for 'bare' IP addresses in RHS
  19. if mid:find("@%d+%.%d+%.%d+%.%d+>$") then
  20. task:insert_result('MID_BARE_IP', 1.0)
  21. end
  22. -- Check for non-FQDN RHS
  23. if mid:find("@[^%.]+>?$") then
  24. task:insert_result('MID_RHS_NOT_FQDN', 1.0)
  25. end
  26. -- Check for missing <>'s
  27. if not mid:find('^<[^>]+>$') then
  28. task:insert_result('MID_MISSING_BRACKETS', 1.0)
  29. end
  30. -- Check for IP literal in RHS
  31. if mid:find("@%[%d+%.%d+%.%d+%.%d+%]") then
  32. task:insert_result('MID_RHS_IP_LITERAL', 1.0)
  33. end
  34. -- Check From address attributes against MID
  35. local from = task:get_from(2)
  36. local fd
  37. if (from and from[1] and from[1].domain and from[1].domain ~= '') then
  38. fd = from[1].domain:lower()
  39. local _,_,md = mid:find("@([^>]+)>?$")
  40. -- See if all or part of the From address
  41. -- can be found in the Message-ID
  42. -- extract tld
  43. local fdtld = nil
  44. local mdtld = nil
  45. if md then
  46. fdtld = rspamd_util.get_tld(fd)
  47. mdtld = rspamd_util.get_tld(md)
  48. end
  49. if (mid:lower():find(from[1].addr:lower(),1,true)) then
  50. task:insert_result('MID_CONTAINS_FROM', 1.0)
  51. elseif (md and fd == md:lower()) then
  52. task:insert_result('MID_RHS_MATCH_FROM', 1.0)
  53. elseif (mdtld ~= nil and fdtld ~= nil and mdtld:lower() == fdtld) then
  54. task:insert_result('MID_RHS_MATCH_FROMTLD', 1.0)
  55. end
  56. end
  57. -- Check To address attributes against MID
  58. local to = task:get_recipients(2)
  59. if (to and to[1] and to[1].domain and to[1].domain ~= '') then
  60. local td = to[1].domain:lower()
  61. local _,_,md = mid:find("@([^>]+)>?$")
  62. -- Skip if from domain == to domain
  63. if ((fd and fd ~= td) or not fd) then
  64. -- See if all or part of the To address
  65. -- can be found in the Message-ID
  66. if (mid:lower():find(to[1].addr:lower(),1,true)) then
  67. task:insert_result('MID_CONTAINS_TO', 1.0)
  68. elseif (md and td == md:lower()) then
  69. task:insert_result('MID_RHS_MATCH_TO', 1.0)
  70. end
  71. end
  72. end
  73. end
  74. -- MID checks from Steve Freegard
  75. local check_mid_id = rspamd_config:register_symbol({
  76. name = 'CHECK_MID',
  77. score = 0.0,
  78. group = 'mid',
  79. type = 'callback,mime',
  80. callback = mid_check_func
  81. })
  82. rspamd_config:register_virtual_symbol('MID_BARE_IP', 1.0, check_mid_id)
  83. rspamd_config:set_metric_symbol('MID_BARE_IP', 2.0, 'Message-ID RHS is a bare IP address', 'default', 'Message ID')
  84. rspamd_config:register_virtual_symbol('MID_RHS_NOT_FQDN', 1.0, check_mid_id)
  85. rspamd_config:set_metric_symbol('MID_RHS_NOT_FQDN', 0.5,
  86. 'Message-ID RHS is not a fully-qualified domain name', 'default', 'Message ID')
  87. rspamd_config:register_virtual_symbol('MID_MISSING_BRACKETS', 1.0, check_mid_id)
  88. rspamd_config:set_metric_symbol('MID_MISSING_BRACKETS', 0.5, 'Message-ID is missing <>\'s', 'default', 'Message ID')
  89. rspamd_config:register_virtual_symbol('MID_RHS_IP_LITERAL', 1.0, check_mid_id)
  90. rspamd_config:set_metric_symbol('MID_RHS_IP_LITERAL', 0.5, 'Message-ID RHS is an IP-literal', 'default', 'Message ID')
  91. rspamd_config:register_virtual_symbol('MID_CONTAINS_FROM', 1.0, check_mid_id)
  92. rspamd_config:set_metric_symbol('MID_CONTAINS_FROM', 1.0, 'Message-ID contains From address', 'default', 'Message ID')
  93. rspamd_config:register_virtual_symbol('MID_RHS_MATCH_FROM', 1.0, check_mid_id)
  94. rspamd_config:set_metric_symbol('MID_RHS_MATCH_FROM', 0.0,
  95. 'Message-ID RHS matches From domain', 'default', 'Message ID')
  96. rspamd_config:register_virtual_symbol('MID_RHS_MATCH_FROMTLD', 1.0, check_mid_id)
  97. rspamd_config:set_metric_symbol('MID_RHS_MATCH_FROMTLD', 0.0,
  98. 'Message-ID RHS matches From domain tld', 'default', 'Message ID')
  99. rspamd_config:register_virtual_symbol('MID_CONTAINS_TO', 1.0, check_mid_id)
  100. rspamd_config:set_metric_symbol('MID_CONTAINS_TO', 1.0, 'Message-ID contains To address', 'default', 'Message ID')
  101. rspamd_config:register_virtual_symbol('MID_RHS_MATCH_TO', 1.0, check_mid_id)
  102. rspamd_config:set_metric_symbol('MID_RHS_MATCH_TO', 1.0, 'Message-ID RHS matches To domain', 'default', 'Message ID')