Skip to content

Commit f372e8b

Browse files
committed
Reintroduce c17728f for Local filesystems
1 parent d448c79 commit f372e8b

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- Fixed an error that could occur when installing Craft with an existing project config, if any image transforms were defined that didn’t specify the `upscale` property.
2525
- Fixed a bug where nested folders in asset search results weren’t showing their relative path.
2626
- Fixed a bug where admin tables’ default delete icon title text wasn’t getting translated. ([#13030](https://github.com/craftcms/cms/issues/13030))
27+
- Fixed a bug where it was possible to save a Local filesystem pointed at a system directory (e.g. the `templates/` or `vendor/` folders).
2728
- Fixed XSS vulnerabilities.
2829

2930
## 4.4.5 - 2023-03-21

src/fs/Local.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Generator;
2323
use RecursiveDirectoryIterator;
2424
use RecursiveIteratorIterator;
25+
use yii\validators\InlineValidator;
2526

2627
/**
2728
* Local represents a local filesystem.
@@ -106,9 +107,33 @@ protected function defineRules(): array
106107
{
107108
$rules = parent::defineRules();
108109
$rules[] = [['path'], 'required'];
110+
$rules[] = [['path'], 'validatePath'];
109111
return $rules;
110112
}
111113

114+
/**
115+
* @param string $attribute
116+
* @param array|null $params
117+
* @param InlineValidator $validator
118+
* @return void
119+
* @since 4.4.6
120+
*/
121+
public function validatePath(string $attribute, ?array $params, InlineValidator $validator): void
122+
{
123+
// Make sure it’s not within any of the system directories
124+
$path = FileHelper::absolutePath($this->getRootPath(), '/');
125+
126+
$systemDirs = Craft::$app->getPath()->getSystemPaths();
127+
128+
foreach ($systemDirs as $dir) {
129+
$dir = FileHelper::absolutePath($dir, '/');
130+
if (str_starts_with("$path/", "$dir/")) {
131+
$validator->addError($this, $attribute, Craft::t('app', 'Local volumes cannot be located within system directories.'));
132+
break;
133+
}
134+
}
135+
}
136+
112137
/**
113138
* @inheritdoc
114139
*/

src/translations/en/app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,7 @@
850850
'Loading' => 'Loading',
851851
'Local Folder' => 'Local Folder',
852852
'Local copies of remote images, generated thumbnails' => 'Local copies of remote images, generated thumbnails',
853+
'Local volumes cannot be located within system directories.' => 'Local volumes cannot be located within system directories.',
853854
'Localizing relations' => 'Localizing relations',
854855
'Location' => 'Location',
855856
'Locations that should be available for previewing entries in this section.' => 'Locations that should be available for previewing entries in this section.',

0 commit comments

Comments
 (0)