solarissmoke / php-dmarc

A simple DMARC report parser written in PHP
Other
70 stars 21 forks source link

Data Truncated dkim_result #9

Closed warlord0 closed 8 years ago

warlord0 commented 8 years ago

With one of my reports I see the following SQL failure.

PHP Fatal error:  Uncaught PDOException: SQLSTATE[01000]: Warning: 1265 Data truncated for column 'dkim_result' at row 1 in /home/warlord/dmarc/vendor/solaris/php-dmarc/Solaris/DmarcAggregateParser.php:104
Stack trace:
#0 /home/warlord/dmarc/vendor/solaris/php-dmarc/Solaris/DmarcAggregateParser.php(104): PDOStatement->execute(Array)
#1 /home/warlord/dmarc/dmarc.php(32): Solaris\DmarcAggregateParser->parse(Array)
#2 {main}
  thrown in /home/warlord/dmarc/vendor/solaris/php-dmarc/Solaris/DmarcAggregateParser.php on line 104

This is caused by AOL not returning a dkim result in the XML report (I beautified it for clarity):

<?xml version="1.0" encoding="windows-1252"?>
    <feedback xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns1='http://dmarc.org/dmarc-xml/0.1' xsi:schemaLocation='http://dmarc.org/dmarc-xml/0.1 dmarc_agg_report.xsd'>
        <report_metadata>
            <org_name>AOL</org_name>
            <email>postmaster@aol.com</email>
            <report_id>mydomain.uk_1478476800</report_id>
            <date_range>
                <begin>1478390400</begin>
                <end>1478476800</end>
            </date_range>
        </report_metadata>
        <policy_published>
            <domain>mydomain.uk</domain>
            <adkim>r</adkim>
            <aspf>r</aspf>
            <p>none</p>
            <sp>none</sp>
            <pct>100</pct>
        </policy_published>
        <record>
            <row>
                <source_ip>212.100.244.249</source_ip>
                <count>1</count>
                <policy_evaluated>
                    <disposition>none</disposition>
                    <spf>fail</spf>
                </policy_evaluated>
            </row>
            <identifiers>
                <header_from>mydomain.uk</header_from>
            </identifiers>
            <auth_results>
                <dkim>
                    <domain>not.evaluated</domain>
                    <result>none</result>
                </dkim>
                <spf>
                    <domain>cgov.cuttlefish.com</domain>
                    <scope>mfrom</scope>
                    <result>pass</result>
                </spf>
            </auth_results>
        </record>
        <record>
            <row>
                <source_ip>82.3.0.0</source_ip>
                <count>1</count>
                <policy_evaluated>
                    <disposition>none</disposition>
                    <dkim>pass</dkim>
                    <spf>pass</spf>
                </policy_evaluated>
            </row>
            <identifiers>
                <header_from>mydomain.uk</header_from>
            </identifiers>
            <auth_results>
                <dkim>
                    <domain>mydomain.uk</domain>
                    <result>pass</result>
                </dkim>
                <spf>
                    <domain>mydomain.uk</domain>
                    <scope>mfrom</scope>
                    <result>pass</result>
                </spf>
            </auth_results>
        </record>
    </feedback>
solarissmoke commented 8 years ago

This is AOL violating the specification, which clearly says that a dkim result should always be present.

I guess we have little choice but to make allowance for this... will look into it a little later.

warlord0 commented 8 years ago

I added in line 103 after the try {:

                    foreach (['dkim', 'spf'] as $type) {
                        if (!property_exists($row->policy_evaluated, $type))                        
                            $row->policy_evaluated->{$type} = 'none';                        
                    }
warlord0 commented 8 years ago

You'll have to forgive me if what I've done is wrong. Kinda new to github and pull requests. Thought I'd give it a try.

solarissmoke commented 8 years ago

Fixed in #12 .