Fixes for handling of invalid p param. Don't allow directory
Zachary Stevens [Sun, 6 Dec 2009 12:23:00 +0000 (12:23 +0000)]
traveral, and don't try to render a template.

lib/Gitalist/Controller/Root.pm
lib/Gitalist/Git/Repo.pm
t/02git_repo.t

index f9e94ad..064ea6d 100644 (file)
@@ -636,7 +636,7 @@ sub auto : Private {
       $c->stash(Project => $c->model('GitRepos')->project($project));
     };
     if ($@) {
-      $c->detach('error_404');
+      $c->detach('/error_404');
     }
   }
 
@@ -679,10 +679,7 @@ sub end : ActionClass('RenderView') {
 sub error_404 :Private {
     my ($self, $c) = @_;
     $c->response->status(404);
-    $c->stash(
-        title => 'Page not found',
-        content => 'Page not found',
-    );
+    $c->response->body('Page not found');
 }
 
 sub age_string {
index 4a5d491..b31faff 100644 (file)
@@ -66,7 +66,8 @@ name.
 =cut
 
     method project (NonEmptySimpleStr $project) {
-        my $path = $self->repo_dir->subdir($project);
+        my $path = $self->repo_dir->subdir($project)->resolve;
+        die "Directory traversal prohibited" unless $self->repo_dir->contains($path);
         die "Not a valid Project" unless $self->_is_git_repo($path);
         return Project->new( $self->repo_dir->subdir($project) );
     }
index ab35c59..821d5db 100644 (file)
@@ -39,5 +39,9 @@ dies_ok {
     my $project = $repo->project();
 } 'throws exception for no project';
 
+dies_ok {
+    my $project = $repo->project('../../../');
+} 'throws exception for directory traversal';
+
 my $project = $repo->project('repo1');
 isa_ok($project, 'Gitalist::Git::Project');