Skip to content

Commit 75a5722

Browse files
committed
Fix Unsafe AUTOLOAD Implementation
1 parent b56047d commit 75a5722

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/VWF/Config.pm

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ our $VERSION = '0.01';
2525
use warnings;
2626
use strict;
2727

28+
use Carp;
2829
use Config::Abstraction;
2930
use CGI::Info;
3031
use Data::Dumper;
@@ -186,8 +187,15 @@ sub AUTOLOAD
186187
# Extract the method name from the AUTOLOAD variable
187188
(my $key = $AUTOLOAD) =~ s/.*:://;
188189

190+
# Don't handle special methods
191+
return if $key eq 'DESTROY';
192+
193+
# Validate method name - only allow safe config keys
194+
Carp::croak("Invalid key name: $key" ) unless $key =~ /^[a-zA-Z_][a-zA-Z0-9_]*$/;
195+
189196
# Return the value of the corresponding hash key
190-
return $self->{$key};
197+
# Only return existing keys to avoid auto-vivification
198+
return exists $self->{$key} ? $self->{$key} : undef;
191199
}
192200

193201
1;

lib/VWF/Display.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ sub get_template_path
326326
return $self->{_filename};
327327
}
328328

329-
my $dir = $self->{_config}->{root_dir} || $self->{_info}->root_dir();
329+
my $dir = $ENV{'root_dir'} || $self->{_config}->{root_dir} || $self->{_info}->root_dir();
330330
if($self->{_logger}) {
331331
$self->{_logger}->debug(__PACKAGE__, ': ', __LINE__, ": root_dir $dir");
332332
$self->{_logger}->debug(Data::Dumper->new([$self->{_config}])->Dump());

0 commit comments

Comments
 (0)