-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
302 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
framework: | ||
messenger: | ||
buses: | ||
messenger.bus.pimcore-core: | ||
middleware: | ||
- SecureStorageBundle\Messenger\Middleware\GuardMiddleware |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
imports: | ||
- { resource: services/*.yaml } | ||
- { resource: services/*.yaml } |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
public: false | ||
|
||
SecureStorageBundle\Maintenance\ProtectPublicDirectoriesTask: | ||
autowire: true | ||
autoconfigure: true | ||
arguments: | ||
$secureStorageConfig: '%pimcore.secure_storage.config%' | ||
$locator: !tagged_locator { tag: flysystem.storage } | ||
tags: | ||
- { name: pimcore.maintenance.task, type: secure_storage_protect_public_directories } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
public: false | ||
|
||
SecureStorageBundle\Messenger\Middleware\GuardMiddleware: | ||
arguments: | ||
$secureStorageConfig: '%pimcore.secure_storage.config%' | ||
tags: | ||
- { name: messenger.middleware } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace SecureStorageBundle\Maintenance; | ||
|
||
use League\Flysystem\FilesystemOperator; | ||
use Pimcore\Maintenance\TaskInterface; | ||
use Psr\Container\ContainerInterface; | ||
|
||
class ProtectPublicDirectoriesTask implements TaskInterface | ||
{ | ||
public function __construct( | ||
protected array $secureStorageConfig, | ||
protected ContainerInterface $locator | ||
) { | ||
} | ||
|
||
public function execute(): void | ||
{ | ||
$assetProtectionConfig = $this->secureStorageConfig['pimcore_asset_protection']['htaccess_protection_public_directories']; | ||
|
||
if (count($assetProtectionConfig['paths']) === 0) { | ||
return; | ||
} | ||
|
||
foreach ($assetProtectionConfig['paths'] as $protectedPath) { | ||
$this->protectPath($protectedPath); | ||
} | ||
} | ||
|
||
private function protectPath(string $protectedPath): void | ||
{ | ||
$data = implode(PHP_EOL, $this->getProtectionLines()); | ||
|
||
$storages = [ | ||
'pimcore.asset.storage', | ||
'pimcore.asset_cache.storage', | ||
'pimcore.thumbnail.storage' | ||
]; | ||
|
||
foreach ($storages as $storageName) { | ||
|
||
$storage = $this->getStorage($storageName); | ||
|
||
if ($protectedPath === '/') { | ||
|
||
$secureFilePath = '.htaccess'; | ||
if (!$storage->fileExists($secureFilePath)) { | ||
$storage->write($secureFilePath, $data, ['bypass_secured_adapter' => true]); | ||
} | ||
|
||
continue; | ||
} | ||
|
||
$secureFilePath = sprintf('%s/.htaccess', $protectedPath); | ||
if ($storage->directoryExists($protectedPath) && !$storage->fileExists($secureFilePath)) { | ||
$storage->write($secureFilePath, $data, ['bypass_secured_adapter' => true]); | ||
} | ||
} | ||
} | ||
|
||
private function getStorage(string $name): FilesystemOperator | ||
{ | ||
return $this->locator->get($name); | ||
} | ||
|
||
private function getProtectionLines(): array | ||
{ | ||
$data = []; | ||
|
||
$data[] = 'RewriteEngine On'; | ||
$data[] = 'RewriteCond %{HTTP_HOST}==%{HTTP_REFERER} !^(.*?)==https?://\1/admin/ [OR]'; | ||
$data[] = 'RewriteCond %{HTTP_COOKIE} !^.*pimcore_admin_sid.*$ [NC]'; | ||
$data[] = 'RewriteRule ^ - [L,F]'; | ||
|
||
return $data; | ||
} | ||
} |
Oops, something went wrong.