修复在linux上使用错误分隔符的问题

*在debian 12上测试
This commit is contained in:
Chenx221 2024-04-11 15:40:08 +08:00
parent 75cac63b9b
commit 0e7088128c
Signed by: chenx221
GPG Key ID: D7A9EC07024C3021
2 changed files with 2 additions and 2 deletions

View File

@ -171,7 +171,7 @@ class HomeController extends Controller
// 使用realpath函数解析路径并检查解析后的路径是否在预期的目录中 // 使用realpath函数解析路径并检查解析后的路径是否在预期的目录中
$realPath = realpath($absolutePath); $realPath = realpath($absolutePath);
$dataDirectory = str_replace('/', '\\', Yii::getAlias(Yii::$app->params['dataDirectory'])); $dataDirectory = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, Yii::getAlias(Yii::$app->params['dataDirectory']));
if (!$realPath || !str_starts_with($realPath, $dataDirectory)) { if (!$realPath || !str_starts_with($realPath, $dataDirectory)) {
throw new NotFoundHttpException('File not found.'); throw new NotFoundHttpException('File not found.');
} }

View File

@ -157,7 +157,7 @@ class VaultController extends Controller
// 使用realpath函数解析路径并检查解析后的路径是否在预期的目录中 // 使用realpath函数解析路径并检查解析后的路径是否在预期的目录中
$realPath = realpath($absolutePath); $realPath = realpath($absolutePath);
$dataDirectory = str_replace('/', '\\', Yii::getAlias(Yii::$app->params['dataDirectory'])); $dataDirectory = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, Yii::getAlias(Yii::$app->params['dataDirectory']));
if (!$realPath || !str_starts_with($realPath, $dataDirectory)) { if (!$realPath || !str_starts_with($realPath, $dataDirectory)) {
throw new NotFoundHttpException('File not found.'); throw new NotFoundHttpException('File not found.');
} }