commit 8d22202: [Fix] Fix an edge case in BITCOIN_ADDR rule

Andrew Lewis nerf at judo.za.org
Fri Jun 25 11:28:04 UTC 2021


Author: Andrew Lewis
Date: 2021-06-23 11:26:40 +0200
URL: https://github.com/rspamd/rspamd/commit/8d22202dc96475a497dfb68279e61d349314c340 (refs/pull/3804/head)

[Fix] Fix an edge case in BITCOIN_ADDR rule
 - when using PCRE
 - and different address types are present

---
 rules/bitcoin.lua                                | 5 +++--
 test/functional/cases/001_merged/280_rules.robot | 6 ++++++
 test/functional/messages/{btc3.eml => btc4.eml}  | 4 ++++
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/rules/bitcoin.lua b/rules/bitcoin.lua
index 56969536c..3cf97fcbe 100644
--- a/rules/bitcoin.lua
+++ b/rules/bitcoin.lua
@@ -180,7 +180,8 @@ local btc_bleach_re = [[/\b(?:(?:[a-zA-Z]\w+:)|(?:bc1))?[qpzry9x8gf2tvdw0s3jn54k
 
 config.regexp['BITCOIN_ADDR'] = {
   description = 'Message has a valid bitcoin wallet address',
-  re = string.format('(%s) || (%s)', normal_wallet_re, btc_bleach_re),
+  -- Use + operator to ensure that each expression is always evaluated
+  re = string.format('(%s) + (%s) > 0', normal_wallet_re, btc_bleach_re),
   re_conditions = {
     [normal_wallet_re] = function(task, txt, s, e)
       if e - s <= 2 then
@@ -228,4 +229,4 @@ config.regexp['BITCOIN_ADDR'] = {
   score = 0.0,
   one_shot = true,
   group = 'scams',
-}
\ No newline at end of file
+}
diff --git a/test/functional/cases/001_merged/280_rules.robot b/test/functional/cases/001_merged/280_rules.robot
index 52ea1c86d..2ae2f7422 100644
--- a/test/functional/cases/001_merged/280_rules.robot
+++ b/test/functional/cases/001_merged/280_rules.robot
@@ -66,6 +66,12 @@ BITCOIN ADDR 3
   ...  Settings={symbols_enabled = [BITCOIN_ADDR]}
   Expect Symbol  BITCOIN_ADDR
 
+BITCOIN ADDR 4
+  Scan File  ${RSPAMD_TESTDIR}/messages/btc4.eml
+  ...  Settings={symbols_enabled = [BITCOIN_ADDR]}
+  Expect Symbol With Exact Options  BITCOIN_ADDR  1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2
+  ...  bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq  bitcoincash:qztslqhavnjcgth9zwu6dw0jjcfy4zahfy7vf0smwp
+
 RCVD_COUNT_ONE
   Scan File  ${RSPAMD_TESTDIR}/messages/btc.eml
   ...  Settings={symbols_enabled = [RCVD_COUNT_ONE]}
diff --git a/test/functional/messages/btc3.eml b/test/functional/messages/btc4.eml
similarity index 82%
copy from test/functional/messages/btc3.eml
copy to test/functional/messages/btc4.eml
index d55c9d6ae..523ce592f 100644
--- a/test/functional/messages/btc3.eml
+++ b/test/functional/messages/btc4.eml
@@ -11,12 +11,16 @@ Content-Type: multipart/alternative; boundary="00000000000004de7805a4489190"
 Content-Type: text/plain; charset="UTF-8"
 Content-Transfer-Encoding: 8bit
 
+bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq
 bitcoincash:qztslqhavnjcgth9zwu6dw0jjcfy4zahfy7vf0smwp
+1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2
 
 --0000000000004bee6805a4484c02
 Content-Type: text/html; charset="UTF-8"
 Content-Transfer-Encoding: 8bit
 
+bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq
 bitcoincash:qztslqhavnjcgth9zwu6dw0jjcfy4zahfy7vf0smwp
+1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2
 
 --0000000000004bee6805a4484c02--


More information about the Commits mailing list