FuCY's picture
Add files using upload-large-folder tool
4d2a9bf verified
Raw History Blame Contribute Delete
4.22 kB
diff --git a/app/bundles/AssetBundle/Form/Type/AssetType.php b/app/bundles/AssetBundle/Form/Type/AssetType.php
index 995aff06e46..f285498e17b 100644
--- a/app/bundles/AssetBundle/Form/Type/AssetType.php
+++ b/app/bundles/AssetBundle/Form/Type/AssetType.php
@@ -20,6 +20,7 @@
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Validator\Constraints\NotBlank;
+use Symfony\Component\Validator\Constraints\Url;
class AssetType extends AbstractType
{
@@ -90,10 +91,17 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'remotePath',
TextType::class,
[
- 'label' => 'mautic.asset.asset.form.remotePath',
- 'label_attr' => ['class' => 'control-label'],
- 'attr' => ['class' => 'form-control'],
- 'required' => false,
+ 'label' => 'mautic.asset.asset.form.remotePath',
+ 'label_attr' => ['class' => 'control-label'],
+ 'attr' => ['class' => 'form-control'],
+ 'required' => false,
+ 'constraints' => [
+ new Url(
+ [
+ 'message' => 'mautic.asset.validation.error.url',
+ ]
+ ),
+ ],
]
);
diff --git a/app/bundles/AssetBundle/Tests/Controller/Api/AssetApiControllerFunctionalTest.php b/app/bundles/AssetBundle/Tests/Controller/Api/AssetApiControllerFunctionalTest.php
index 411ae853f28..10f6f78a140 100644
--- a/app/bundles/AssetBundle/Tests/Controller/Api/AssetApiControllerFunctionalTest.php
+++ b/app/bundles/AssetBundle/Tests/Controller/Api/AssetApiControllerFunctionalTest.php
@@ -23,6 +23,19 @@ public function testCreateNewRemoteAsset()
$this->assertNotNull($response['asset']['size']);
}
+ public function testCreateNewRemoteAssetWithVulnerableFile(): void
+ {
+ $payload = [
+ 'file' => 'file:///etc/passwd',
+ 'storageLocation' => 'remote',
+ 'title' => 'title',
+ ];
+ $this->client->request('POST', 'api/assets/new', $payload);
+ $clientResponse = $this->client->getResponse();
+ $this->assertSame(400, $clientResponse->getStatusCode(), $clientResponse->getContent());
+ $this->assertEquals('{"errors":[{"code":400,"message":"remotePath: The remote should be a valid URL.","details":{"remotePath":["The remote should be a valid URL."]}}]}', $clientResponse->getContent());
+ }
+
public function testCreateNewLocalAsset()
{
$assetsPath = $this->client->getKernel()->getContainer()->getParameter('mautic.upload_dir');
diff --git a/app/bundles/AssetBundle/Translations/en_US/validators.ini b/app/bundles/AssetBundle/Translations/en_US/validators.ini
index d9532dbcf1b..a9c593adbb3 100644
--- a/app/bundles/AssetBundle/Translations/en_US/validators.ini
+++ b/app/bundles/AssetBundle/Translations/en_US/validators.ini
@@ -3,4 +3,5 @@ mautic.asset.asset.error.missing.title="Assset Title is required."
mautic.asset.asset.error.missing.remote.path="A remote URL must be specified when remote storage is selected."
mautic.asset.asset.error.file.size="Upload failed as the file is %fileSize% MB which exceeds the maximum allowed file size of %maxSize% MB. This setting can be changed in the Configuration."
mautic.asset.asset.error.file.extension="Upload failed as the file extension, %fileExtension%, is not in the list of allowed extensions (%extensions%). This setting can be changed in the Configuration."
-mautic.asset.asset.error.file.extension.js="Upload failed as the file extension is not in the list of allowed extensions (%extensions%). This setting can be changed in the Configuration."
\ No newline at end of file
+mautic.asset.asset.error.file.extension.js="Upload failed as the file extension is not in the list of allowed extensions (%extensions%). This setting can be changed in the Configuration."
+mautic.asset.validation.error.url="The remote should be a valid URL."
\ No newline at end of file