Skip to content

Commit badf23b

Browse files
committed
Check types for solution handler upload
1 parent 2947c30 commit badf23b

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

api/src/main/resources/application.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ csm:
101101
authorized-mime-types:
102102
workspaces:
103103
- application/zip
104+
- application/xml
104105
- application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
105106
- application/x-tika-ooxml
106107
- text/csv
@@ -111,6 +112,7 @@ csm:
111112
- application/x-sh
112113
- text/x-python
113114
- text/plain
115+
- text/x-yaml
114116
vendor: azure
115117
azure:
116118
appIdUri: "http://dev.api.cosmotech.com"

build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ allprojects {
4949
apply(plugin = "io.gitlab.arturbosch.detekt")
5050

5151
repositories {
52-
mavenLocal()
5352
maven {
5453
name = "GitHubPackages"
5554
url = uri("https://maven.pkg.github.com/Cosmo-Tech/cosmotech-api-common")

solution/src/main/kotlin/com/cosmotech/solution/azure/SolutionServiceImpl.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import com.cosmotech.api.events.OrganizationRegistered
1212
import com.cosmotech.api.events.OrganizationUnregistered
1313
import com.cosmotech.api.exceptions.CsmAccessForbiddenException
1414
import com.cosmotech.api.exceptions.CsmResourceNotFoundException
15+
import com.cosmotech.api.utils.ResourceScanner
1516
import com.cosmotech.api.utils.changed
1617
import com.cosmotech.api.utils.compareToAndMutateIfNeeded
1718
import com.cosmotech.api.utils.getCurrentAuthenticatedUserName
@@ -37,6 +38,7 @@ import org.springframework.stereotype.Service
3738
internal class SolutionServiceImpl(
3839
private val resourceLoader: ResourceLoader,
3940
private val azureStorageBlobServiceClient: BlobServiceClient,
41+
private val resourceScanner: ResourceScanner,
4042
) : CsmAzureService(), SolutionApiService {
4143

4244
override fun findAllSolutions(organizationId: String) =
@@ -243,9 +245,6 @@ internal class SolutionServiceImpl(
243245
solution.name,
244246
solution.version)
245247

246-
// Security checks
247-
// TODO Security-wise, we should also check the content of the archive for potential attack
248-
// vectors, like upload of malicious files, zip bombing, path traversal attacks, ...
249248
try {
250249
val archiverType = ArchiveStreamFactory.detect(body.inputStream.buffered())
251250
if (ArchiveStreamFactory.ZIP != archiverType) {
@@ -256,6 +255,8 @@ internal class SolutionServiceImpl(
256255
throw IllegalArgumentException("A Zip Archive is expected.", ae)
257256
}
258257

258+
resourceScanner.scanMimeTypes(body, csmPlatformProperties.upload.authorizedMimeTypes.handlers)
259+
259260
azureStorageBlobServiceClient
260261
.getBlobContainerClient(organizationId.sanitizeForAzureStorage())
261262
.getBlobClient(

workspace/src/test/kotlin/com/cosmotech/workspace/azure/WorkspaceServiceImplTests.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class WorkspaceServiceImplTests {
7373
every { csmPlatformPropertiesAuthorizedMimeTypes.workspaces } returns
7474
listOf(
7575
"application/zip",
76+
"application/xml",
7677
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
7778
"application/x-tika-ooxml",
7879
"text/csv",

0 commit comments

Comments
 (0)