Skip to content

Commit c7ce5b3

Browse files
author
Joan He
committed
MAGETWO-36791: Fixed too broad permissions on files
1 parent 4419c3f commit c7ce5b3

File tree

18 files changed

+37
-22
lines changed

18 files changed

+37
-22
lines changed

app/code/Magento/Backup/Model/Fs/Collection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ protected function _hideBackupsForApache()
9191
$filename = '.htaccess';
9292
if (!$this->_varDirectory->isFile($filename)) {
9393
$this->_varDirectory->writeFile($filename, 'deny from all');
94-
$this->_varDirectory->changePermissions($filename, 0644);
94+
$this->_varDirectory->changePermissions($filename, 0640);
9595
}
9696
}
9797

app/code/Magento/Captcha/Helper/Data.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function getImgDir($website = null)
149149
$mediaDir = $this->_filesystem->getDirectoryWrite(DirectoryList::MEDIA);
150150
$captchaDir = '/captcha/' . $this->_getWebsiteCode($website);
151151
$mediaDir->create($captchaDir);
152-
$mediaDir->changePermissions($captchaDir, 0775);
152+
$mediaDir->changePermissions($captchaDir, Filesystem\DriverInterface::WRITEABLE_DIRECTORY_MODE);
153153

154154
return $mediaDir->getAbsolutePath($captchaDir) . '/';
155155
}

app/code/Magento/Catalog/Model/Product/Attribute/Backend/Media.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Magento\Framework\App\Filesystem\DirectoryList;
1515
use Magento\Framework\Exception\LocalizedException;
16+
use Magento\Framework\Filesystem\DriverInterface;
1617

1718
/**
1819
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
@@ -396,7 +397,7 @@ public function addImage(
396397
$this->_mediaDirectory->copyFile($file, $destinationFile);
397398

398399
$storageHelper->saveFile($this->_mediaConfig->getTmpMediaShortUrl($fileName));
399-
$this->_mediaDirectory->changePermissions($destinationFile, 0777);
400+
$this->_mediaDirectory->changePermissions($destinationFile, DriverInterface::WRITEABLE_DIRECTORY_MODE);
400401
}
401402
} catch (\Exception $e) {
402403
throw new LocalizedException(__('We couldn\'t move this file: %1.', $e->getMessage()));

dev/tests/integration/testsuite/Magento/Framework/Filesystem/Directory/WriteTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public function testChangePermissions()
228228
{
229229
$directory = $this->getDirectoryInstance('newDir1', 0777);
230230
$directory->create('test_directory');
231-
$this->assertTrue($directory->changePermissions('test_directory', 0644));
231+
$this->assertTrue($directory->changePermissions('test_directory', 0640));
232232
}
233233

234234
/**

dev/tests/performance/framework/Magento/TestFramework/Application.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Magento\TestFramework;
1111

1212
use Magento\Framework\App\Filesystem\DirectoryList;
13+
use Magento\Framework\Filesystem\DriverInterface;
1314

1415
class Application
1516
{
@@ -184,7 +185,7 @@ protected function _updateFilesystemPermissions()
184185
)->getDirectoryWrite(
185186
DirectoryList::VAR_DIR
186187
);
187-
$varDirectory->changePermissions('', 0777);
188+
$varDirectory->changePermissions('', DriverInterface::WRITEABLE_DIRECTORY_MODE);
188189
}
189190

190191
/**

dev/tools/Magento/Tools/Migration/Acl/Db/Logger/File.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Tools\Migration\Acl\Db\Logger;
77

88
use InvalidArgumentException;
9+
use Magento\Framework\Filesystem\DriverInterface;
910

1011
/**
1112
* Db migration logger. Output result put to file
@@ -27,7 +28,7 @@ public function __construct($file)
2728
{
2829
$logDir = realpath(__DIR__ . '/../../') . '/log/';
2930
if (false == is_dir($logDir)) {
30-
mkdir($logDir, 0777, true);
31+
mkdir($logDir, DriverInterface::WRITEABLE_DIRECTORY_MODE, true);
3132
}
3233
if (false == is_writeable($logDir)) {
3334
throw new InvalidArgumentException('Directory ' . dirname($logDir) . ' is not writeable');

dev/tools/Magento/Tools/Migration/Acl/FileManager.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Tools\Migration\Acl;
77

8+
use Magento\Framework\Filesystem\DriverInterface;
9+
810
class FileManager
911
{
1012
/**
@@ -15,7 +17,7 @@ class FileManager
1517
public function write($fileName, $contents)
1618
{
1719
if (false == is_dir(dirname($fileName))) {
18-
mkdir(dirname($fileName), 0777, true);
20+
mkdir(dirname($fileName), DriverInterface::WRITEABLE_DIRECTORY_MODE, true);
1921
}
2022
file_put_contents($fileName, $contents);
2123
}

dev/tools/Magento/Tools/Migration/System/Writer/FileSystem.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Tools\Migration\System\Writer;
77

8+
use Magento\Framework\Filesystem\DriverInterface;
9+
810
class FileSystem implements \Magento\Tools\Migration\System\WriterInterface
911
{
1012
/**
@@ -15,7 +17,7 @@ class FileSystem implements \Magento\Tools\Migration\System\WriterInterface
1517
public function write($fileName, $contents)
1618
{
1719
if (false == is_dir(dirname($fileName))) {
18-
mkdir(dirname($fileName), 0777, true);
20+
mkdir(dirname($fileName), DriverInterface::WRITEABLE_DIRECTORY_MODE, true);
1921
}
2022
file_put_contents($fileName, $contents);
2123
}

lib/internal/Magento/Framework/Archive/Helper/File.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function __destruct()
9090
* @throws LocalizedException
9191
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
9292
*/
93-
public function open($mode = 'w+', $chmod = 0666)
93+
public function open($mode = 'w+', $chmod = 0660)
9494
{
9595
$this->_isInWriteMode = $this->_isWritableMode($mode);
9696

lib/internal/Magento/Framework/Filesystem/Io/IoInterface.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento\Framework\Filesystem\Io;
7+
use Magento\Framework\Filesystem\DriverInterface;
78

89
/**
910
* Input/output client interface
@@ -33,7 +34,7 @@ public function close();
3334
* @param bool $recursive
3435
* @return bool
3536
*/
36-
public function mkdir($dir, $mode = 0777, $recursive = true);
37+
public function mkdir($dir, $mode = DriverInterface::WRITEABLE_DIRECTORY_MODE, $recursive = true);
3738

3839
/**
3940
* Delete a directory

lib/internal/Magento/Framework/Filesystem/Io/Sftp.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// @codingStandardsIgnoreFile
88

99
namespace Magento\Framework\Filesystem\Io;
10+
use Magento\Framework\Filesystem\DriverInterface;
1011

1112
/**
1213
* Sftp client interface
@@ -76,7 +77,7 @@ public function close()
7677
* @return bool
7778
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
7879
*/
79-
public function mkdir($dir, $mode = 0777, $recursive = true)
80+
public function mkdir($dir, $mode = DriverInterface::WRITEABLE_DIRECTORY_MODE, $recursive = true)
8081
{
8182
if ($recursive) {
8283
$no_errors = true;

lib/internal/Magento/Framework/Logger/Handler/Base.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function write(array $record)
5454
{
5555
$logDir = $this->filesystem->getParentDirectory($this->url);
5656
if (!$this->filesystem->isDirectory($logDir)) {
57-
$this->filesystem->createDirectory($logDir, 0777);
57+
$this->filesystem->createDirectory($logDir, DriverInterface::WRITEABLE_DIRECTORY_MODE);
5858
}
5959

6060
parent::write($record);

lib/internal/Magento/Framework/Setup/BackupRollback.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Framework\Backup\Filesystem\Helper;
1414
use Magento\Framework\Exception\LocalizedException;
1515
use Magento\Framework\Filesystem\Driver\File;
16+
use Magento\Framework\Filesystem\DriverInterface;
1617
use Magento\Framework\ObjectManagerInterface;
1718
use Magento\Framework\Phrase;
1819

@@ -102,7 +103,7 @@ public function codeBackup($time, $type = Factory::TYPE_FILESYSTEM)
102103
}
103104
$backupsDir = $this->directoryList->getPath(DirectoryList::VAR_DIR) . '/' . self::DEFAULT_BACKUP_DIRECTORY;
104105
if (!$this->file->isExists($backupsDir)) {
105-
$this->file->createDirectory($backupsDir, 0777);
106+
$this->file->createDirectory($backupsDir, DriverInterface::WRITEABLE_DIRECTORY_MODE);
106107
}
107108
$fsBackup->setBackupsDir($backupsDir);
108109
$fsBackup->setBackupExtension('tgz');
@@ -186,7 +187,7 @@ public function dbBackup($time)
186187
$dbBackup->setRootDir($this->directoryList->getRoot());
187188
$backupsDir = $this->directoryList->getPath(DirectoryList::VAR_DIR) . '/' . self::DEFAULT_BACKUP_DIRECTORY;
188189
if (!$this->file->isExists($backupsDir)) {
189-
$this->file->createDirectory($backupsDir, 0777);
190+
$this->file->createDirectory($backupsDir, DriverInterface::WRITEABLE_DIRECTORY_MODE);
190191
}
191192
$dbBackup->setBackupsDir($backupsDir);
192193
$dbBackup->setBackupExtension('gz');

lib/internal/Magento/Framework/System/Dirs.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Framework\System;
77

8+
use Magento\Framework\Filesystem\DriverInterface;
9+
810
class Dirs
911
{
1012
/**
@@ -73,7 +75,7 @@ public static function rm($dirname)
7375
* @return true
7476
* @throws \Exception
7577
*/
76-
public static function mkdirStrict($path, $recursive = true, $mode = 0777)
78+
public static function mkdirStrict($path, $recursive = true, $mode = DriverInterface::WRITEABLE_DIRECTORY_MODE)
7779
{
7880
$exists = file_exists($path);
7981
if ($exists && is_dir($path)) {

lib/internal/Magento/Framework/System/Ftp.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
namespace Magento\Framework\System;
8+
use Magento\Framework\Filesystem\DriverInterface;
89

910
/**
1011
* Class to work with remote FTP server
@@ -50,7 +51,7 @@ public function mdkir($name)
5051
* @param int $mode
5152
* @return bool
5253
*/
53-
public function mkdirRecursive($path, $mode = 0777)
54+
public function mkdirRecursive($path, $mode = DriverInterface::WRITEABLE_DIRECTORY_MODE)
5455
{
5556
$this->checkConnected();
5657
$dir = explode("/", $path);
@@ -217,7 +218,7 @@ public function raw($cmd)
217218
* @return bool
218219
* @throws \Exception
219220
*/
220-
public function upload($remote, $local, $dirMode = 0777, $ftpMode = FTP_BINARY)
221+
public function upload($remote, $local, $dirMode = DriverInterface::WRITEABLE_DIRECTORY_MODE, $ftpMode = FTP_BINARY)
221222
{
222223
$this->checkConnected();
223224

pub/errors/processor.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* See COPYING.txt for license details.
55
*/
66
namespace Magento\Framework\Error;
7+
use Magento\Framework\Filesystem\DriverInterface;
78

89
/**
910
* Error processor
@@ -453,11 +454,11 @@ public function saveReport($reportData)
453454
$this->_setReportData($reportData);
454455

455456
if (!file_exists($this->_reportDir)) {
456-
@mkdir($this->_reportDir, 0777, true);
457+
@mkdir($this->_reportDir, DriverInterface::WRITEABLE_DIRECTORY_MODE, true);
457458
}
458459

459460
@file_put_contents($this->_reportFile, serialize($reportData));
460-
@chmod($this->_reportFile, 0777);
461+
@chmod($this->_reportFile, DriverInterface::WRITEABLE_DIRECTORY_MODE);
461462

462463
if (isset($reportData['skin']) && self::DEFAULT_SKIN != $reportData['skin']) {
463464
$this->_setSkin($reportData['skin']);

setup/src/Magento/Setup/Console/Command/DiCompileMultiTenantCommand.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Setup\Console\Command;
77

8+
use Magento\Framework\Filesystem\DriverInterface;
89
use Magento\Setup\Model\ObjectManagerProvider;
910
use Magento\Framework\App\ObjectManager;
1011
use Symfony\Component\Console\Input\InputInterface;
@@ -351,7 +352,7 @@ private function compileCode($generationDir, $fileExcludePatterns, $input)
351352
$relations = $directoryInstancesNamesList->getRelations();
352353
// 2.2 Compression
353354
if (!file_exists(dirname($relationsFile))) {
354-
mkdir(dirname($relationsFile), 0777, true);
355+
mkdir(dirname($relationsFile), DriverInterface::WRITEABLE_DIRECTORY_MODE, true);
355356
}
356357
$relations = array_filter($relations);
357358
file_put_contents($relationsFile, $serializer->serialize($relations));
@@ -368,7 +369,7 @@ private function compileCode($generationDir, $fileExcludePatterns, $input)
368369
}
369370
$outputContent = $serializer->serialize($pluginDefinitions);
370371
if (!file_exists(dirname($pluginDefFile))) {
371-
mkdir(dirname($pluginDefFile), 0777, true);
372+
mkdir(dirname($pluginDefFile), DriverInterface::WRITEABLE_DIRECTORY_MODE, true);
372373
}
373374
file_put_contents($pluginDefFile, $outputContent);
374375
}

setup/src/Magento/Setup/Module/I18n/Pack/Writer/File/AbstractFile.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ abstract protected function _getFileExtension();
143143
* @param bool $recursive Allows the creation of nested directories specified in the $destinationPath
144144
* @return void
145145
*/
146-
protected function _createDirectoryIfNotExist($destinationPath, $mode = 0755, $recursive = true)
146+
protected function _createDirectoryIfNotExist($destinationPath, $mode = 0750, $recursive = true)
147147
{
148148
if (!is_dir($destinationPath)) {
149149
mkdir($destinationPath, $mode, $recursive);

0 commit comments

Comments
 (0)