Skip to content

IBX-11681: Added filename validation in DownloadController and corresponding tests#756

Open
wiewiurdp wants to merge 2 commits into
4.6from
IBX-11681-Possibility-to-download-all-files-using-a-loop-which-may-cause-DDoS
Open

IBX-11681: Added filename validation in DownloadController and corresponding tests#756
wiewiurdp wants to merge 2 commits into
4.6from
IBX-11681-Possibility-to-download-all-files-using-a-loop-which-may-cause-DDoS

Conversation

@wiewiurdp
Copy link
Copy Markdown
Contributor

🎫 Issue IBX-11681

Description:

Added filename validation to the content download endpoint for binary files.

Previously, /content/download/{contentId}/{fieldIdentifier}/{filename} accepted any filename value from the URL and still returned the file as long as contentId and fieldIdentifier matched an accessible field. This made it possible to enumerate downloadable files more easily by guessing content identifiers and reusing common field identifiers such as file.

This change makes the download controller verify that the filename provided in the URL matches the actual file name stored in the field value. If it does not match, the controller now returns NotFoundException before loading the binary file from storage.

@wiewiurdp wiewiurdp force-pushed the IBX-11681-Possibility-to-download-all-files-using-a-loop-which-may-cause-DDoS branch from aa0bf1c to 1ba641c Compare May 25, 2026 13:05
@wiewiurdp wiewiurdp force-pushed the IBX-11681-Possibility-to-download-all-files-using-a-loop-which-may-cause-DDoS branch from 1ba641c to 93d53c1 Compare May 25, 2026 13:10
@wiewiurdp wiewiurdp marked this pull request as ready for review May 25, 2026 13:49
@wiewiurdp wiewiurdp requested a review from a team May 25, 2026 13:49
@ibexa-workflow-automation-1 ibexa-workflow-automation-1 Bot requested review from Steveb-p, ViniTou, alongosz, barw4, bnowak, ciastektk, konradoboza, mikadamczyk and tbialcz and removed request for a team May 25, 2026 13:49
Copy link
Copy Markdown
Contributor

@mikadamczyk mikadamczyk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

@konradoboza konradoboza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good but I think providing the test case that Mikołaj has mentioned makes sense.

@@ -0,0 +1,142 @@
<?php

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declaring strict types is missing.

Comment on lines +29 to +30
/** @var \Ibexa\Contracts\Core\Repository\ContentService|\PHPUnit\Framework\MockObject\MockObject */
private $contentService;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please apply the similar to the other properties:

Suggested change
/** @var \Ibexa\Contracts\Core\Repository\ContentService|\PHPUnit\Framework\MockObject\MockObject */
private $contentService;
/** @var \Ibexa\Contracts\Core\Repository\ContentService&\PHPUnit\Framework\MockObject\MockObject */
private ContentService $contentService;

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
11.8% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants