public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Lorenz Stechauner <l.stechauner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-access-control] fix #1500: permission path syntax check for access control
Date: Fri, 16 Apr 2021 14:34:38 +0200	[thread overview]
Message-ID: <20210416123438.93188-1-l.stechauner@proxmox.com> (raw)

Syntax for permission paths is now checked on API calls for
creation or update on permissions.

Signed-off-by: Lorenz Stechauner <l.stechauner@proxmox.com>
---
 PVE/API2/ACL.pm      |  4 ++++
 PVE/AccessControl.pm | 31 +++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/PVE/API2/ACL.pm b/PVE/API2/ACL.pm
index c340267..857c672 100644
--- a/PVE/API2/ACL.pm
+++ b/PVE/API2/ACL.pm
@@ -141,6 +141,10 @@ __PACKAGE__->register_method ({
 	my $path = PVE::AccessControl::normalize_path($param->{path});
 	raise_param_exc({ path => "invalid ACL path '$param->{path}'" }) if !$path;
 
+	if (!$param->{delete} && !PVE::AccessControl::check_path($path)) {
+	    raise_param_exc({ path => "invalid ACL path '$param->{path}'" });
+	}
+
 	PVE::AccessControl::lock_user_config(
 	    sub {
 
diff --git a/PVE/AccessControl.pm b/PVE/AccessControl.pm
index 8b5be1e..5ac2df2 100644
--- a/PVE/AccessControl.pm
+++ b/PVE/AccessControl.pm
@@ -60,6 +60,24 @@ cfs_register_file('priv/tfa.cfg',
 		  \&parse_priv_tfa_config,
 		  \&write_priv_tfa_config);
 
+sub get_permission_paths {
+	return (
+	'/',
+	'/access',
+	'/access/groups',
+	'/access/realm',
+	'/nodes',
+	'/nodes/{node}',
+	'/pool',
+	'/pool/{poolid}',
+	'/sdn',
+	'/storage',
+	'/storage/{storage}',
+	'/vms',
+	'/vms/{vmid}',
+    )
+}
+
 sub verify_username {
     PVE::Auth::Plugin::verify_username(@_);
 }
@@ -929,6 +947,19 @@ sub normalize_path {
     return $path;
 }
 
+sub check_path {
+    my $path = normalize_path(shift);
+    my @regex_str_arr = ();
+    foreach (get_permission_paths()) {
+	    my $regex_str = $_;
+	$regex_str =~ s/\{vmid\}/\\d{3,}/;
+	$regex_str =~ s/\{[a-z]+\}/[[:alnum:]\\.\\-\\_]+/;
+	push(@regex_str_arr, $regex_str);
+    }
+    my $regex_str = '^(' . join('|', @regex_str_arr) . ')$';
+    return $path =~ m@$regex_str@;
+}
+
 PVE::JSONSchema::register_format('pve-groupid', \&verify_groupname);
 sub verify_groupname {
     my ($groupname, $noerr) = @_;
-- 
2.20.1




             reply	other threads:[~2021-04-16 12:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-16 12:34 Lorenz Stechauner [this message]
2021-04-16 13:09 ` Thomas Lamprecht

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=20210416123438.93188-1-l.stechauner@proxmox.com \
    --to=l.stechauner@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