Skip to content

fix(tus): accept base64-encoded checksums in Upload-Checksum header [stable-8.2] - #885

Open
mmattel wants to merge 3 commits into
stable-8.2from
backport-883-to-stable-8.2
Open

mmattel wants to merge 3 commits into
stable-8.2from
backport-883-to-stable-8.2

Conversation

@mmattel

@mmattel mmattel commented Dec 3, 2026

Copy link
Copy Markdown

Backport of #883 to stable-8.2.

Note: on this branch checkHash lives in two places (pre-coordinator refactor):

  • pkg/storage/utils/decomposedfs/upload/upload.go
  • pkg/ocm/storage/received/upload.go

Both are fixed. See #883 for full details.

🤖 Generated with Claude Code

The TUS protocol spec requires the Upload-Checksum header value to be
base64-encoded.  The TusPhp client (used in acceptance tests) always
sends base64.  checkHash() was comparing the raw base64 string against
hex.EncodeToString(), which never matches, so every upload that sent a
checksum received HTTP 460 Checksum Mismatch.

Decode from base64 first (using h.Size() to verify the decoded length
matches the expected hash); if decoding succeeds, convert to hex before
comparing.  Plain hex values (from direct API callers) fall through
unchanged, so backward compatibility is preserved.

Relates to #879 (which re-enabled checksum validation but missed the
encoding difference between TUS clients and the internal hex format).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Signed-off-by: Martin Mattel <github@diemattels.at>
@mmattel
mmattel requested a review from a team as a code owner December 3, 2026 17:23
@kw-security

kw-security commented Dec 3, 2026 •

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues
✅ Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

For multi-chunk TUS uploads each PATCH carries the checksum of that
chunk only, not the whole-file checksum. Storing a per-chunk checksum
for FinishUpload whole-file validation caused every chunked upload with
per-chunk checksums to fail with 460 Checksum Mismatch.

Restrict SetChecksum() to single-chunk uploads: offset == 0 and
Content-Length equals the declared upload size. For multi-chunk uploads
the Upload-Checksum header is silently ignored, preserving the existing
behaviour that tusd v2 established when it dropped per-chunk validation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Signed-off-by: Martin Mattel <github@diemattels.at>
stable-8.2 passes fs directly as tusd.DataStore instead of the
upload.Coordinator abstraction introduced in later branches; add a
comment explaining why the type assertion is safe here.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Signed-off-by: Martin Mattel <github@diemattels.at>
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.

3 participants