File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change 1313use nystudio107 \transcoder \Transcoder ;
1414
1515use Craft ;
16- use craft \web \ Controller ;
16+ use craft \errors \ AssetDisallowedExtensionException ;
1717use craft \helpers \Json ;
18+ use craft \web \Controller ;
1819
1920/**
2021 * @author nystudio107
@@ -63,6 +64,14 @@ public function beforeAction($action)
6364 public function actionDownloadFile ($ url )
6465 {
6566 $ filePath = parse_url ($ url , PHP_URL_PATH );
67+ // Remove any relative paths
68+ $ filePath = preg_replace ('/\.\.\/+/ ' , '' , $ filePath );
69+ $ extension = strtolower (pathinfo ($ filePath , PATHINFO_EXTENSION ));
70+ $ allowedExtensions = Craft::$ app ->getConfig ()->getGeneral ()->allowedFileExtensions ;
71+ if (!in_array ($ extension , $ allowedExtensions , true )) {
72+ throw new AssetDisallowedExtensionException ("File “ {$ filePath }” cannot be downloaded because “ {$ extension }” is not allowed. " );
73+ }
74+
6675 $ filePath = $ _SERVER ['DOCUMENT_ROOT ' ].$ filePath ;
6776 Craft::$ app ->getResponse ()->sendFile (
6877 $ filePath ,
You can’t perform that action at this time.
0 commit comments