[PATCH spf] Anchor subpatterns of aField/mxField/ptrField correctly

11 views
Skip to first unread message

fox.cpp

unread,
Jul 24, 2020, 11:04:09 AM7/24/20
to chas...@googlegroups.com, fox.cpp
Only first pattern was anchored. This created mismatches
if "a:", "mx:", "ptr:" are contained within rule.
"a:" is possible in IPv6 addresses, exp= use (or any rule that permits
arbitrary strings) may lead to such mismatch as well.
---
spf.go | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/spf.go b/spf.go
index b8f74ed..b26a60c 100644
--- a/spf.go
+++ b/spf.go
@@ -151,9 +151,9 @@ type resolution struct {
ipNames []string
}

-var aField = regexp.MustCompile(`^a$|a:|a/`)
-var mxField = regexp.MustCompile(`^mx$|mx:|mx/`)
-var ptrField = regexp.MustCompile(`^ptr$|ptr:`)
+var aField = regexp.MustCompile(`^(a$|a:|a/)`)
+var mxField = regexp.MustCompile(`^(mx$|mx:|mx/)`)
+var ptrField = regexp.MustCompile(`^(ptr$|ptr:)`)

func (r *resolution) Check(domain string) (Result, error) {
r.count++
--
2.27.0

Alberto Bertogli

unread,
Jul 26, 2020, 12:49:00 PM7/26/20
to fox.cpp, chas...@googlegroups.com
On Fri, Jul 24, 2020 at 06:03:54PM +0300, fox.cpp wrote:
>Only first pattern was anchored. This created mismatches
>if "a:", "mx:", "ptr:" are contained within rule.
>"a:" is possible in IPv6 addresses, exp= use (or any rule that permits
>arbitrary strings) may lead to such mismatch as well.

Thanks a lot for finding this and sending a patch!

Merged (amended with some tests):
https://blitiri.com.ar/git/r/spf/c/67a432adc6658d28cb0009da0c394c3355ca63ea/

I also just tagged v1.1.1 which includes this fix.

Thanks again,
Alberto

Reply all
Reply to author
Forward
0 new messages