Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error ATTACK from FileUploadFile #125

Closed
diegobittencourt opened this issue Mar 25, 2022 · 3 comments
Closed

Error ATTACK from FileUploadFile #125

diegobittencourt opened this issue Mar 25, 2022 · 3 comments
Assignees
Labels
Invalid This doesn't seem right Question Further information is requested

Comments

@diegobittencourt
Copy link

diegobittencourt commented Mar 25, 2022

Bug Report

My upload file validator is configured as below:

[
    'type'     => FileInput::class,
    'name'     => 'image_2',
    'required' => false,
    'validators' => [
        [
            'name'    => 'FileUploadFile',
        ],
        [
            'name'    => 'FileMimeType',                        
            'options' => [                            
                'mimeType'  => [
                    'image/jpeg', 
                    'image/png'
                ]
            ]
        ],
        [
            'name'    => 'FileIsImage'
        ],                          
        [
            'name'    => 'FileImageSize',                        
            'options' => [                            
                'minWidth'  => 128,
                'minHeight' => 128,
                'maxWidth'  => 4096,
                'maxHeight' => 4096
            ]
        ],                    
    ],
    'filters'  => [                    
        [
            'name' => 'FileRenameUpload',
            'options' => [  
                'target'             => './public/img',
                'useUploadName'      => false,
                'useUploadExtension' => true,
                'overwrite'          => true,
                'randomize'          => true,
            ]
        ]
    ],     
],

Error ATTACK is send from validador FileUploadFile:
ATTACK => "File '%value%' was illegally uploaded. This could be a possible attack"

The error comes from:

if (! is_uploaded_file($content['tmp_name'])) {
    $this->throwError($content, self::ATTACK);
}

The function is_uploaded_file returns false always after call move_upload_file.

The function move_upload_file is call from Filter FileRenameUpload.

I believe the ATTACK error is correct, but if I call FileUploadRename the ATTACK error will be called inconveniently.

This is unexpected behavior in the development of features, or is there a way to disable ATTACK error so that this does not occur.

@diegobittencourt diegobittencourt added the Bug Something isn't working label Mar 25, 2022
@Ocramius
Copy link
Member

Once the file is moved, any kind of upload validation will obviously fail.

In practice, the "is uploaded file" validation can only be performed when validating unfiltered input.

@Ocramius Ocramius added Documentation Documentation Needed and removed Bug Something isn't working labels Mar 27, 2022
@froschdesign
Copy link
Member

@diegobittencourt
Unfortunately, I cannot reproduce the problem.

This is my short test:

include_once __DIR__ . '/vendor/autoload.php';

if (count($_FILES)) {
    $config = [
        [
            'type'       => Laminas\InputFilter\FileInput::class,
            'name'       => 'image',
            'validators' => [
                [
                    'name' => Laminas\Validator\File\UploadFile::class,
                ],
                [
                    'name'    => Laminas\Validator\File\MimeType::class,
                    'options' => [
                        'mimeType' => [
                            'image/jpeg',
                            'image/png',
                        ],
                    ],
                ],
                [
                    'name' => Laminas\Validator\File\IsImage::class,
                ],
                [
                    'name'    => Laminas\Validator\File\ImageSize::class,
                    'options' => [
                        'minWidth'  => 128,
                        'minHeight' => 128,
                        'maxWidth'  => 4096,
                        'maxHeight' => 4096,
                    ],
                ],
            ],
            'filters'    => [
                [
                    'name'    => Laminas\Filter\File\RenameUpload::class,
                    'options' => [
                        'target'               => './docs',
                        'use_upload_name'      => false,
                        'use_upload_extension' => true,
                        'overwrite'            => true,
                        'randomize'            => true,
                    ],
                ],
            ],
        ],
    ];

    $inputFilter = (new Laminas\InputFilter\Factory())
        ->createInputFilter($config)
        ->setData($_FILES);

    var_dump($_FILES);
    var_dump($inputFilter->isValid());
    var_dump($inputFilter->getMessages());

    // Execute rename filter
    $inputFilter->getValues();
}
?>
<form method="post" enctype="multipart/form-data">
    <input type="file" name="image">
    <input type="submit">
</form>

@Ocramius

Once the file is moved, any kind of upload validation will obviously fail.

The input Laminas\InputFilter\FileInput::class of laminas-inputfilter runs the validators before the filters (the opposite behaviour of Laminas\InputFilter\Input::class). So everything works as expected.

@gsteel
Copy link
Member

gsteel commented Jul 11, 2024

This > 2 year old issue does not seem to be an issue…

@gsteel gsteel closed this as not planned Won't fix, can't repro, duplicate, stale Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Invalid This doesn't seem right Question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants