Skip to content

fix(tus): restore Upload-Checksum validation broken by tusd v2 [stable-9.0] - #13681

Open
mmattel wants to merge 3 commits into
stable-9.0from
backport/stable-9.0-tus-checksum
Open

mmattel wants to merge 3 commits into
stable-9.0from
backport/stable-9.0-tus-checksum

Conversation

@mmattel

@mmattel mmattel commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Backport of #13666 to stable-9.0.

Includes both commits:

  • Original fix: forward Upload-Checksum from TUS POST into the InitiateFileUpload opaque, store it via SetChecksum on PATCH, verify on FinishUpload, and correct the HTTP status from 419 → 460
  • Base64 fix: checkHash() now decodes the TUS-spec base64 value before comparing against the hex digest (see PR comment on fix(tus): restore Upload-Checksum validation broken by tusd v2 #13666 for root-cause analysis)

Upstream reva fixes: owncloud/reva#883 (main), owncloud/reva#884 (stable-9.0)

🤖 Generated with Claude Code

tusd v2 silently dropped the entire checksum extension. As a result,
any Upload-Checksum header sent on PATCH (or on a POST creation-with-upload)
was ignored: the server advertised the checksum extension but never
actually validated it, returning 204 on uploads with wrong checksums
instead of the required 460 Checksum Mismatch.

Three independent gaps had to be closed:

1. pkg/upload/tus_adapter.go — FinishUpload already switched on
   ChecksumMismatch but mapped it to the internal CS3 code 419 instead
   of the TUS-spec mandated 460. Fixed to return 460.

2. pkg/upload/tus_adapter.go — added SetChecksum() method to tusAdapter
   so the PATCH layer can persist the Upload-Checksum header value into
   the session before tusd processes the chunk.

3. pkg/rhttp/datatx/manager/tus/tus.go — before PatchFile, extract
   Upload-Checksum, normalise algorithm to lowercase, and call SetChecksum
   via a local checksumSetter interface.

4. internal/http/services/owncloud/ocdav/tus.go — add Upload-Checksum to
   the InitiateFileUpload opaque map when present in the POST, so the
   creation-with-upload path also verifies checksums. Mirrors handlePut.

This is a temporary vendor fix pending merge of owncloud/reva#879.
Needs backporting to stable-9.0 and stable-8.2.

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

Signed-off-by: Martin Mattel <github@diemattels.at>
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 matched, 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 size); if decoding succeeds, convert to hex
before comparing.  Plain hex values fall through unchanged.

Upstream fix: owncloud/reva#883

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:39
@update-docs

update-docs Bot commented Dec 3, 2026

Copy link
Copy Markdown

Thanks for opening this pull request! The maintainers of this repository would appreciate it if you would create a changelog item based on your changes.

@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

💻 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.

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

Signed-off-by: Martin Mattel <github@diemattels.at>
@mmattel

mmattel commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

code/snyk check is failing — needs Snyk access to resolve

The code/snyk (Snyk Code SAST) check is in ERROR state. The other two Snyk checks (license/snyk, security/snyk) both pass.

Noteworthy: the identical code changes in the master PR #13666 pass code/snyk cleanly. The failure appears to be specific to the stable-9.0 branch context — most likely a pre-existing Snyk Code finding in one of the five vendor files this PR touches, surfaced by the diff.

Snyk PR-check URL for investigation:
https://app.eu.snyk.io/org/owncloud-infinite-scale/project/19723732-82b3-4add-aae1-42dd3057212c/pr-check/cb5fb86d-aaa5-432a-9fa9-e76b95949ca0

If the finding is a false positive or a pre-existing issue already accepted by the team, it can be marked as ignored in the Snyk UI or suppressed via the repo's .snyk policy file.

This branch has not been deployed

No deployments
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.

2 participants