mail icon indicating copy to clipboard operation
mail copied to clipboard

Undefined array key in DKIM validator

Open Externalnet opened this issue 2 years ago • 7 comments

Steps to reproduce

Use the mail app with a valid secure mailserver (configured with DKIM, SPF DMARC enabled)

Expected behavior

I recieve no error messeages in nexcloud.log

Actual behavior

generates an error in nextcloud.log

Mail app version

3.5.0

Mailserver or service

Postfix

Operating system

Ubuntu 22.04.3 LTS

PHP engine version

PHP 8.1

Web server

Apache (supported)

Database

MySQL

Additional info

{"reqId":"XZbzoJYTj37YYgyQX9OO","level":3,"time":"2024-01-03T08:51:46+00:00","remoteAddr":"<IPADDRESS>","user":"<EMAILADDRESS>","app":"PHP","method":"GET","url":"/index .php/apps/mail/api/messages/10491/dkim","message":"Undefined array key "t" at /var/www/html/nextcloud/apps/mail/vendor/phpmailer/dkimvalidator/src/Validator.php#140","userAgent":"Mozilla/5 .0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36","version":"28.0.1.1","data":{"app":"PHP"}}

Externalnet avatar Jan 03 '24 11:01 Externalnet

https://github.com/PHPMailer/DKIMValidator/issues/9?

ChristophWurst avatar Jan 03 '24 11:01 ChristophWurst

@ChristophWurst That indeed seems to fix the issue Thank you very much :-)

-->

line: 144 (Validator.php): if ((int) $dkimTags['x'] < (int) $dkimTags['t']) { MUST BE: if ( isset($dkimTags['t']) && ((int) $dkimTags['x'] < (int) $dkimTags['t']) ) {

Externalnet avatar Jan 03 '24 11:01 Externalnet

@ChristophWurst Looks quiet over in that repo and I'm doubtful a PR will go anywhere. Think we should fork it or did you already have something else in mind?

joshtrichards avatar Jan 23 '24 00:01 joshtrichards

Sending a patch upstream would still be nice. We can then make a copy into our repo and use something like https://packagist.org/packages/cweagans/composer-patches to avoid a full fork.

ChristophWurst avatar Jan 23 '24 07:01 ChristophWurst

i made a pr hoping this will be fixed this is my first pr in the open source world

https://github.com/angrychimp/php-dkim/pull/14/commits/3d90eff0e420c0f42e2112cd7e7ba1de884a7d5f

blackstormlab avatar Apr 12 '24 02:04 blackstormlab

I've been getting the following error: Undefined array key 1 at /var/www/nextcloud/apps/mail/vendor/phpmailer/dkimvalidator/src/Validator.php#52

It looks like the explode function might not always return an array with two elements.

            //Split into tags
            $dkimTags = explode(';', $signatureToProcess);
            foreach ($dkimTags as $tagIndex => $tagContent) {
                [$tagName, $tagValue] = explode('=', trim($tagContent), 2);
                unset($dkimTags[$tagIndex]);
                if ($tagName === '') {
                    continue;
                }
                $dkimTags[$tagName] = $tagValue;
            }

Possible solution is to skip the current iteration of the loop if the $tagContent string doesn't contain the '=' character.

  //Split into tags
  $dkimTags = explode(';', $signatureToProcess);
  foreach ($dkimTags as $tagIndex => $tagContent) {
      $tagParts = explode('=', trim($tagContent), 2);
      if (count($tagParts) < 2) {
          continue;
      }
      [$tagName, $tagValue] = $tagParts;
      unset($dkimTags[$tagIndex]);
      if ($tagName === '') {
          continue;
      }
      $dkimTags[$tagName] = $tagValue;
  }

I'm gonna give this a go and see what happens.

dustbro avatar Jun 14 '24 20:06 dustbro

So far, so good.

dustbro avatar Jun 16 '24 12:06 dustbro