Overview
Impact: Medium | Priority: P2 | Effort: Medium
The native library download tasks in multiple Kotlin Multiplatform modules use URL().openStream() without connection/read timeouts and lack checksum verification. This poses supply chain security risks and can cause builds to hang indefinitely on network issues.
Problem Statement
What's the issue?
The download logic in build.gradle.kts files for:
runanywhere-core-jni
runanywhere-core-llamacpp
runanywhere-core-onnx
Uses URL(downloadUrl).openStream() which:
- Has no connection or read timeout - builds can hang indefinitely on network issues
- Lacks checksum verification - downloaded binaries are not validated, creating supply chain security risk
Why does it matter?
- Build reliability: Network issues can cause CI/CD pipelines to hang indefinitely
- Security: Without checksum verification, compromised binaries could be downloaded without detection
- Maintainability: The same download logic is duplicated across three modules
Current State
Affected files:
sdk/runanywhere-kotlin/modules/runanywhere-core-jni/build.gradle.kts (lines 212-229)
sdk/runanywhere-kotlin/modules/runanywhere-core-llamacpp/build.gradle.kts (lines 218-235)
sdk/runanywhere-kotlin/modules/runanywhere-core-onnx/build.gradle.kts (similar pattern)
Current code pattern:
URL(downloadUrl).openStream().use { input ->
zipFile.outputStream().use { output ->
input.copyTo(output)
}
}
Proposed Solution
1. Add connection and read timeouts
val connection = URL(downloadUrl).openConnection() as HttpURLConnection
connection.connectTimeout = 30_000 // 30 seconds
connection.readTimeout = 120_000 // 2 minutes for large files
connection.inputStream.use { input ->
// ...
}
2. Add SHA256 checksum verification
- Download
.sha256 checksum files alongside binaries
- Verify downloaded file against expected checksum before extraction
- Fail build if checksum doesn't match
3. Extract to shared Gradle convention plugin
Create a shared build logic module to avoid duplication:
sdk/runanywhere-kotlin/build-logic/
├── build.gradle.kts
└── src/main/kotlin/
└── NativeLibraryDownloadPlugin.kt
Implementation Plan
Success Criteria
Related
Overview
Impact: Medium | Priority: P2 | Effort: Medium
The native library download tasks in multiple Kotlin Multiplatform modules use
URL().openStream()without connection/read timeouts and lack checksum verification. This poses supply chain security risks and can cause builds to hang indefinitely on network issues.Problem Statement
What's the issue?
The download logic in
build.gradle.ktsfiles for:runanywhere-core-jnirunanywhere-core-llamacpprunanywhere-core-onnxUses
URL(downloadUrl).openStream()which:Why does it matter?
Current State
Affected files:
sdk/runanywhere-kotlin/modules/runanywhere-core-jni/build.gradle.kts(lines 212-229)sdk/runanywhere-kotlin/modules/runanywhere-core-llamacpp/build.gradle.kts(lines 218-235)sdk/runanywhere-kotlin/modules/runanywhere-core-onnx/build.gradle.kts(similar pattern)Current code pattern:
Proposed Solution
1. Add connection and read timeouts
2. Add SHA256 checksum verification
.sha256checksum files alongside binaries3. Extract to shared Gradle convention plugin
Create a shared build logic module to avoid duplication:
Implementation Plan
build-logicmodule with shared download utilitiesHttpURLConnectionwith timeoutsrunanywhere-core-jnito use shared pluginrunanywhere-core-llamacppto use shared pluginrunanywhere-core-onnxto use shared plugin.sha256filesSuccess Criteria
Related