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

fix: Check file extension instead of mimeType [WPB-10605] #2950

Conversation

borichellow
Copy link
Contributor

What's new in this PR?

Issues

in ValidateAssetMimeTypeUseCase when we calculate if file can be shared or not we were comparing files mimeType to list of allowed Extensions.

Causes (Optional)

Just was implemented in that way long time ago.

Solutions

fix it and compare files extension to list of allowed Extensions.

Copy link
Contributor

github-actions bot commented Aug 15, 2024

Test Results

2 927 tests   2 804 ✔️  27s ⏱️
   497 suites     123 💤
   497 files           0

Results for commit 5774d19.

♻️ This comment has been updated with latest results.

@datadog-wireapp
Copy link

datadog-wireapp bot commented Aug 15, 2024

Datadog Report

All test runs 5189aa6 🔗

2 Total Test Services: 0 Failed, 2 Passed

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Test Service View
kalium-ios 0 0 0 2804 123 1.64s Link
kalium-jvm 0 0 0 2955 107 6.81s Link

@@ -133,7 +133,7 @@ internal class ScheduleNewAssetMessageUseCaseImpl(
FileSharingStatus.Value.EnabledAll -> { /* no-op*/
}

is FileSharingStatus.Value.EnabledSome -> if (!validateAssetMimeTypeUseCase(assetMimeType, it.state.allowedType)) {
is FileSharingStatus.Value.EnabledSome -> if (!validateAssetMimeTypeUseCase(assetName, it.state.allowedType)) {
Copy link
Member

Choose a reason for hiding this comment

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

can we change the name of the user case to reflect what it does now

Copy link
Contributor

@yamilmedina yamilmedina left a comment

Choose a reason for hiding this comment

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

Looking good :D left some questions and suggestions 🙌

* Returns true if the mime type is allowed and false otherwise.
* @param mimeType the mime type to validate.
* Returns true if the file extension is present in file name and is allowed and false otherwise.
* @param fileName the file name (with extension) to validate.
* @param allowedExtension the list of allowed extension.
*/
interface ValidateAssetMimeTypeUseCase {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
interface ValidateAssetMimeTypeUseCase {
interface ValidateAssetFileTypeUseCase {

val extension = mimeType.split("/").last().lowercase()
return allowedExtension.any {
it.lowercase() == extension
override operator fun invoke(fileName: String, allowedExtension: List<String>): Boolean {
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: What if we have multiple extensions hiding in the file or other type of tricks ? Would be good idea to follow some of these tips ?

https://book.hacktricks.xyz/pentesting-web/file-upload#bypass-file-extensions-checks

@@ -53,7 +53,7 @@ internal class AssetMessageHandlerImpl(
FileSharingStatus.Value.EnabledAll -> true

is FileSharingStatus.Value.EnabledSome -> validateAssetMimeTypeUseCase(
messageContent.value.mimeType,
messageContent.value.name ?: "",
Copy link
Member

Choose a reason for hiding this comment

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

to avoid any hidden bugs we can pass the name as nullable string and handle the null case by returning not valid

Copy link

@MohamadJaara MohamadJaara merged commit 9db15f2 into release/android-cycle-4.6 Aug 16, 2024
19 checks passed
@MohamadJaara MohamadJaara deleted the fix/check-file-extension-instead-of-mimetype branch August 16, 2024 09:00
@echoes-hq echoes-hq bot added the echoes: unplanned Any work item that isn’t part of the product or technical roadmap. label Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
echoes: unplanned Any work item that isn’t part of the product or technical roadmap. 🚨 Potential breaking changes 👕 size: L type: bug / fix 🐞
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants