linagora / james-project

Mirror of Apache James Project
Apache License 2.0
72 stars 62 forks source link

JAMES-3920 Fix SPF mailet back to AsynchronousSPFExecutor #4805

Closed chibenwa closed 5 months ago

vttranlina commented 6 months ago

New comment of bug reporter: https://issues.apache.org/jira/browse/JAMES-3920?focusedCommentId=17775777&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-17775777

vttranlina commented 6 months ago

After hours of debugging, I tend to think it is a bug of AsynchronousSPFExecutor (bug of spf resolver library)

the spfResult of AsynchronousSPFExecutor is the result of the case handler Exception inside this class. https://github.com/apache/james-jspf/blob/c95db10d829b462a3164d29a48be33b0c88a66b8/resolver/src/main/java/org/apache/james/jspf/executor/AsynchronousSPFExecutor.java#L82

The first error:

org.apache.james.jspf.core.exceptions.NoneException: No SPF record found for host: bytle.net
    at org.apache.james.jspf.policies.NoSPFRecordFoundPolicy.getSPFRecord(NoSPFRecordFoundPolicy.java:37)
    at org.apache.james.jspf.impl.SPF$SPFPolicyPostFilterChecker.checkSPF(SPF.java:174)
    at org.apache.james.jspf.executor.AsynchronousSPFExecutor.execute(AsynchronousSPFExecutor.java:59)
    at org.apache.james.jspf.impl.SPF.checkSPF(SPF.java:305)
    at org.apache.james.jspf.impl.SPFQuery.main(SPFQuery.java:112)

after that, I tried to remove NoSPFRecordFoundPolicy in SPF.getPolicies by comment line policies.add(new SPFPolicyPostFilterChecker(new NoSPFRecordFoundPolicy()));

I got another error:

java.lang.NullPointerException: Cannot invoke "org.apache.james.jspf.core.SPF1Record.iterator()" because "spfRecord" is null
    at org.apache.james.jspf.impl.SPF$SPFRecordChecker.checkSPF(SPF.java:89)
    at org.apache.james.jspf.executor.AsynchronousSPFExecutor.execute(AsynchronousSPFExecutor.java:59)
    at org.apache.james.jspf.impl.SPF.checkSPF(SPF.java:305)
    at org.apache.james.jspf.impl.SPFQuery.main(SPFQuery.java:112)

// Note that Nicolas reported

From the Jspf Assembly, version  1.03 :
java -cp ".\*;.\lib\*" org.apache.james.jspf.impl.SPFQuery --ip 192.99.55.226 --sender nico@bytle.net --helo beau.bytle.net

It because SPFQuery use DefaultSPF, and DefaultSPF use AsynchronousSPFExecutor, just change it to SynchronousSPFExecutor then SPFQuery will work as Nicolas expected

chibenwa commented 6 months ago

Yes there's an issue with AsynchronousSPFExecutor.

Can we put together an effort to look into JSPF, write a test reproducing, and fix it?

vttranlina commented 5 months ago

My pr for showing why the bug and the idea to resolve it: https://github.com/apache/james-jspf/pull/18 (note that: It just cheats for one case, It is not a over solution)

chibenwa commented 5 months ago

That's a good start!

chibenwa commented 5 months ago

https://github.com/apache/james-jspf/pull/19