public inbox for pmg-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pmg-devel] [PATCH pmg-api 1/1] rulesystem: limit linelength of disclaimer to 998 bytes
@ 2021-11-22 19:50 Stoiko Ivanov
  2021-11-23  6:16 ` Thomas Lamprecht
  0 siblings, 1 reply; 2+ messages in thread
From: Stoiko Ivanov @ 2021-11-22 19:50 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

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)

reported in our community forum:
https://forum.proxmox.com/threads/dkim-body-has-been-altered-when-enabling-disclaimer-function.97919/

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
 src/PMG/RuleDB/Disclaimer.pm | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/PMG/RuleDB/Disclaimer.pm b/src/PMG/RuleDB/Disclaimer.pm
index 1b1accf..1c81b03 100644
--- a/src/PMG/RuleDB/Disclaimer.pm
+++ b/src/PMG/RuleDB/Disclaimer.pm
@@ -84,6 +84,10 @@ sub save {
     defined($self->{ogroup}) || die "undefined object attribute: ERROR";
     defined($self->{value}) || die "undefined object attribute: ERROR";
 
+    if ($self->{value} =~ /^.{998,}$/m) {
+	die "too long line in disclaimer - breaks RFC 5322!\n";
+    }
+
     if (defined ($self->{id})) {
 	# update
 	
-- 
2.30.2





^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [pmg-devel] [PATCH pmg-api 1/1] rulesystem: limit linelength of disclaimer to 998 bytes
  2021-11-22 19:50 [pmg-devel] [PATCH pmg-api 1/1] rulesystem: limit linelength of disclaimer to 998 bytes Stoiko Ivanov
@ 2021-11-23  6:16 ` Thomas Lamprecht
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2021-11-23  6:16 UTC (permalink / raw)
  To: Stoiko Ivanov, pmg-devel

On 22.11.21 20:50, 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
> 
> 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)
> 
> reported in our community forum:
> https://forum.proxmox.com/threads/dkim-body-has-been-altered-when-enabling-disclaimer-function.97919/
> 
> Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
> ---
>  src/PMG/RuleDB/Disclaimer.pm | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/src/PMG/RuleDB/Disclaimer.pm b/src/PMG/RuleDB/Disclaimer.pm
> index 1b1accf..1c81b03 100644
> --- a/src/PMG/RuleDB/Disclaimer.pm
> +++ b/src/PMG/RuleDB/Disclaimer.pm
> @@ -84,6 +84,10 @@ sub save {
>      defined($self->{ogroup}) || die "undefined object attribute: ERROR";
>      defined($self->{value}) || die "undefined object attribute: ERROR";
>  
> +    if ($self->{value} =~ /^.{998,}$/m) {


1. a comment that the regex match is used to avoid the fact that the `length` function is
   working on characters (vs. bytes) only would be good, but..

2. regex isn't actually _that_ better, if one adds a `use utf8` it also matches chars and
   not bytes here

Maybe go for the more explicit variant? I think the following should work (but with encodings
involved one is never sure..)

if (length(Encode::encode("UTF-8", $self->{value})) > 998)

> +	die "too long line in disclaimer - breaks RFC 5322!\n";
> +    }
> +
>      if (defined ($self->{id})) {
>  	# update
>  	
> 





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-11-23  6:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-22 19:50 [pmg-devel] [PATCH pmg-api 1/1] rulesystem: limit linelength of disclaimer to 998 bytes Stoiko Ivanov
2021-11-23  6:16 ` Thomas Lamprecht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal