Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Template/Filters.pm
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,8 @@ sub redirect_filter_factory {
'OUTPUT_PATH is not set'))
unless $outpath;

$context->throw('redirect', "relative filenames are not supported: $file")
if $file =~ m{(^|/)\.\./};
$context->throw('redirect', "path traversal is not permitted: $file")
if $file =~ m{(^|[\\/])\.\.([\\/]|$)};

$options = { binmode => $options } unless ref $options;

Expand Down
36 changes: 36 additions & 0 deletions t/filter.t
Original file line number Diff line number Diff line change
Expand Up @@ -981,3 +981,39 @@ foo(bar)
[% "foo(bar)" | uri %]
-- expect --
foo(bar)

-- test --
-- use evalperl --
[% TRY -%]
[% FILTER redirect('../traversal') %]
should not reach here
[% END -%]
[% CATCH -%]
ERROR [% error.type %]: [% error.info %]
[% END %]
-- expect --
ERROR redirect: path traversal is not permitted: ../traversal

-- test --
-- use evalperl --
[% TRY -%]
[% FILTER redirect('..') %]
should not reach here
[% END -%]
[% CATCH -%]
ERROR [% error.type %]: [% error.info %]
[% END %]
-- expect --
ERROR redirect: path traversal is not permitted: ..

-- test --
-- use evalperl --
[% TRY -%]
[% FILTER redirect('sub/../escape') %]
should not reach here
[% END -%]
[% CATCH -%]
ERROR [% error.type %]: [% error.info %]
[% END %]
-- expect --
ERROR redirect: path traversal is not permitted: sub/../escape
15 changes: 14 additions & 1 deletion t/vars.t
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ my $params = {
expose => sub { undef $Template::Stash::PRIVATE },
add => sub { $_[0] + $_[1] },

'numlist' => [ 10, 20, 30 ],

# don't define a 'z' - DEFAULT test relies on its non-existance
};

Expand Down Expand Up @@ -463,7 +465,7 @@ bravo

-- test --
[% a = '' b = '' -%]
[% DEFAULT
[% DEFAULT
a = c
b = d
z = r
Expand All @@ -472,6 +474,17 @@ bravo
-- expect --
charlie delta romeo

-- test --
[% DEFAULT numlist.0 = 999 -%]
[% numlist.0 %]
-- expect --
10

-- test --
[% DEFAULT numlist.3 = 40 -%]
[% numlist.3 %]
-- expect --
40

#------------------------------------------------------------------------
# 'global' vars
Expand Down