Re: header_checks and regexes

2022-03-10 Thread Viktor Dukhovni
> On 10 Mar 2022, at 3:48 pm, Alex  wrote:
> 
> Can I use sender_checks to bypass a host like mail.coupahost.com? The
> client IP will constantly change, but I can rely on the sending domain
> to remain the same.

Conditional header checks require a milter or content filter that
can make such fine distinctions.  Postfix built-in header checks
are global.

-- 
Viktor.



Re: header_checks and regexes

2022-03-10 Thread Alex
Hi,

I now have these mime_header_checks working properly, but it turns out
there are companies sending legitimate invoices as HTML attachments,
ugh.

Mar  8 07:49:05 xavier postfix-118/cleanup[2084042]: C01C310024593:
reject: header Content-Disposition: attachment;?
filename=purchase_order.html from
a31-88.smtp-out.amazonses.com[54.240.31.88];
from=<0100017f6993716e-42efe44-02df-4144-a0cb-35f9b82890b7-000...@mail.coupahost.com>
to= proto=ESMTP
helo=: 5.7.1 ".html" file attachment
types not allowed

Can I use sender_checks to bypass a host like mail.coupahost.com? The
client IP will constantly change, but I can rely on the sending domain
to remain the same.

If so, how do I control the ordering to be sure the mime_header_checks
are processed after the sender_checks?


On Fri, Mar 4, 2022 at 5:15 PM Alex  wrote:
>
> Hi,
>
> > > I believe there's a dot missing in the first one, as in '.(386' but
> > > it's more than that, because I experimented with that too.
> >
> > No, it would have to be:  \.(386|...)
> > otherwise '.' just matches any character.  Your RE pattern is sloppy
> > in places, ... correct REs take some care.
>
> Yes, that is what I meant. I believe there were problems with the
> regex that I fixed, but I was also using header_checks instead of
> mime_header_checks.
>
> Just for completeness, here's what worked for me.
>
> Given the following attachment:
> --caef4405d964f4b8
> Content-Type: text/html; charset="US-ASCII"; name="download.html"
> Content-Disposition: attachment; filename="download.html"
> Content-Transfer-Encoding: base64
> Content-ID: 
> X-Attachment-Id: f_l0chj96g0
>
> TWFpbGd1biBNYWduaWZpY2VudCBBUEk=
> --caef4405d964f4b8--
>
> $ postmap -c /etc/postfix -q 'Content-Disposition: attachment;
> filename="download.html"' pcre:/etc/postfix/mime_header_checks.pcre
> REJECT ".html" file attachment types not allowed
>
> mime_header_checks = pcre:/etc/postfix/mime_header_checks.pcre
>
> /^Content-(Disposition|Type):\s+.+?(file)?name="?.+?\.(386|exe|ad[ept]|app|as[dpx]|ba[st]|bin|btm|cab|cb[lt]|cgi|chm|cil|cla(ss)?|cmd|cp[el]|crt|cs[chs]|cvp|dll|dot|drv|em(ai)?l|ex[_e]|fon|fxp|hlp|ht[ar]|in[fips]|html|isp|jar|jse?|keyreg|ksh|lib|lnk|md[abetw]|mht(m|ml)?|mp3|ms[ciopt]|nte|nws|obj|ocx|ops|ov.|pcd|pgm|pif|p[lm]|pot|pps|prg|reg|sc[rt]|sh[bs]?|slb|smm|sw[ft]|sys|url|vb[esx]?|vir|vmx|vxd|wm[dsz]|ws[cfh]|xlw|xms|\{[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}\})\b/
> REJECT ".$3" file attachment types not allowed
>
> Can I also ask a more general question? How are other people handling
> attachments such as those I've listed which really have no purpose
> these days but to spread malware?
>
> The vast majority of HTML attachments we receive are not malicious,
> but just silently quarantining them was leading to too many support
> requests.
>
> Thanks so much for your help.


Re: Long pause during SMTP conversation, timeout settings

2022-03-10 Thread Viktor Dukhovni
On Thu, Mar 10, 2022 at 10:35:01AM -0500, Wietse Venema wrote:

> > I am using a milter that uses a connection timeout of five minutes, ie
> > this milter simply closes the connection from Postfix after five minutes
> > of silence.
> 
> If the problem is that email arrives slowly (800 bytes/second) and
> you actually want to receive that email, then setting a short timeout
> on the Milter side is not helpful.

There could also be latency in any prior milters, and in processing RBL
lookups for individual recipients, plus any slow lookups in data
restrictions.  Milter connections overlap at least part of the envelope
processing, and when multiple milters are specified they're processed in
order.

-- 
Viktor.