Skip to content

Commit

Permalink
disallows some mime types for upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Elorfin committed Feb 1, 2023
1 parent 0d80277 commit 00983e3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/main/core/Controller/APINew/FileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Claroline\AppBundle\API\Crud;
use Claroline\AppBundle\Controller\AbstractCrudController;
use Claroline\CoreBundle\Entity\File\PublicFile;
use Claroline\CoreBundle\Library\Configuration\PlatformConfigurationHandler;
use Claroline\CoreBundle\Validator\Exception\InvalidDataException;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -26,6 +27,14 @@
*/
class FileController extends AbstractCrudController
{
/** @var PlatformConfigurationHandler */
private $config;

public function __construct(PlatformConfigurationHandler $config)
{
$this->config = $config;
}

public function getClass(): string
{
return PublicFile::class;
Expand All @@ -50,6 +59,10 @@ public function uploadAction(Request $request): JsonResponse

$objects = [];
foreach ($files as $file) {
if (!empty($this->config->getParameter('file_blacklist')) && in_array($file->getMimeType(), $this->config->getParameter('file_blacklist'))) {
throw new InvalidDataException('Unauthorized file type.');
}

$object = $this->crud->create(PublicFile::class, [], ['file' => $file, Crud::THROW_EXCEPTION]);
$objects[] = $this->serializer->serialize($object);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public function up(Schema $schema): void

// merge organization managers and organization members table
$this->addSql('
INSERT INTO user_organization (user_id, organization_id, is_manager)
SELECT a.user_id, a.organization_id, 1 AS is_manager
INSERT INTO user_organization (user_id, organization_id, is_manager, is_main)
SELECT a.user_id, a.organization_id, 1 AS is_manager, 0 AS is_main
FROM claro_user_administrator AS a
WHERE NOT EXISTS (
SELECT uo.*
Expand Down
2 changes: 2 additions & 0 deletions src/main/core/Resources/config/services/controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ services:
Claroline\CoreBundle\Controller\APINew\FileController:
parent: Claroline\AppBundle\Controller\AbstractCrudController
public: true
arguments:
- '@Claroline\CoreBundle\Library\Configuration\PlatformConfigurationHandler'

Claroline\CoreBundle\Controller\APINew\ObjectLockController:
arguments:
Expand Down

0 comments on commit 00983e3

Please sign in to comment.