Commit 60630ac1 authored by Dietmar Maurer's avatar Dietmar Maurer

only allow pre-defined directories (avoid regex)

Just to be more secure.
parent 43138247
...@@ -265,16 +265,17 @@ sub handle_request { ...@@ -265,16 +265,17 @@ sub handle_request {
} }
if ($self->{dirs} && ($method eq 'GET')) { if ($self->{dirs} && ($method eq 'GET')) {
foreach my $dir (keys %{$self->{dirs}}) { # we only allow simple names
# we only allow simple names if ($uri =~ m!^(/\S+/)([a-zA-Z0-9\-\_\.]+)$!) {
if ($uri =~ m/^$dir([a-zA-Z0-9\-\_\.\/]+)$/) { my ($subdir, $file) = ($1, $2);
my $reluri = $1; if (my $dir = $self->{dirs}->{$subdir}) {
$reluri =~ s/\.\./XX/g; # do not allow '..' my $filename = "$dir$file";
my $filename = "$self->{dirs}->{$dir}$reluri";
my $fh = IO::File->new($filename) || my $fh = IO::File->new($filename) ||
die "unable to open file '$filename' - $!\n"; die "unable to open file '$filename' - $!\n";
send_file_start($self, $reqstate, $filename); send_file_start($self, $reqstate, $filename);
return; return;
} else {
print "FAILED\n"
} }
} }
} }
......
...@@ -44,11 +44,33 @@ $0 = "pveproxy"; ...@@ -44,11 +44,33 @@ $0 = "pveproxy";
PVE::APIDaemon::enable_debug() if $opt_debug; PVE::APIDaemon::enable_debug() if $opt_debug;
sub add_dirs {
my ($result_hash, $alias, $subdir) = @_;
$result_hash->{$alias} = $subdir;
my $wanted = sub {
my $dir = $File::Find::dir;
if ($dir =~m!^$subdir(.*)$!) {
my $name = "$alias$1/";
$result_hash->{$name} = "$dir/";
}
};
find({wanted => $wanted, follow => 0, no_chdir => 1}, $subdir);
}
my $cpid; my $cpid;
my $daemon; my $daemon;
eval { eval {
my $dirs = {};
add_dirs($dirs, '/pve2/ext4/', '/usr/share/pve-manager/ext4/');
add_dirs($dirs, '/pve2/images/' => '/usr/share/pve-manager/images/');
add_dirs($dirs, '/pve2/css/' => '/usr/share/pve-manager/css/');
add_dirs($dirs, '/vncterm/' => '/usr/share/vncterm/');
$daemon = PVE::APIDaemon->new( $daemon = PVE::APIDaemon->new(
port => 8006, port => 8006,
keep_alive => 100, keep_alive => 100,
...@@ -69,12 +91,7 @@ eval { ...@@ -69,12 +91,7 @@ eval {
file => '/usr/share/pve-manager/images/favicon.ico', file => '/usr/share/pve-manager/images/favicon.ico',
}, },
}, },
dirs => { dirs => $dirs,
'/pve2/images/' => '/usr/share/pve-manager/images/',
'/pve2/css/' => '/usr/share/pve-manager/css/',
'/pve2/ext4/' => '/usr/share/pve-manager/ext4/',
'/vncterm/' => '/usr/share/vncterm/',
},
); );
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment