public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH v2 pve-access-control] fix #1500: permission path syntax check for access control
@ 2021-04-19  7:16 Lorenz Stechauner
  2021-04-19  9:52 ` [pve-devel] applied: " Thomas Lamprecht
  0 siblings, 1 reply; 3+ messages in thread
From: Lorenz Stechauner @ 2021-04-19  7:16 UTC (permalink / raw)
  To: pve-devel

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>
---
 Regex is now hardcoded,
 removed get_permission_paths,
 check_path does not call normalize_path anymore,
 indentation fix

 PVE/API2/ACL.pm      |  4 ++++
 PVE/AccessControl.pm | 18 ++++++++++++++++++
 2 files changed, 22 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..4ef1080 100644
--- a/PVE/AccessControl.pm
+++ b/PVE/AccessControl.pm
@@ -929,6 +929,24 @@ sub normalize_path {
     return $path;
 }
 
+sub check_path {
+    return shift =~ m!^(
+	/
+	|/access
+	|/access/groups
+	|/access/realm
+	|/nodes
+	|/nodes/[[:alnum:]\.\-\_]+
+	|/pool
+	|/pool/[[:alnum:]\.\-\_]+
+	|/sdn
+	|/storage
+	|/storage/[[:alnum:]\.\-\_]+
+	|/vms
+	|/vms/\d{3,}
+    )$!xs;
+}
+
 PVE::JSONSchema::register_format('pve-groupid', \&verify_groupname);
 sub verify_groupname {
     my ($groupname, $noerr) = @_;
-- 
2.20.1




^ permalink raw reply	[flat|nested] 3+ messages in thread

* [pve-devel] applied: [PATCH v2 pve-access-control] fix #1500: permission path syntax check for access control
  2021-04-19  7:16 [pve-devel] [PATCH v2 pve-access-control] fix #1500: permission path syntax check for access control Lorenz Stechauner
@ 2021-04-19  9:52 ` Thomas Lamprecht
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Lamprecht @ 2021-04-19  9:52 UTC (permalink / raw)
  To: Proxmox VE development discussion, Lorenz Stechauner

On 19.04.21 09:16, Lorenz Stechauner wrote:
> 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>
> ---
>  Regex is now hardcoded,
>  removed get_permission_paths,
>  check_path does not call normalize_path anymore,
>  indentation fix
> 
>  PVE/API2/ACL.pm      |  4 ++++
>  PVE/AccessControl.pm | 18 ++++++++++++++++++
>  2 files changed, 22 insertions(+)
> 
>

applied, thanks! nice patch mail format and work-wise all top-notch, nice!




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [pve-devel] [PATCH v2 pve-access-control] fix #1500: permission path syntax check for access control
@ 2021-04-19  9:42 Dietmar Maurer
  0 siblings, 0 replies; 3+ messages in thread
From: Dietmar Maurer @ 2021-04-19  9:42 UTC (permalink / raw)
  To: Proxmox VE development discussion, Lorenz Stechauner

FYI, I do it without any regex in rust:

https://git.proxmox.com/?p=proxmox-backup.git;a=blob;f=src/config/acl.rs;h=61e507ec42bf5a30f64f56564a1fb107d148fb7b;hb=HEAD#l272

I guess this is faster (at least in rust).


> On 04/19/2021 9:16 AM Lorenz Stechauner <l.stechauner@proxmox.com> wrote:
> 
>  
> 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>
> ---
>  Regex is now hardcoded,
>  removed get_permission_paths,
>  check_path does not call normalize_path anymore,
>  indentation fix
> 
>  PVE/API2/ACL.pm      |  4 ++++
>  PVE/AccessControl.pm | 18 ++++++++++++++++++
>  2 files changed, 22 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..4ef1080 100644
> --- a/PVE/AccessControl.pm
> +++ b/PVE/AccessControl.pm
> @@ -929,6 +929,24 @@ sub normalize_path {
>      return $path;
>  }
>  
> +sub check_path {
> +    return shift =~ m!^(
> +	/
> +	|/access
> +	|/access/groups
> +	|/access/realm
> +	|/nodes
> +	|/nodes/[[:alnum:]\.\-\_]+
> +	|/pool
> +	|/pool/[[:alnum:]\.\-\_]+
> +	|/sdn
> +	|/storage
> +	|/storage/[[:alnum:]\.\-\_]+
> +	|/vms
> +	|/vms/\d{3,}
> +    )$!xs;
> +}
> +
>  PVE::JSONSchema::register_format('pve-groupid', \&verify_groupname);
>  sub verify_groupname {
>      my ($groupname, $noerr) = @_;
> -- 
> 2.20.1
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-04-19  9:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-19  7:16 [pve-devel] [PATCH v2 pve-access-control] fix #1500: permission path syntax check for access control Lorenz Stechauner
2021-04-19  9:52 ` [pve-devel] applied: " Thomas Lamprecht
2021-04-19  9:42 [pve-devel] " Dietmar Maurer

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