tierpod / dmarc-report-converter

Convert dmarc reports from xml to human-readable formats
MIT License
237 stars 25 forks source link

Error without outputting json file when report contains empty record #36

Closed hostep closed 6 months ago

hostep commented 7 months ago

Hi there

Thanks for this awesome tool, I've been experimenting with it for the last 2 weeks or so and it works very good! However, today I ran into a problem, that only seems to happen when choosing json as output format.

When running the tool today, it suddenly stopped with this error:

2024/03/07 08:11:18 [ERROR] processFiles: json: error calling MarshalJSON for type dmarc.Report: json: unsupported value: NaN

It took me a while to figure out where the problem came from, but eventually I found an empty generated json file and I could trace back to a report that contained something like this:

    <record>
        <row>
            <source_ip/>
            <count>0</count>
            <policy_evaluated>
                <disposition/>
                <dkim/>
                <spf/>
            </policy_evaluated>
        </row>
        <identifiers>
            <header_from/>
        </identifiers>
        <auth_results>
            <spf>
                <domain/>
                <result/>
            </spf>
        </auth_results>
    </record>

Not sure why a reporter would send such an empty report, but it happened.

When choosing html as output format, this tool is able to generate a report without errors, but not with json output format. Would be great if this bug could be fixed somehow, either by fixing the json generating logic, or by just skip outputting a report since this one contains no useful info

(would also be nice if this tool had some verbose flag, that you can use to output debug info, for example in this case it would have been nice if I could find the problematic report's filename while running in verbose mode)

Thanks!

tierpod commented 7 months ago

Thank you for report, it's a bug, I'll try to investigate it.

tierpod commented 6 months ago

Hello. I added this edge case to tests and fixed the problem. v0.7.0 was released with this fix included (and other major dependencies updates). Thank you for your detailed report!

would also be nice if this tool had some verbose flag

You can add log_debug: true to config file to see more log messages. Also, you can add debug: true into input -> imap section to see detailed imap conversation.

Unfortunately, I haven't found easy way to extract more details (e.g. position) from default json.Marshal error message yet.

hostep commented 6 months ago

Super, thank you very much!