ValiMail / authentication-headers

library for the generation of email authentication headers
Other
16 stars 4 forks source link

AttributeError: 'NoneType' object has no attribute 'decode' in check_arc. #31

Closed msapiro closed 9 months ago

msapiro commented 9 months ago

I have a message that produces this, but it is unwieldy and I tried to edit it down, but that produced a different issue. Here's a traceback

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/mailman/mm/venv/lib/python3.9/site-packages/mailman/utilities/retry.py", line 44, in f_retry
    return f(*args, **kwargs)
  File "/opt/mailman/mm/venv/lib/python3.9/site-packages/mailman/handlers/validate_authenticity.py", line 93, in authenticate
    auth_result = authenticate_message(
  File "/opt/mailman/mm/venv/lib/python3.9/site-packages/authheaders/__init__.py", line 416, in authenticate_message
    arc_result = check_arc(msg, None, dnsfunc=dnsfunc)
  File "/opt/mailman/mm/venv/lib/python3.9/site-packages/authheaders/__init__.py", line 316, in check_arc
    return ARCAuthenticationResult(result=cv.decode('ascii'), result_comment=comment)
AttributeError: 'NoneType' object has no attribute 'decode'

The relevant code is:

def check_arc(msg, logger=None, dnsfunc=None):
    """ Compute the chain validation status of an inbound message.
    @param msg: an RFC822 formatted message (with either \\n or \\r\\n line endings)
    @param logger: An optional logger
    @param dnsfunc: An optional dns lookup function (intended for testing)
    """

    a = ARC(msg)
    try:
        if(dnsfunc):
            cv, results, comment = a.verify(dnsfunc=dnsfunc)
        else:
            cv, results, comment = a.verify()
    except DKIMException as e:
        cv, results, comment = CV_Fail, [], "%s" % e
    except DNSException as e:
        cv, results, comment = CV_Fail, [], "%s" % e
    except Exception as e:
        cv, results, comment = CV_Fail, [], "%s" % e
    if comment == 'success':
        comment = None
    return ARCAuthenticationResult(result=cv.decode('ascii'), result_comment=comment)

The problem is the verify method of the ARC instance can return cv = None per lines 1186-1188 in dkim/init.py

    for result in result_data:
      if result['cv'] == CV_Fail:
        return None, result_data, "ARC-Seal[%d] reported failure, the chain is terminated" % result['instance']

and this results in the exception.

kitterma commented 9 months ago

Thanks. Great bug report.

Scott K

kitterma commented 9 months ago

Thanks. Fixed in git.

kitterma commented 9 months ago

Fixed in 0.16.2.