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 151D175912 for ; Thu, 22 Apr 2021 10:09:28 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 02CED18B95 for ; Thu, 22 Apr 2021 10:08:58 +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 id 5F6D018B8B for ; Thu, 22 Apr 2021 10:08:57 +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 2F4C745BCC for ; Thu, 22 Apr 2021 10:08:57 +0200 (CEST) Message-ID: <4d601bee-3c3d-a8a2-f376-01f1b100de4c@proxmox.com> Date: Thu, 22 Apr 2021 10:08:56 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Thunderbird/88.0 Content-Language: en-US To: Proxmox VE development discussion , =?UTF-8?Q?Fabian_Gr=c3=bcnbichler?= References: <20210421115943.100078-1-l.stechauner@proxmox.com> <1619074571.4va2rkfmko.astroid@nora.none> From: Thomas Lamprecht In-Reply-To: <1619074571.4va2rkfmko.astroid@nora.none> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.021 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment NICE_REPLY_A -0.001 Looks like a legit reply (A) SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [httpserver.pm] Subject: Re: [pve-devel] [PATCH manager] fix #3389: Skip CSRF token check also for API tokens on file upload 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, 22 Apr 2021 08:09:28 -0000 On 22.04.21 10:05, Fabian Gr=C3=BCnbichler wrote: > On April 21, 2021 1:59 pm, Lorenz Stechauner wrote: >> On file upload, the check for CSRF tokens was already skipped >> when performing user authentication.This now happens for API >> tokens also. >> >> Signed-off-by: Lorenz Stechauner >> --- >> PVE/HTTPServer.pm | 34 +++++++++++++++++----------------- >> 1 file changed, 17 insertions(+), 17 deletions(-) >> >> diff --git a/PVE/HTTPServer.pm b/PVE/HTTPServer.pm >> index 64976c7c..63b8583e 100755 >> --- a/PVE/HTTPServer.pm >> +++ b/PVE/HTTPServer.pm >> @@ -79,8 +79,8 @@ sub auth_handler { >> =20 >> if ($require_auth) { >> if ($api_token) { >> + # returns tokenid actually >> $username =3D PVE::AccessControl::verify_token($api_token); >> - $rpcenv->set_user($username); #actually tokenid in this case >> } else { >> die "No ticket\n" if !$ticket; >> =20 >> @@ -94,25 +94,25 @@ sub auth_handler { >> die "No ticket\n" >> if ($rel_uri ne '/access/tfa' || $method ne 'POST'); >> } >> + } >> =20 >> - $rpcenv->set_user($username); >> - >> - if ($method eq 'POST' && $rel_uri =3D~ m|^/nodes/([^/]+)/storage= /([^/]+)/upload$|) { >> - my ($node, $storeid) =3D ($1, $2); >> - # we disable CSRF checks if $isUpload is set, >> - # to improve security we check user upload permission here >> - my $perm =3D { check =3D> ['perm', "/storage/$storeid", ['Datastore= =2EAllocateTemplate']] }; >> - $rpcenv->check_api2_permissions($perm, $username, {}); >> - $isUpload =3D 1; >> - } >> + $rpcenv->set_user($username); >> =20 >> - # we skip CSRF check for file upload, because it is >> - # difficult to pass CSRF HTTP headers with native html forms, >> - # and it should not be necessary at all. >> - my $euid =3D $>; >> - PVE::AccessControl::verify_csrf_prevention_token($username, $tok= en) >> - if !$isUpload && ($euid !=3D 0) && ($method ne 'GET'); >> + if ($method eq 'POST' && $rel_uri =3D~ m|^/nodes/([^/]+)/storage/([^= /]+)/upload$|) { >> + my ($node, $storeid) =3D ($1, $2); >> + # we disable CSRF checks if $isUpload is set, >> + # to improve security we check user upload permission here >> + my $perm =3D { check =3D> ['perm', "/storage/$storeid", ['Datast= ore.AllocateTemplate']] }; >> + $rpcenv->check_api2_permissions($perm, $username, {}); >> + $isUpload =3D 1; >> } >> + >> + # we skip CSRF check for file upload, because it is >> + # difficult to pass CSRF HTTP headers with native html forms, >> + # and it should not be necessary at all. >> + my $euid =3D $>; >> + PVE::AccessControl::verify_csrf_prevention_token($username, $token) >> + if !$isUpload && ($euid !=3D 0) && ($method ne 'GET'); >=20 > this verify_csrf_prevention_token call was never triggered for API=20 > tokens before, on purpose - one of the design goals of API tokens was t= o=20 > provide stateless API access without requiring round-trips like our=20 > regular, ticket-based sessions do. CSRF-prevention also does not make=20 > much sense outside of the browser context (whereas API tokens are for=20 > automated access by non-browser clients). >=20 > with this change we'd now suddenly require CSRF tokens for API tokens a= s=20 > well, and IIRC API tokens can't even get one of those (and even if they=20 > could, none of the existing clients would know about that and could no = > longer do any non-GET requests with tokens). >=20 > I think (but I haven't tested it!) that > - setting $isUpload for the API token case as well > - leaving the CSRF check limited to regular (non-API-token) authenticat= ion >=20 > should give us the desired effect without any side-effects. the actual = > upload handling is in PVE::APIServer::AnyEvent and just seems to check = > for $isUpload in the result of auth_handler. >=20 you're right, good catch! @Lorenz, care to send out a patch bringing it back it shape?