From 4ac4655aaa14f887a6e5eaf2aaf7448b867bdf1c Mon Sep 17 00:00:00 2001 From: CPANSec Security Scanner Bot Date: Tue, 24 Nov 2026 14:29:11 +0000 Subject: [PATCH] Net::Server: chdir to / after chroot post_bind calls chroot() when the chroot option is set but never changes the working directory. The process keeps a working directory outside the jail, so any path the server or a handler opens relative to it, including "..", resolves against the real filesystem rather than the chroot. Call chdir("/") immediately after a successful chroot, and stop with a fatal error if it fails, so the working directory is inside the jail before privileges are dropped. Note the new behaviour in the chroot option's documentation. Notes for deciding whether to apply this patch: - After chroot the working directory is the root of the jail. A server or handler that relied on relative paths resolving against the directory it was started in must use paths inside the jail. - Not tested on a running server. It was checked by review and by applying it to Net-Server 2.018. - Applies on its own to Net-Server 2.018, and together with the other CPANSec patches for Net-Server 2.018 when they are applied in CVE-ID order. --- lib/Net/Server.pm | 1 + lib/Net/Server.pod | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Net/Server.pm b/lib/Net/Server.pm index 17353d3..3889ef1 100644 --- a/lib/Net/Server.pm +++ b/lib/Net/Server.pm @@ -404,6 +404,7 @@ sub post_bind { # secure the process and background it $self->fatal("Specified chroot \"$prop->{'chroot'}\" doesn't exist.") if ! -d $prop->{'chroot'}; $self->log(2, "Chrooting to $prop->{'chroot'}"); chroot($prop->{'chroot'}) || $self->fatal("Couldn't chroot to \"$prop->{'chroot'}\": $!"); + chdir("/") || $self->fatal("Couldn't chdir to \"/\" after chroot: $!"); } # drop privileges diff --git a/lib/Net/Server.pod b/lib/Net/Server.pod index 960cfb4..10ad697 100644 --- a/lib/Net/Server.pod +++ b/lib/Net/Server.pod @@ -884,7 +884,9 @@ the client connection will be closed. Defaults to empty array refs. =item chroot Directory to chroot to after bind process has taken place and the -server is still running as root. Defaults to undef. +server is still running as root. The working directory is changed to +the root of the chroot, so relative paths resolve inside it. Defaults +to undef. =item user -- 2.53.0