From f1fbcd04a8c694b8f79a611df6e942dda3f954fe Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 2 Mar 2009 10:23:40 +0000 Subject: [PATCH] --- src/Hydra/lib/Hydra/Controller/Build.pm | 5 ----- src/Hydra/lib/Hydra/Controller/Root.pm | 2 +- src/Hydra/lib/Hydra/Helper/CatalystUtils.pm | 11 ++++++++++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Hydra/lib/Hydra/Controller/Build.pm b/src/Hydra/lib/Hydra/Controller/Build.pm index 131ce229..7b549d9b 100644 --- a/src/Hydra/lib/Hydra/Controller/Build.pm +++ b/src/Hydra/lib/Hydra/Controller/Build.pm @@ -7,11 +7,6 @@ use Hydra::Helper::Nix; use Hydra::Helper::CatalystUtils; -# Security checking of filenames. -my $pathCompRE = "(?:[A-Za-z0-9-\+][A-Za-z0-9-\+\._]*)"; -my $relPathRE = "(?:$pathCompRE(?:\/$pathCompRE)*)"; - - sub build : Chained('/') PathPart CaptureArgs(1) { my ($self, $c, $id) = @_; diff --git a/src/Hydra/lib/Hydra/Controller/Root.pm b/src/Hydra/lib/Hydra/Controller/Root.pm index 3ede1f10..8da4b111 100644 --- a/src/Hydra/lib/Hydra/Controller/Root.pm +++ b/src/Hydra/lib/Hydra/Controller/Root.pm @@ -352,7 +352,7 @@ sub updateProject { # The Nix expression path must be relative and can't contain ".." elements. my $nixExprPath = trim $c->request->params->{"jobset-$baseName-nixexprpath"}; - die "Invalid Nix expression path: $nixExprPath" if $nixExprPath !~ /^$Build::relPathRE$/; + die "Invalid Nix expression path: $nixExprPath" if $nixExprPath !~ /^$relPathRE$/; my $nixExprInput = trim $c->request->params->{"jobset-$baseName-nixexprinput"}; die "Invalid Nix expression input name: $nixExprInput" unless $nixExprInput =~ /^\w+$/; diff --git a/src/Hydra/lib/Hydra/Helper/CatalystUtils.pm b/src/Hydra/lib/Hydra/Helper/CatalystUtils.pm index 66577520..865666e6 100644 --- a/src/Hydra/lib/Hydra/Helper/CatalystUtils.pm +++ b/src/Hydra/lib/Hydra/Helper/CatalystUtils.pm @@ -2,9 +2,13 @@ package Hydra::Helper::CatalystUtils; use strict; use Exporter; +use Readonly; our @ISA = qw(Exporter); -our @EXPORT = qw(getBuild error notFound); +our @EXPORT = qw( + getBuild error notFound + $pathCompRE $relPathRE +); sub getBuild { @@ -28,4 +32,9 @@ sub notFound { } +# Security checking of filenames. +Readonly::Scalar our $pathCompRE => "(?:[A-Za-z0-9-\+][A-Za-z0-9-\+\._]*)"; +Readonly::Scalar our $relPathRE => "(?:$pathCompRE(?:\/$pathCompRE)*)"; + + 1;