fix: cap Base64 media transfers at 10 MB, upload limit at most 32 MB

This commit is contained in:
2026-09-26 05:04:38 +02:00
parent 7f58301a71
commit 28bb033a8b
12 changed files with 122 additions and 25 deletions
@@ -62,6 +62,18 @@ final class MediaDownloadAbilityTest extends TestCase
self::assertSame('lit_unsupported', $result->get_error_code());
}
public function testDownloadsAreCappedAtTenMegabytesEvenWithAHigherUploadLimit(): void
{
Functions\when('get_option')->justReturn(['upload_mb' => 32]);
file_put_contents($this->file, str_repeat('x', 10 * 1024 * 1024 + 1));
$result = (new MediaDownloadAbility(new Limits()))->execute(['id' => 40]);
self::assertSame('lit_unsupported', $result->get_error_code());
self::assertStringContainsString('Limit 10 MB', $result->get_error_message());
self::assertStringContainsString('URL', (string) $result->get_error_data()['hint']);
}
public function testUnknownSizeIsNotFound(): void
{
Functions\when('get_option')->justReturn([]);
@@ -131,6 +131,18 @@ final class MediaImporterTest extends TestCase
self::assertSame([], $this->tempFiles, 'no temp file may be written for an oversized upload');
}
public function testBase64UploadsAreCappedAtTenMegabytesEvenWithAHigherUploadLimit(): void
{
Functions\when('get_option')->justReturn(['upload_mb' => 32]);
$result = $this->importer()->fromBase64(str_repeat('A', 16 * 1024 * 1024), 'big.png', []);
self::assertSame('lit_validation_failed', $result->get_error_code());
self::assertStringContainsString('Limit 10 MB', $result->get_error_message());
self::assertStringContainsString('lit/media-upload-from-url', (string) $result->get_error_data()['hint']);
self::assertSame([], $this->tempFiles);
}
public function testInvalidBase64IsRejected(): void
{
$result = $this->importer()->fromBase64('***', 'x.png', []);
@@ -154,4 +154,12 @@ final class MediaUploadAbilitiesTest extends TestCase
self::assertFalse($ability->isDirect());
self::assertTrue((new MediaUploadFromUrlAbility(Mockery::mock(MediaImporter::class), $this->uploads()))->isDirect());
}
public function testDescriptionNamesTheTenMegabyteCapForBase64(): void
{
Functions\when('get_option')->justReturn(['upload_mb' => 32]);
$ability = new MediaUploadAbility(Mockery::mock(MediaImporter::class), $this->uploads(), new Limits());
self::assertStringContainsString('höchstens 10 MB', $ability->description());
}
}