-
Notifications
You must be signed in to change notification settings - Fork 6
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
fix: Check file extension instead of mimeType [WPB-10605] #2950
Conversation
Datadog ReportAll test runs ✅ 2 Total Test Services: 0 Failed, 2 Passed Test Services
|
@@ -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)) { |
There was a problem hiding this comment.
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
There was a problem hiding this 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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 { |
There was a problem hiding this comment.
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 ?: "", |
There was a problem hiding this comment.
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
Quality Gate passedIssues Measures |
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.