public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Hannes Laimer <h.laimer@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-access-control] ldap: decode attribute values as UTF-8
Date: Fri, 17 Apr 2026 13:04:51 +0200	[thread overview]
Message-ID: <20260417110451.134766-1-h.laimer@proxmox.com> (raw)

Net::LDAP's get_value() returns octets as raw bytes as received over
the wire. Per RFC 4511 [0] LDAPString values are UTF-8 encoded, but
Perl does not know that.

PVE::Tools::encode_text() then re-encodes the bytes as UTF-8, producing
a double-encoded sequence that ends up in user.cfg for any non-ASCII
name. On read decode_text() only undoes one layer, so the GUI and CLI
render the partially-decoded middle form instead of the original text.

Decode the value as UTF-8 right after retrieval so that downstream
code operates on a proper character string and encode_text() produces
single-encoded UTF-8.

[0] https://datatracker.ietf.org/doc/html/rfc4511#section-4.1.2

Reported-by: https://forum.proxmox.com/threads/support-for-unicode-characters-in-usernames.182832/
Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
 src/PVE/Auth/LDAP.pm | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/PVE/Auth/LDAP.pm b/src/PVE/Auth/LDAP.pm
index 093863c..ae17878 100755
--- a/src/PVE/Auth/LDAP.pm
+++ b/src/PVE/Auth/LDAP.pm
@@ -3,6 +3,8 @@ package PVE::Auth::LDAP;
 use strict;
 use warnings;
 
+use Encode;
+
 use PVE::Auth::Plugin;
 use PVE::JSONSchema;
 use PVE::LDAP;
@@ -330,6 +332,11 @@ sub get_users {
         foreach my $attr (keys %$user_attributes) {
             if (my $ours = $ldap_attribute_map->{$attr}) {
                 my $value = $user_attributes->{$attr}->[0];
+                # Net::LDAP returns octets; DirectoryString-syntax attributes
+                # (sn, givenName, mail, description, ...) are UTF-8 on the
+                # wire, so mark them as such before we hand them off to the
+                # rest of the stack, which assumes character strings.
+                $value = Encode::decode('UTF-8', $value) if defined($value);
                 eval { verify_sync_attribute_value($ours, $value) };
                 if (my $err = $@) {
                     warn "skipping attribute mapping '$attr'->'$ours' for user '$username' - $err";
-- 
2.47.3





                 reply	other threads:[~2026-04-17 11:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260417110451.134766-1-h.laimer@proxmox.com \
    --to=h.laimer@proxmox.com \
    --cc=pve-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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal