-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Description
Q | A |
---|---|
Bug report? | yes |
Feature request? | no |
BC Break report? | no |
RFC? | no |
Symfony version | 2.7.38 |
In v2.7.38 it was introduced a security fix to uploaded files.
PR: #24993
The problem is that if you upload the files using ajax and you use the javascript below for ajax upload:
$('body').on('submit', '.ajaxForm', function (e) {
var formData = new FormData($(this)[0]);
$.ajax({
type: 'POST',
url: your_url,
processData: false,
contentType: false,
data: formData
});
}
In Symfony\Component\Form\Extension\Core\Type\FileType::buildForm() when calling $event->getData() you obtain the following structure:
array:1 [▼
0 => array:1 [▼
0 => UploadedFile {#13 ▼
-test: false
-originalName: "IMG_20171110_150940.jpg"
-mimeType: "image/jpeg"
-size: 593894
-error: 0
}
]
]
And when calling $requestHandler->isFileUpload($file), $file is an array instead of the actual file, and the result will be false.
Is it something that I'm doing wrong when uploading files with ajax and I shouldn't get the structure above, or could we add some extra checks either in FileType?
This is the form config:
$builder
->add('documents', 'file', array(
'required' => false,
'attr' => array('multiple' => 'multiple'),
'mapped' => false,
'multiple'=>true,
))
;