Răsfoiți Sursa

Fix #290: phantom routes due to improper hash handling

George Baugh 2 ani în urmă
părinte
comite
20a9712628
1 a modificat fișierele cu 6 adăugiri și 1 ștergeri
  1. 6 1
      lib/TCMS.pm

+ 6 - 1
lib/TCMS.pm

@@ -6,6 +6,7 @@ use warnings;
 no warnings 'experimental';
 use feature qw{signatures state};
 
+use Clone qw{clone};
 use Date::Format qw{strftime};
 
 use Sys::Hostname();
@@ -53,6 +54,7 @@ $routes{'/robots.txt'} = {
     method   => 'GET',
     callback => \&robots,
 };
+my $routes_immutable = clone(\%routes);
 
 my %aliases = $data->aliases();
 
@@ -75,6 +77,9 @@ sub app {
     # Start the server timing clock
     my $start = [gettimeofday];
 
+    # Don't allow any captured routes to persist past a request in the routing table
+    %routes = %$routes_immutable;
+
     my $env = shift;
 
     # Discard the path used in the log, it's too long and enough 4xx error code = ban
@@ -247,7 +252,7 @@ sub app {
     $query->{user}     = $active_user;
 
     return _forbidden($query)  if exists $routes{$path}{auth} && !$active_user;
-    return _notfound($query)   unless $routes{$path} && ref $routes{$path} eq 'HASH' && keys(%{$routes{$path}});
+    return _notfound($query)   unless exists $routes{$path} && ref $routes{$path} eq 'HASH' && keys(%{$routes{$path}});
     return _badrequest($query) unless grep { $env->{REQUEST_METHOD} eq $_ } ( $routes{$path}{method} || '', 'HEAD' );
 
     @{$query}{ keys( %{ $routes{$path}{'data'} } ) } = values( %{ $routes{$path}{'data'} } ) if ref $routes{$path}{'data'} eq 'HASH' && %{ $routes{$path}{'data'} };