Skip to content

Commit eb50b7c

Browse files
fix: validate redirect host against allowlist to prevent SSRF bypass
Re-validate each redirected URL's host against allowedDownloadHosts inside the resolveRedirects loop, preventing an attacker from using a trusted initial URL that redirects to an internal/restricted resource. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d0f86fe commit eb50b7c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

android/app/src/main/java/ai/offgridmobile/download/DownloadManagerModule.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,18 @@ class DownloadManagerModule(reactContext: ReactApplicationContext) :
397397
if (responseCode in 300..399) {
398398
val location = connection.getHeaderField("Location")
399399
if (location.isNullOrEmpty()) return currentUrl
400-
currentUrl = if (location.startsWith("http")) {
400+
val nextUrl = if (location.startsWith("http")) {
401401
location
402402
} else {
403403
URL(URL(currentUrl), location).toString()
404404
}
405+
// Re-validate redirected host against allowlist to prevent SSRF bypass
406+
val nextHost = try { URL(nextUrl).host } catch (_: Exception) { null }
407+
if (nextHost == null || !allowedDownloadHosts.any { nextHost == it || nextHost.endsWith(".$it") }) {
408+
android.util.Log.w("DownloadManager", "Redirect to unauthorized host blocked: $nextHost")
409+
return currentUrl
410+
}
411+
currentUrl = nextUrl
405412
} else {
406413
return currentUrl
407414
}

0 commit comments

Comments
 (0)