From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: Daniel Berteaud <daniel@firewall-services.com>
Cc: pmg-devel@lists.proxmox.com
Subject: Re: [pmg-devel] [PATCH pmg-api 1/1] [pmg-api]: fix #3098 : first check for exact domain match
Date: Tue, 27 Oct 2020 12:39:01 +0100 [thread overview]
Message-ID: <20201027123901.0117e0a5@rosa.proxmox.com> (raw)
In-Reply-To: <20201026105046.424454-2-daniel@firewall-services.com>
Hi,
Thank you very much for catching this, opening a report and directly
providing a patch!
The patch works as advertised (gave it a quick spin on my test-setup).
However I wonder if it wouldn't be better to address this by sorting
properly - instead of differentiating between exact match and first
matching subdomain we could match for the longest matching subdomain
(suggestion inline).
This should cover your issue as well as far as I can tell, and provide
fewer suprises regarding the chosen signing domain.
What do you think?
On Mon, 26 Oct 2020 11:50:46 +0100
Daniel Berteaud <daniel@firewall-services.com> wrote:
> When selecting the sending domain for the DKIM signature, we should first check for an exact match. If none is found, look for parent domains. This fixes the case where wrong signing domain can be added if sign_all is disabled and we sign both a parent and a child domain.
>
> Signed-off-by: Daniel Berteaud <daniel@firewall-services.com>
> ---
> src/PMG/DKIMSign.pm | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/src/PMG/DKIMSign.pm b/src/PMG/DKIMSign.pm
> index 7cb06a6..8fd9eed 100644
> --- a/src/PMG/DKIMSign.pm
> +++ b/src/PMG/DKIMSign.pm
> @@ -69,6 +69,14 @@ sub signing_domain {
> my $dkimdomains = PVE::INotify::read_file('dkimdomains');
> $dkimdomains = PVE::INotify::read_file('domains') if !scalar(%$dkimdomains);
>
> + # First check for an exact match in the domain list
> + foreach my $domain (sort keys %$dkimdomains) {
> + if ( $input_domain eq $domain ) {
> + $self->domain($domain);
> + return 1;
> + }
> + }
> + # If no exact match is found, check for parent/child domains
> foreach my $domain (sort keys %$dkimdomains) {
by replacing `sort keys %$dkimdomains` with:
`sort { length($b) <=> length($a) || $a cmp $b} keys %$dkimdomains`
(from the top of my head - without thorough tests) - sort longest domains
first and if the length is equal sort lexically
> if ( $input_domain =~ /\Q$domain\E$/i ) {
> $self->domain($domain);
next prev parent reply other threads:[~2020-10-27 11:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-26 10:50 [pmg-devel] [PATCH pmg-api 0/1] DKIM, " Daniel Berteaud
2020-10-26 10:50 ` [pmg-devel] [PATCH pmg-api 1/1] [pmg-api]: fix #3098 : " Daniel Berteaud
2020-10-27 11:39 ` Stoiko Ivanov [this message]
2020-10-27 11:46 ` Daniel Berteaud
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201027123901.0117e0a5@rosa.proxmox.com \
--to=s.ivanov@proxmox.com \
--cc=daniel@firewall-services.com \
--cc=pmg-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox