Skip to content

Commit

Permalink
Item13883: improve filename validation (Item15163)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed Aug 5, 2022
1 parent a71f1a5 commit a5ec350
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 4 additions & 3 deletions core/lib/Foswiki/Sandbox.pm
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ sub validateAttachmentName {
my @result;
foreach my $component (@dirs) {
return unless defined($component) && $component ne '';

# Filter nasty characters
$component =~ s/$Foswiki::cfg{AttachmentNameFilter}//g;

next if $component eq '.';
if ( $component eq '..' ) {
if ( scalar(@result) ) {
Expand All @@ -214,9 +218,6 @@ sub validateAttachmentName {
}
}
else {

# Filter nasty characters
$component =~ s/$Foswiki::cfg{AttachmentNameFilter}//g;
push( @result, $component );
}
}
Expand Down
11 changes: 11 additions & 0 deletions core/lib/Foswiki/UI/Viewfile.pm
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,17 @@ sub viewfile {
$fileName = Foswiki::Sandbox::untaint( $fileName,
\&Foswiki::Sandbox::validateAttachmentName );

if ( !$fileName ) {
throw Foswiki::OopsException(
'attention',
def => 'no_such_attachment',
web => $web,
topic => $topic,
status => 404,
params => ['?']
);
}

#print STDERR "VIEWFILE: web($web), topic($topic), file($fileName)\n";

my $rev = Foswiki::Store::cleanUpRevID( scalar( $query->param('rev') ) );
Expand Down

0 comments on commit a5ec350

Please sign in to comment.