Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xbill.DNS.lookup.NoSuchRRSetException;
import org.xbill.DNS.WireParseException;

/**
* Synchronous implementation of SPFExecuter. All queries will get executed synchronously
Expand Down Expand Up @@ -90,7 +91,16 @@ private void handleCont(SPFSession session, FutureSPFResult result, DNSLookupCon
if (e instanceof IOException && e.getMessage().startsWith("Timed out ")) {
e = new TimeoutException(e.getMessage());
}
if (e instanceof NoSuchRRSetException) {

/**
* When exceptions occur trying to resolve the DNS response, we must do some clean
* up handling or the request will end up hanging.
*
* NOTE — The org.xbill.DNS.WireParseException gets triggered if the SPF record is truncated
* due to too many lookups. There might be other types of DNS exceptions that need
* to be caught as well.
*/
if ((e instanceof NoSuchRRSetException) || (e instanceof WireParseException)) {
try {
DNSLookupContinuation dnsLookupContinuation = cont.getListener().onDNSResponse(new DNSResponse(new ArrayList<>()), session);
handleCont(session, result, dnsLookupContinuation, checker);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,16 @@ public void test() {
assertEquals("Received-SPF: pass (spfCheck: domain of linagora.com designates 109.197.176.25 as permitted sender) client-ip=109.197.176.25; envelope-from=nico@linagora.com; helo=linagora.com;",
result.getHeader());
}

@Test
public void shouldParseWireParseExceptionRecordTruncated() {
SPF spf = new DefaultSPF();
SPFResult result = spf.checkSPF("170.146.224.15", "HelpDesk@arcofmc.org", "arcofmc.org");
System.out.println(result.getResult());
System.out.println(result.getExplanation());
System.out.println(result.getHeader());
assertEquals("permerror", result.getResult());
assertEquals("Received-SPF: permerror (spfCheck: Error in processing SPF Record) client-ip=170.146.224.15; envelope-from=HelpDesk@arcofmc.org; helo=arcofmc.org;",
result.getHeader());
}
}