Skip to content

bug(ocdav): TUS create returns a bare 412 on an invalid name; PUT/MOVE/COPY/MKCOL return 400 with a message #654

Closed

Description

@michaelstingl

Describe the bug

The ocdav name validation rejects a configured set of characters; the default set includes the backslash. On that rejection the write handlers respond differently. The TUS create handler returns a bare 412 Precondition Failed with no body. put.go, move.go, copy.go, and mkcol.go return 400 Bad Request with a naming message. The inconsistent status and the missing body leave clients unable to tell the user why an upload failed.

Steps to reproduce

Run against a space (the filename in Upload-Metadata is base64):

# TUS create, name contains a backslash
POST /dav/spaces/<spaceID>     Upload-Metadata: filename <base64 of "...IM\000024">
  -> 412 Precondition Failed, empty body

# same name without the backslash
PUT  /dav/spaces/<spaceID>/...IM000024
  -> 201 Created

# MOVE an existing file onto a backslash name (raw "\" and percent-encoded %5C)
MOVE /dav/spaces/<spaceID>/clean   Destination: .../...IM\000024
  -> 400 Bad Request ("destination naming rules")

Expected behavior

The TUS create path reports an invalid name the same way the other write handlers do: 400 Bad Request with the ValidateName error in the body. Clients can then surface the reason.

The TUS spec supports this. It leaves the status for a metadata-based rejection to the server (the server MAY reject an upload based on Upload-Metadata, with no prescribed code), and it reserves 412 Precondition Failed for one case: an unsupported Tus-Resumable version, where the response must also carry a Tus-Version header. A bare 412 for an invalid name overlaps that reserved meaning, so a TUS-aware client can read it as a version problem. 400 is also what TUS uses for a malformed creation request.

The other handlers were aligned in:

Actual behavior

In internal/http/services/owncloud/ocdav/tus.go (the ValidateName branch, current main), the handler calls w.WriteHeader(http.StatusPreconditionFailed) and returns, with no body. put.go, move.go, copy.go, and mkcol.go return 400 via errors.Marshal(...) on the same ValidateName/ValidateDestination failure. The TUS create path is therefore the only write handler that returns a 412 with no reason.

Setup

reva v2.46.x as bundled in OpenCloud 6.1.0 (rolling). Reproduced over HTTP with curl, and with the OpenCloud desktop client 3.0.3 and the web UI. Default NameValidation.InvalidChars (\f, \r, \n, \).

Additional context

The user-facing symptom was reported in:

With the bare 412 and no body, the desktop client shows an empty "server replied:" and blacklists the file, with no recovery until it is renamed. The web UI shows "Unbekannter Fehler" with only an X-Request-Id. The 412 ("Precondition Failed") also reads as a protocol or header precondition rather than an invalid name.

🤖 drafted with Claude Code, reviewed before submitting.

Activity

  1. michaelstingl commented on Jun 1, 2026

    @michaelstingl
    Author

    History

    Name validation reached the TUS create path in one commit, "disallow reserved names", which wired the check to the 412 already used by the nearby precondition checks in the same function. The same pull request changed put.go to return 400 with the marshalled body, so the two branches diverged by which neighbour each copied.

    The first upload and move name checks came earlier.

    The acceptance scenario that pins 412 was copied from the ownCloud 10 test suite.

    OpenCloud acceptance tests

    The api-integration suite pins the current 412, so aligning the status turns these red until they move to 400:

    The other checks in those scenarios (no Location, file not created) stay valid, so the update is the status value only.

    Clients

    From reading each client's handling of the create response, not from running them against a patched build, no client depends on the 412:

    • web (tus-js-client): 412 and 400 are both non-retryable 4xx, handled identically.
    • desktop: the create 412 is classified as an etag or checksum precondition ("the e-tag has changed"), so it schedules a remote re-discovery and a soft retry that cannot succeed for an invalid name. 400 classifies as a hard error.
    • Android (OpenCloud Android library): 412 maps to a conflict result, with the in-code note "for TUS, 412 typically indicates Upload-Offset precondition mismatch". 400 drops that mapping.
    • iOS SDK (OpenCloudSDK): the TUS create path returns a generic status error for any non-201, identical for 412 and 400.

    So no client reads the create 412 as an invalid name, and 400 is at least as safe everywhere.

    🤖 drafted with Claude Code, reviewed before submitting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions