Skip to content

Commit c412c97

Browse files
committed
fix: enforce Content-Type to accept only binary responses
Add validation for CLI downloads that ensures the Content-Type header is indicating a binary stream (`application/octet-stream`), including common variants with parameters. This prevents saving unexpected HTML or other non-binary responses (e.g., from frontend dev servers on :8080) as binaries, improving reliability and providing clearer error feedback.
1 parent 3b88d15 commit c412c97

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Changed
6+
7+
- content-type is now enforced when downloading the CLI to accept only binary responses
8+
59
## 0.6.1 - 2025-08-11
610

711
### Added

src/main/kotlin/com/coder/toolbox/cli/downloader/CoderDownloadService.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ class CoderDownloadService(
5151

5252
return when (response.code()) {
5353
HTTP_OK -> {
54+
val contentType = response.headers()["Content-Type"]?.lowercase()
55+
if (contentType?.startsWith("application/octet-stream") != true) {
56+
throw ResponseException(
57+
"Invalid content type '$contentType' when downloading CLI from $remoteBinaryURL. Expected application/octet-stream.",
58+
response.code()
59+
)
60+
}
5461
context.logger.info("Downloading binary to temporary $cliTempDst")
5562
response.saveToDisk(cliTempDst, showTextProgress, buildVersion)?.makeExecutable()
5663
DownloadResult.Downloaded(remoteBinaryURL, cliTempDst)

0 commit comments

Comments
 (0)