IBX-11681: Added filename validation in DownloadController and corresponding tests#756
Conversation
aa0bf1c to
1ba641c
Compare
1ba641c to
93d53c1
Compare
mikadamczyk
left a comment
There was a problem hiding this comment.
Could we add an integration test for URL-encoded filenames here? Since the new check uses strict equality $field->value->fileName !== $filename, any encoding or decoding differences in the real request flow may cause valid downloads to be rejected as NotFound. Especially for spaces or special characters.
konradoboza
left a comment
There was a problem hiding this comment.
Looks good but I think providing the test case that Mikołaj has mentioned makes sense.
6b76513 to
be18b9b
Compare
be18b9b to
51d7f2c
Compare
|
| private const FILENAME = 'Q1 report #1 + 100%.jpg'; | ||
|
|
||
| /** @var \Ibexa\Contracts\Core\Repository\ContentService&\PHPUnit\Framework\MockObject\MockObject */ | ||
| private $contentService; |
There was a problem hiding this comment.
Please adjust all the similar:
| private $contentService; | |
| private ContentService $contentService; |
| ]); | ||
|
|
||
| $this->contentService | ||
| ->expects($this->once()) |
There was a problem hiding this comment.
All occurrences should be fixed:
| ->expects($this->once()) | |
| ->expects(self::once()) |
| $controllerResolver = self::getContainer()->get('controller_resolver'); | ||
| self::assertInstanceOf(ControllerResolverInterface::class, $controllerResolver); | ||
|
|
||
| return new HttpKernel($dispatcher, $controllerResolver, $requestStack, new ArgumentResolver()); |
There was a problem hiding this comment.
Newlines for arguments.
| final class DownloadControllerTest extends TestCase | ||
| { | ||
| /** @var \Ibexa\Contracts\Core\Repository\ContentService&\PHPUnit\Framework\MockObject\MockObject */ | ||
| private $contentService; |
There was a problem hiding this comment.
Again, the same remark:
| private $contentService; | |
| private ContentService $contentService; |
| ]); | ||
|
|
||
| $this->contentService | ||
| ->expects($this->once()) |
There was a problem hiding this comment.
| ->expects($this->once()) | |
| ->expects(self::once()) |
|
|
||
| public function testDownloadBinaryFileActionReturnsNotFoundWhenFilenameDoesNotMatch(): void | ||
| { | ||
| $this->expectException(NotFoundException::class); |
There was a problem hiding this comment.
This should be moved to just before triggering the actual function that throws an exception.


Description:
Added filename validation to the content download endpoint for binary files.
Previously,
/content/download/{contentId}/{fieldIdentifier}/{filename}accepted anyfilenamevalue from the URL and still returned the file as long ascontentIdandfieldIdentifiermatched an accessible field. This made it possible to enumerate downloadable files more easily by guessing content identifiers and reusing common field identifiers such asfile.This change makes the download controller verify that the
filenameprovided in the URL matches the actual file name stored in the field value. If it does not match, the controller now returnsNotFoundExceptionbefore loading the binary file from storage.