Fix banned mime type errors in DefaultContentScannerService (#7255)

The content scanner allows disabling certain mime types for files in the set up HS, but it turns out for the scan operation instead of returning an `"is_valid": false` result in that case, it returns an error with a `MCS_MIME_TYPE_FORBIDDEN` reason. We need to handle that case as if it had returned the false `isValid` value.
This commit is contained in:
Jorge Martin Espinosa
2026-07-22 16:48:44 +02:00
committed by GitHub
parent 05917bd65f
commit 18034e02a2
2 changed files with 18 additions and 6 deletions
@@ -10,6 +10,7 @@ package io.element.android.features.contentscanner.impl
import io.element.android.features.contentscanner.api.ContentScannerService
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
import io.element.android.libraries.matrix.api.core.EventId
import io.element.android.libraries.matrix.api.exception.ClientException
import io.element.android.libraries.matrix.api.media.MediaSource
import io.element.android.libraries.matrix.api.scanner.ContentScanner
import io.element.android.libraries.matrix.ui.media.contentvalidation.ContentValidationState
@@ -42,12 +43,19 @@ class DefaultContentScannerService(
contentValidationState.update(url, contentValidationValue)
}
.onFailure { exception ->
if (exception is IOException) {
// If it's an IO-related exception, we can retry later, so we don't store the error
contentValidationState.update(url, ContentValidationValue.Unknown)
} else {
// For other exceptions, we cache the failure
contentValidationState.update(url, ContentValidationValue.UnrecoverableError(exception))
when (exception) {
is IOException -> {
// If it's an IO-related exception, we can retry later, so we don't store the error
contentValidationState.update(url, ContentValidationValue.Unknown)
}
is ClientException.ContentScanner if exception.reason.isDangerous() -> {
// It's a dangerous content (banned mime-type?), we mark it as invalid
contentValidationState.update(url, ContentValidationValue.Invalid)
}
else -> {
// For other exceptions, we cache the failure
contentValidationState.update(url, ContentValidationValue.UnrecoverableError(exception))
}
}
}
}