From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id A0257A17D8 for ; Thu, 15 Jun 2023 13:13:03 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 7709625A51 for ; Thu, 15 Jun 2023 13:12:33 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Thu, 15 Jun 2023 13:12:33 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id A358B45915; Thu, 15 Jun 2023 13:12:32 +0200 (CEST) Message-ID: <320da32f-cb75-3f4c-4535-c52736325915@proxmox.com> Date: Thu, 15 Jun 2023 13:12:32 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Wolfgang Bumiller Cc: pve-devel@lists.proxmox.com References: <20230615093215.1755347-1-d.csapak@proxmox.com> From: Dominik Csapak In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.015 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [jsonschema.pm] Subject: Re: [pve-devel] [PATCH RFC common] fix #4778: fix boolean type check for json parameters over the api X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Jun 2023 11:13:03 -0000 On 6/15/23 11:51, Wolfgang Bumiller wrote: > On Thu, Jun 15, 2023 at 11:32:15AM +0200, Dominik Csapak wrote: >> if a real json boolean is sent via the api, $value is a >> JSON::PP::Boolean here instead of a string/scalar >> >> so we should validate that too >> >> the $value itself can be used normally in conditions like >> ---- >> if ($value) { >> ---- >> >> This worked for most api calls by accident before commit: >> f398a3d ("proxy request: forward json content type and parameters") >> >> since when the call was proxied to pvedaemon or another node, it would >> get translated to a www-form-urlencoded parameter instead of json >> and most (if not all) api calls that accept boolean parameters in the >> body (POST/PUT) are forwarded to pvedaemon >> >> Signed-off-by: Dominik Csapak >> --- >> i tested this with a few api calls (e.g. in the user creation/edit) >> and it worked, but maybe the safer option would be to convert those >> values to '1'/'0' ? we could reuse the 'normalize_legacy_param_formats' >> function in RESTHandler for this, but this only checks the top level >> parameters (which would be enough for now) >> >> src/PVE/JSONSchema.pm | 5 ++++- >> 1 file changed, 4 insertions(+), 1 deletion(-) >> >> diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm >> index 85d47f2..ebe443f 100644 >> --- a/src/PVE/JSONSchema.pm >> +++ b/src/PVE/JSONSchema.pm >> @@ -10,6 +10,7 @@ use Devel::Cycle -quiet; # todo: remove? >> use PVE::Tools qw(split_list $IPV6RE $IPV4RE); >> use PVE::Exception qw(raise); >> use HTTP::Status qw(:constants); >> +use JSON; >> use Net::IP qw(:PROC); >> use Data::Dumper; >> >> @@ -1039,7 +1040,9 @@ sub check_type { >> # qr// regexes can be used as strings and make sense for format=regex >> return 1; >> } else { >> - if ($vt) { > > ^ I think we should keep this > >> + if ($type eq 'boolean' && JSON::is_bool($value)) { > > ^ and just have this _inside_ the `if ($vt)` case - since that should be > set in this case? > sure makes sense, i'll wait with the next version if someone has any additional thing to say about the general approach (@thomas? @fabian? @fiona?)