Skip to content

Fix content_type detection for extensions GitHub rejects (#32) - #33

Merged
drogers0 merged 1 commit into
mainfrom
fix/content-type-allowlist-issue-32
Jul 20, 2026
Merged

Fix content_type detection for extensions GitHub rejects (#32)#33
drogers0 merged 1 commit into
mainfrom
fix/content-type-allowlist-issue-32

Conversation

@drogers0

Copy link
Copy Markdown
Owner

Fixes #32.

Problem

detectContentType relied on mime.TypeByExtension, whose output GitHub's upload policy endpoint (POST /upload/policies/assets) rejects with 422 content_type is not included in the list for many extensions:

  • .jpg (the reported bug): on Windows, Go's mime reads the registry, which commonly returns legacy image/pjpeg / image/jpg. GitHub only accepts image/jpeg. Renaming to .jpeg worked because that path yielded image/jpeg.
  • Broken on macOS/Linux too: for several code/data extensions (.md, .yaml, .yml, .jsonc, .cs, .php, .py, .patch, .cpuprofile, .ipynb, .tsx, .tgz) Go's mime table returns nothing, so detectContentType fell back to application/octet-stream, which GitHub rejects for text types. Uploading these advertised file types failed on every platform.
  • Wrong values: .wavaudio/x-wav, .cpptext/x-c, .tsvideo/mp2t (the well-known MPEG-TS collision), .pdbapplication/vnd.palm, .sqlapplication/x-sql — all rejected.

Fix

Expand the existing githubContentType override map (which previously held only .log) with 21 entries. Each accepted value was verified against GitHub's live policy endpoint (HTTP 201), and the type Go would otherwise send was verified rejected (422). Only extensions Go gets wrong are pinned; extensions whose mime value GitHub already accepts continue to use the mime.TypeByExtension fallback.

Notable verified mappings: .tstext/typescript, .tsxtext/tsx, .jstext/javascript (GitHub rejects application/javascript), .yaml/.ymlapplication/x-yaml (GitHub rejects text/yaml).

Testing

  • Added cases to TestDetectContentType in internal/upload/upload_test.go.
  • go build ./..., go vet ./..., and go test ./... all pass.

detectContentType relied on mime.TypeByExtension, whose output GitHub's
upload policy endpoint rejects (422 "content_type is not included in the
list") for many extensions:

  - On Windows, mime reads the registry, which returns legacy types for
    JPEG (image/pjpeg / image/jpg) — the failure reported in #32.
  - On every OS, Go has no mapping for several code/data extensions
    (.md, .yaml, .py, .ts, .tsx, ...), so detectContentType fell back to
    application/octet-stream, which GitHub rejects for text types. This
    broke uploads of those file types even on macOS/Linux.
  - A few extensions map to a type GitHub rejects (.wav -> audio/x-wav,
    .cpp -> text/x-c, .ts -> video/mp2t, .pdb -> application/vnd.palm,
    .sql -> application/x-sql).

Expand the githubContentType override map with 21 entries, each verified
accepted (HTTP 201) against GitHub's policy endpoint, covering only the
extensions Go would otherwise get wrong. Extensions whose mime value is
already accepted continue to use the mime fallback.
@drogers0
drogers0 merged commit 78948bc into main Jul 20, 2026
2 checks passed
@drogers0
drogers0 deleted the fix/content-type-allowlist-issue-32 branch July 20, 2026 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.jpg uploads fail with 422 content_type not included in list — emits legacy image/jpg or image/pjpeg instead of image/jpeg

1 participant