Skip to content

Commit

Permalink
[media] Fix download of filenames with commas (aces#9510)
Browse files Browse the repository at this point in the history
In the Media module, allows files with names containing commas to be
downloaded (would previously result in an error).
  • Loading branch information
victori444 authored Jan 17, 2025
1 parent 9d94422 commit 78e430f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion modules/media/jsx/mediaIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ class MediaIndex extends Component {
+ encodeURIComponent(row['File Name']);
result = (
<td className={style}>
<a href={downloadURL} target="_blank" download={row['File Name']}>
<a
href={downloadURL}
target="_blank"
download={encodeURIComponent(row['File Name'])}
>
{cell}
</a>
</td>
Expand Down
3 changes: 2 additions & 1 deletion php/libraries/FilesDownloadHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@ public function handle(ServerRequestInterface $request) : ResponseInterface
}
//Use basename to remove path traversal characters.
$filename = $request->getAttribute('filename');

if (empty($filename)) {
return new \LORIS\Http\Response\JSON\BadRequest(
self::ERROR_EMPTY_FILENAME
);
}

assert(is_string($filename) || $filename instanceof \Stringable);
$filename = \Utility::resolvePath(strval($filename));
$filename = urldecode(\Utility::resolvePath(strval($filename)));

$targetPath = \Utility::appendForwardSlash(
$this->downloadDirectory->getPathname()
Expand Down

0 comments on commit 78e430f

Please sign in to comment.