CVE-2023-6599 (PHP, published 2023-12-08T00:15Z)
Description: value: Missing Standardized Error Handling Mechanism in GitHub repository microweber/microweber prior to 2.0.
Severity: nan (CVSS v3 base score: 4.3)
Weakness: CWE-755 \u2014 Improper Handling of Exceptional Conditions
The product does not handle or incorrectly handles an exceptional condition.
Repository: https://github.com/microweber/microweber
Files changed:
src/MicroweberPackages/FileManager/Http/Controllers/PluploadController.php
src/MicroweberPackages/Media/MediaManager.php
src/MicroweberPackages/Media/Traits/MediaTrait.php
src/MicroweberPackages/Media/migrations/2020_07_02_000000_create_media_table.php
src/MicroweberPackages/Media/tests/LegacyMediaTest.php
Commit message: update


Vulnerable code:
        $fileName = str_replace(array('(', ')', "'", "!", "`", "*", "#"), '_', $fileName);
        $fileName = str_replace(' ', '_', $fileName);
        $fileName = str_replace('..', '.', $fileName);

        if (!isset($s['id']) and isset($s['filename']) and !isset($data['media_type'])) {
        if (isset($s['filename']) && is_array($s['filename'])) {
            if (isset($s['filename']['error'])) {
                return false;
            }
        }
                                'src' => $url,
                $table->text('embed_code')->nullable();
class MediaTest extends TestCase
            'src' => 'http://lorempixel.com/400/200/',
            'src' => 'http://lorempixel.com/400/200/',

Fixed code:
        $fileName = str_replace(array('(', ')', "'", "!", "`", "*", "#", "<", ">"), '-', $fileName);
        $fileName = str_replace(' ', '-', $fileName);
        $fileName = str_replace('..', '-', $fileName);
        $data = xss_clean($data);
        if (isset($s['filename']) && !is_string($s['filename'])) {
           return false;
        }
            and is_string($s['filename'])
        if (!isset($s['id']) and isset($s['filename']) and is_string($s['filename']) and !isset($data['media_type'])) {
                                'filename' => $url,
                //$table->text('embed_code')->nullable();
class LegacyMediaTest extends TestCase
            'filename' => 'http://lorempixel.com/400/200/',
            'filename' => 'http://lorempixel.com/400/200/',
    }

    public function testSaveMediaArrayInFilename()
    {
        $picture = array(
            'rel_type' => 'content',
            'rel_id' => 3,
            'title' => 'My new pic',
            'media_type' => 'picture',
            'filename' => ['http://lorempixel.com/400/200/', 'http://lorempixel.com/400/200/'],
        );
        $saved_pic_id = save_media($picture);

        $this->assertFalse($saved_pic_id);
    }
    public function testSaveMediaXssFilename()
    {
        $xss = '<style>@keyframes x{}</style><xss style="animation-name:x" onanimationend="alert(document.cookie)"></xss>';

        $picture = array(
            'rel_type' => 'content',
            'rel_id' => 3,
            'title' => 'My new pic to xss'.$xss,
            'description' => 'My new pic description xss'.$xss,
            'media_type' => 'picture',
            'filename' => 'http://lorempixel.com/400/200/'.$xss,
        );
        $saved_pic_id = save_media($picture);
        $picture_data = get_media_by_id($saved_pic_id);

        $this->assertNotEquals($picture_data['title'], $picture['title']);
        $this->assertNotEquals($picture_data['description'], $picture['description']);
        $this->assertNotEquals($picture_data['filename'], $picture['filename']);