File size: 4,220 Bytes
4d2a9bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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