From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id A29921FF09C for ; Mon, 21 Sep 2026 15:57:09 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id BED1B2156B; Mon, 21 Sep 2026 15:57:05 +0200 (CEST) From: Arthur Bied-Charreton To: pve-devel@lists.proxmox.com Subject: [PATCH pve-common v3] fix #7077: schema: validate length before format and pattern Date: Mon, 21 Sep 2026 15:56:32 +0200 Message-ID: <20260921135701.475036-1-a.bied-charreton@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 1 AWL -0.893 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods RDNS_NONE 1.274 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record Message-ID-Hash: IJ7ZY4UID6ZYTGS2ID347AUI56XDL6CI X-Message-ID-Hash: IJ7ZY4UID6ZYTGS2ID347AUI56XDL6CI X-MailFrom: abied-charreton@jett.proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The JSON schema validation first checked input against the registered format function and pattern, and only then against min and max length. This caused length constraints when they were implicit in custom format verification functions or regex patterns, which resulted in generic format violation error messages instead of the more specific length violation. Change the validation order to check length constraints before registered formats and patterns. This is functionally equivalent, and comes with the UX advantage of providing more precise error messages in a lot of cases. Link: https://bugzilla.proxmox.com/show_bug.cgi?id=7077 Signed-off-by: Arthur Bied-Charreton --- Changes since v2: rebase onto master src/PVE/JSONSchema.pm | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm index 34f2949..ec2072a 100644 --- a/src/PVE/JSONSchema.pm +++ b/src/PVE/JSONSchema.pm @@ -1627,31 +1627,31 @@ sub check_prop { return; } - if (my $format = $schema->{format}) { - eval { check_format($format, $value, $path); }; - if ($@) { - add_error($errors, $path, "invalid format - $@"); + if (defined(my $max = $schema->{maxLength})) { + if (length($value) > $max) { + add_error($errors, $path, "value may only be $max characters long"); return; } } - if (my $pattern = $schema->{pattern}) { - if ($value !~ m/^$pattern\z/) { - add_error($errors, $path, "value does not match the regex pattern"); + if (defined(my $min = $schema->{minLength})) { + if (length($value) < $min) { + add_error($errors, $path, "value must be at least $min characters long"); return; } } - if (defined(my $max = $schema->{maxLength})) { - if (length($value) > $max) { - add_error($errors, $path, "value may only be $max characters long"); + if (my $format = $schema->{format}) { + eval { check_format($format, $value, $path); }; + if ($@) { + add_error($errors, $path, "invalid format - $@"); return; } } - if (defined(my $min = $schema->{minLength})) { - if (length($value) < $min) { - add_error($errors, $path, "value must be at least $min characters long"); + if (my $pattern = $schema->{pattern}) { + if ($value !~ m/^$pattern\z/) { + add_error($errors, $path, "value does not match the regex pattern"); return; } } -- 2.47.3