You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

http_headers.lua 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. --[[
  2. Copyright (c) 2015, Vsevolod Stakhov <vsevolod@highsecure.ru>
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ]]--
  13. local logger = require "rspamd_logger"
  14. local ucl = require "ucl"
  15. -- Disable DKIM checks if passed via HTTP headers
  16. rspamd_config:add_condition("R_DKIM_ALLOW", function(task)
  17. local hdr = task:get_request_header('DKIM')
  18. if hdr then
  19. local parser = ucl.parser()
  20. local res, err = parser:parse_string(tostring(hdr))
  21. if not res then
  22. logger.infox(task, "cannot parse DKIM header: %1", err)
  23. return true
  24. end
  25. local obj = parser:get_object()
  26. if obj['result'] then
  27. if obj['result'] == 'pass' or obj['result'] == 'allow' then
  28. task:insert_result('R_DKIM_ALLOW', 1.0, 'http header')
  29. elseif obj['result'] == 'fail' or obj['result'] == 'reject' then
  30. task:insert_result('R_DKIM_REJECT', 1.0, 'http header')
  31. elseif obj['result'] == 'tempfail' or obj['result'] == 'softfail' then
  32. task:insert_result('R_DKIM_TEMPFAIL', 1.0, 'http header')
  33. end
  34. return false
  35. end
  36. end
  37. return true
  38. end)
  39. -- Disable DKIM checks if passed via HTTP headers
  40. rspamd_config:add_condition("R_SPF_ALLOW", function(task)
  41. local hdr = task:get_request_header('SPF')
  42. if hdr then
  43. local parser = ucl.parser()
  44. local res, err = parser:parse_string(tostring(hdr))
  45. if not res then
  46. logger.infox(task, "cannot parse SPF header: %1", err)
  47. return true
  48. end
  49. local obj = parser:get_object()
  50. if obj['result'] then
  51. if obj['result'] == 'pass' or obj['result'] == 'allow' then
  52. task:insert_result('R_SPF_ALLOW', 1.0, 'http header')
  53. elseif obj['result'] == 'fail' or obj['result'] == 'reject' then
  54. task:insert_result('R_SPF_FAIL', 1.0, 'http header')
  55. elseif obj['result'] == 'neutral' then
  56. task:insert_result('R_SPF_NEUTRAL', 1.0, 'http header')
  57. elseif obj['result'] == 'tempfail' or obj['result'] == 'softfail' then
  58. task:insert_result('R_SPF_TEMPFAIL', 1.0, 'http header')
  59. end
  60. return false
  61. end
  62. end
  63. return true
  64. end)
  65. rspamd_config:add_condition("DMARC_POLICY_ALLOW", function(task)
  66. local hdr = task:get_request_header('DMARC')
  67. if hdr then
  68. local parser = ucl.parser()
  69. local res, err = parser:parse_string(tostring(hdr))
  70. if not res then
  71. logger.infox(task, "cannot parse DMARC header: %1", err)
  72. return true
  73. end
  74. local obj = parser:get_object()
  75. if obj['result'] then
  76. if obj['result'] == 'pass' or obj['result'] == 'allow' then
  77. task:insert_result('DMARC_POLICY_ALLOW', 1.0, 'http header')
  78. elseif obj['result'] == 'fail' or obj['result'] == 'reject' then
  79. task:insert_result('DMARC_POLICY_REJECT', 1.0, 'http header')
  80. elseif obj['result'] == 'quarantine' then
  81. task:insert_result('DMARC_POLICY_QUARANTINE', 1.0, 'http header')
  82. elseif obj['result'] == 'tempfail' or obj['result'] == 'softfail' then
  83. task:insert_result('DMARC_POLICY_SOFTFAIL', 1.0, 'http header')
  84. end
  85. return false
  86. end
  87. end
  88. return true
  89. end)