From c911419121d00cc2d7a4daaa12239c676ac106a7 Mon Sep 17 00:00:00 2001 From: Hendrik Brueckner Date: Mon, 6 Jul 2026 13:59:28 +0200 Subject: [PATCH] iucvterm/ts-shell: Validate guest name before constructing the audit file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The guest name is provided on the CLI and needs to be validated before the file path to the session audit file is constructed. Reviewed-by: Jan Höppner Reviewed-by: Steffen Eiden Signed-off-by: Hendrik Brueckner Signed-off-by: Jan Höppner --- iucvterm/bin/ts-shell.in | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/iucvterm/bin/ts-shell.in b/iucvterm/bin/ts-shell.in index 80902804..b5abdba4 100755 --- a/iucvterm/bin/ts-shell.in +++ b/iucvterm/bin/ts-shell.in @@ -237,7 +237,7 @@ sub loadAuthorization(\%) } elsif ($key =~ /^@(\S+)$/) { my $group = $1; - $authorized = 1 if grep {/^${group}$/} @{$cfg->{groups}}; + $authorized = 1 if grep {/^\Q${group}\E$/} @{$cfg->{groups}}; log_debug "Found group: $key" if $authorized; } @@ -406,7 +406,15 @@ sub get_auditlog_file($$$) } } - $$filepath = "$cfg->{auditdir}/$cfg->{user}/" . uc $guest . "_"; + # validate and sanitize guest directory + $guest = uc $guest; + unless ($guest =~ /^([A-Z0-9@#\$_-]{1,8})$/) { + log_error "Creating session file path failed for guest: $guest"; + return 0; # return error + } + + # construct the file path + $$filepath = "$cfg->{auditdir}/$cfg->{user}/" . $guest . "_"; $$filepath .= strftime '%F-%H%M%S', localtime; log_debug "Session transcript file: $$filepath";