Skip to content

Commit

Permalink
Check if the include listed after include: could be a domainname, fai…
Browse files Browse the repository at this point in the history
…l if the include looks like include:include:domain.ext
  • Loading branch information
markvantilburg committed Dec 18, 2024
1 parent fdb63f9 commit 829c471
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions BusinessMonitor.MailTools.Test/SpfTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public void TestModifiers()
[TestCase("")]
[TestCase("v=spf1 -boop")]
[TestCase("v=spf1 boop:boop")]
[TestCase("v=spf1 include:include:businessmonitor.nl")]
public void TestInvalid(string value)
{
Assert.Throws<SpfInvalidException>(() =>
Expand Down
8 changes: 7 additions & 1 deletion BusinessMonitor.MailTools/Spf/SpfCheck.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using BusinessMonitor.MailTools.Dns;
using BusinessMonitor.MailTools.Exceptions;
using System.Net;
using System.Text.RegularExpressions;

namespace BusinessMonitor.MailTools.Spf
{
Expand Down Expand Up @@ -83,7 +84,7 @@ private SpfRecord GetRecord(string domain)
{
throw new SpfInvalidException("Too many SPF records found on domain");
}

// Parse and validate the record and return it
var parsed = ParseSpfRecord(record);

Expand Down Expand Up @@ -238,6 +239,11 @@ private static SpfDirective ParseDirective(string qualifier, string mechanism, s
case SpfMechanism.Include:
directive.Include = value;

if (Regex.Match(value, "^([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,}$").Length != 1)
{
throw new SpfInvalidException($"Include must be a domain name. The include value '{value}' fails");
}

break;

case SpfMechanism.IP4:
Expand Down

0 comments on commit 829c471

Please sign in to comment.