* [pmg-devel] [PATCH pmg-api v2] rulesystem: limit linelength of disclaimer to 998 bytes
@ 2021-11-24 21:00 Stoiko Ivanov
2021-11-25 8:28 ` [pmg-devel] applied: " Thomas Lamprecht
0 siblings, 1 reply; 2+ messages in thread
From: Stoiko Ivanov @ 2021-11-24 21:00 UTC (permalink / raw)
To: pmg-devel
As described in
http://www.postfix.org/postconf.5.html#smtp_line_length_limit
postfix splits lines which are longer by inserting <cr><lf><space> 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 <s.ivanov@proxmox.com>
---
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* [pmg-devel] applied: [PATCH pmg-api v2] rulesystem: limit linelength of disclaimer to 998 bytes
2021-11-24 21:00 [pmg-devel] [PATCH pmg-api v2] rulesystem: limit linelength of disclaimer to 998 bytes Stoiko Ivanov
@ 2021-11-25 8:28 ` Thomas Lamprecht
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2021-11-25 8:28 UTC (permalink / raw)
To: Stoiko Ivanov, pmg-devel
On 24.11.21 22:00, Stoiko Ivanov wrote:
> As described in
> http://www.postfix.org/postconf.5.html#smtp_line_length_limit
>
> postfix splits lines which are longer by inserting <cr><lf><space> 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 <s.ivanov@proxmox.com>
> ---
> v2->v1:
> * incorporated Thomas' feedback - huge thanks!
> * replaced the 2/3 occurences of encode('UTF-8',...) by a temporary varialbe
great that it could roughly stay the same amount of work, the memory scan should
be rather cheap.
> * 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(-)
>
>
applied, thanks!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-11-25 8:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-24 21:00 [pmg-devel] [PATCH pmg-api v2] rulesystem: limit linelength of disclaimer to 998 bytes Stoiko Ivanov
2021-11-25 8:28 ` [pmg-devel] applied: " Thomas Lamprecht
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox