File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed
Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change 1414
1515use Craft ;
1616use craft \errors \AssetDisallowedExtensionException ;
17- use craft \helpers \Json ;
17+ use craft \helpers \Json as JsonHelper ;
18+ use craft \helpers \Path as PathHelper ;
1819use craft \web \Controller ;
20+ use yii \web \BadRequestHttpException ;
1921
2022/**
2123 * @author nystudio107
@@ -65,7 +67,10 @@ public function actionDownloadFile($url)
6567 {
6668 $ filePath = parse_url ($ url , PHP_URL_PATH );
6769 // Remove any relative paths
68- $ filePath = preg_replace ('/\.\.\/+/ ' , '' , $ filePath );
70+ if (!PathHelper::ensurePathIsContained ($ filePath )) {
71+ throw new BadRequestHttpException ('Invalid resource path: ' . $ filePath );
72+ }
73+ // Only work for `allowedFileExtensions` file extensions
6974 $ extension = strtolower (pathinfo ($ filePath , PATHINFO_EXTENSION ));
7075 $ allowedExtensions = Craft::$ app ->getConfig ()->getGeneral ()->allowedFileExtensions ;
7176 if (!in_array ($ extension , $ allowedExtensions , true )) {
@@ -164,6 +169,6 @@ public function actionProgress($filename)
164169 }
165170 }
166171
167- return Json ::encode ($ result );
172+ return JsonHelper ::encode ($ result );
168173 }
169174}
You can’t perform that action at this time.
0 commit comments