From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 3B14081943 for ; Wed, 24 Nov 2021 22:01:24 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 18E7F248AE for ; Wed, 24 Nov 2021 22:00:54 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id EA425248A2 for ; Wed, 24 Nov 2021 22:00:51 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 841F046068 for ; Wed, 24 Nov 2021 22:00:51 +0100 (CET) From: Stoiko Ivanov To: pmg-devel@lists.proxmox.com Date: Wed, 24 Nov 2021 22:00:48 +0100 Message-Id: <20211124210048.78905-1-s.ivanov@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.307 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pmg-devel] [PATCH pmg-api v2] rulesystem: limit linelength of disclaimer to 998 bytes X-BeenThere: pmg-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Nov 2021 21:01:24 -0000 As described in http://www.postfix.org/postconf.5.html#smtp_line_length_limit postfix splits lines which are longer by inserting to adhere with RFC 5322 (section 2.1.1): https://datatracker.ietf.org/doc/html/rfc5322#section-2.1.1 (or actually section 4.5.3.1.6. where characters are translated to octets) If a longer line is part of the disclaimer pmg-smtp-filter adds it without this modification, which breaks DKIM signatures (since the body is modified by postfix after the body hash is computed) regular-expression matching is used instead of length(), because the limit is on line-length (and a disclaimer can contain multiple lines) reported in our community forum: https://forum.proxmox.com/threads/.97919/ Signed-off-by: Stoiko Ivanov --- v2->v1: * incorporated Thomas' feedback - huge thanks! * replaced the 2/3 occurences of encode('UTF-8',...) by a temporary varialbe * read up quite a bit on the magic world of encoding) * verified that the encoded value is indeed the one we want to compare against src/PMG/RuleDB/Disclaimer.pm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/PMG/RuleDB/Disclaimer.pm b/src/PMG/RuleDB/Disclaimer.pm index 1b1accf..d3003b2 100644 --- a/src/PMG/RuleDB/Disclaimer.pm +++ b/src/PMG/RuleDB/Disclaimer.pm @@ -84,12 +84,17 @@ sub save { defined($self->{ogroup}) || die "undefined object attribute: ERROR"; defined($self->{value}) || die "undefined object attribute: ERROR"; + my $value = encode('UTF-8', $self->{value}); + if ($value =~ /^.{998,}$/m) { + die "too long line in disclaimer - breaks RFC 5322!\n"; + } + if (defined ($self->{id})) { # update $ruledb->{dbh}->do( "UPDATE Object SET Value = ? WHERE ID = ?", - undef, encode('UTF-8', $self->{value}), $self->{id}); + undef, $value, $self->{id}); } else { # insert @@ -98,7 +103,7 @@ sub save { "INSERT INTO Object (Objectgroup_ID, ObjectType, Value) " . "VALUES (?, ?, ?);"); - $sth->execute($self->ogroup, $self->otype, encode('UTF-8', $self->{value})); + $sth->execute($self->ogroup, $self->otype, $value); $self->{id} = PMG::Utils::lastid($ruledb->{dbh}, 'object_id_seq'); } -- 2.30.2