From 45a864efa6fa4c8652431bf8b8c2dc3da0735e0b Mon Sep 17 00:00:00 2001 From: "Michael \"Kiwi\" Ngarimu" <24663124+namelessmasses@users.noreply.github.com> Date: Wed, 1 Jan 2025 05:53:44 -0800 Subject: [PATCH] Allow multiple '*' globs in the From pattern (#471) --------- Co-authored-by: lieser --- manifest.json | 2 +- modules/dkim/signRules.mjs.js | 2 +- test/unittest/signRulesSpec.mjs.js | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index ee2ed97e..c20c38a5 100644 --- a/manifest.json +++ b/manifest.json @@ -10,7 +10,7 @@ "gecko": { "id": "dkim_verifier@pl", "strict_min_version": "91.0", - "strict_max_version": "121.*" + "strict_max_version": "128.*" } }, "permissions": [ diff --git a/modules/dkim/signRules.mjs.js b/modules/dkim/signRules.mjs.js index bbbaa60b..35ff2060 100644 --- a/modules/dkim/signRules.mjs.js +++ b/modules/dkim/signRules.mjs.js @@ -225,7 +225,7 @@ function glob(str, pattern) { // escape all special regex charters besides * let regexpPattern = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&"); // replace * with correct regex - regexpPattern = regexpPattern.replace("*", ".*"); + regexpPattern = regexpPattern.replace(/\*/g, ".*"); const regexp = new RegExp(`^${regexpPattern}$`, "i"); return regexp.test(str); diff --git a/test/unittest/signRulesSpec.mjs.js b/test/unittest/signRulesSpec.mjs.js index b3c1523c..24cf579d 100644 --- a/test/unittest/signRulesSpec.mjs.js +++ b/test/unittest/signRulesSpec.mjs.js @@ -126,6 +126,14 @@ describe("Sign rules [unittest]", function () { res = await SignRules.check(dkimNone, "bar@a.foo.comX"); expect(res.result).is.equal("none"); + + await SignRules.addRule("bar.com", null, "*@mail.*.bar.com", "bar.com", SignRules.TYPE.ALL); + res = await SignRules.check(dkimNone, "@mail.a.bar.com"); + expect(res.result).is.equal("PERMFAIL"); + res = await SignRules.check(dkimNone, "test@mail.foo.bar.com"); + expect(res.result).is.equal("PERMFAIL"); + res = await SignRules.check(dkimNone, "test@foo.bar.com"); + expect(res.result).is.equal("none"); }); it("Add user exception", async function () { let res = await SignRules.check(dkimNone, "bar@paypal.com");