WebDAV: move the If-Match check into the versions commit step #951

Closed
opened 2026-10-17 02:01:29 +00:00 by Cordy · 4 comments
Owner

From the fix-922 spec §14 (2026-10-16).

What happens: WebDAV PUT with If-Match checks the ETag before the write starts. Since v0.6.347 the versions engine has a commit step that runs under a lock on the path: it checks what the path holds right before publishing. Another save can still land between the If-Match check and that commit step. That save is then replaced, although it is kept as a version, so nothing is lost. A client relying on If-Match for optimistic concurrency, such as a sync client, therefore gets 2xx instead of 412 in that window.

Expected: the precondition is evaluated at the commit step. If the path no longer has the expected ETag there, the save is refused with 412, and nothing is published.

To do:

  • Pass the expected ETag through the context into the record plan's commit.
  • Compare it under the lock and answer 412 (storage.ErrPrecondition or similar).
  • Same for WOPI's X-COOL-WOPI-Timestamp if it fits.
  • Add tests for the race, using the record hook.
From the fix-922 spec §14 (2026-10-16). **What happens:** WebDAV `PUT` with `If-Match` checks the ETag before the write starts. Since v0.6.347 the versions engine has a commit step that runs under a lock on the path: it checks what the path holds right before publishing. Another save can still land between the `If-Match` check and that commit step. That save is then replaced, although it is kept as a version, so nothing is lost. A client relying on `If-Match` for optimistic concurrency, such as a sync client, therefore gets 2xx instead of 412 in that window. **Expected:** the precondition is evaluated at the commit step. If the path no longer has the expected ETag there, the save is refused with 412, and nothing is published. **To do:** - Pass the expected ETag through the context into the record plan's commit. - Compare it under the lock and answer 412 (`storage.ErrPrecondition` or similar). - Same for WOPI's X-COOL-WOPI-Timestamp if it fits. - Add tests for the race, using the record hook.
Author
Owner

Deep research (2026-10-17)

The full write-up, with sources, is in ~/cairn-work/scratch/b7e/backlog/research-951.md.

Standards.

  • RFC 9110 §13.1.1: when If-Match is false, the server must not carry out the request. The stated purpose is to prevent lost updates.
  • Neither RFC 9110 nor RFC 4918 says the check has to be atomic, so checking early and again at the commit step meets both.
  • Collabora's spec says the host "should not save" when the timestamp differs, and should answer 409 with code 1010.

Products that close the window.

  • oCIS/OpenCloud: reva re-checks If-Match, If-None-Match and If-Unmodified-Since under the node lock after the upload.
  • AWS S3 checks the condition when the write completes.
  • Seafile merges at commit.
  • Nextcloud holds a lock from the check to the rename, so the losing writer gets 423. It still has gaps for new files and for locks that expire during long uploads.

Products with Cairn's window today.

  • Apache mod_dav and WsgiDAV/SeafDAV check before the body arrives.
  • nginx dav and golang.org/x/net/webdav don't check If-Match on PUT at all.

What broke for others.

  • super-productivity #10590: three clients sent the same If-Match, all got 201, and tracked time was lost.
  • rmail PR #38 fixed exactly this bug by moving the check inside the write transaction.

Clients affected.

  • Nextcloud desktop sends If-Match on PUT, and on 412 makes a "conflicted copy" at its next sync.
  • Collabora is affected through its timestamp.
  • rclone, Cyberduck and macOS Finder don't send If-Match, so they aren't affected.

Recommendation.

  • Keep the early check, and run the same check again in write.commit right after the path lock is taken, before any snapshot.
  • A mismatch answers 412 and publishes nothing. The other writer only waits for one commit, and no one gets 423.
  • Drop the body after a late 412. The client still has it, and every client reviewed handles 412 itself. Keeping refused bodies as versions would fill the default 10-version limit and push out real history.
  • Include If-None-Match (also *) on PUT.
  • Include the WOPI timestamp: 409 with code 1010, no rescue copy, no size hint.
  • File DELETE/MOVE/COPY preconditions as a separate low-priority issue. No client reviewed sends them, and deletes go to trash.

What users would see. A sync client that loses the race gets 412 and makes a conflicted copy, instead of silently replacing someone's save. Collabora shows its "changed in storage" prompt. Nothing changes for anyone else.

Side findings.

  • Cairn accepts weak ETags (W/) in If-Match, which the RFC forbids. I recommend documenting this rather than changing it, because a proxy that weakens ETags would otherwise turn every conditional PUT into a 412.
  • posix ETags are only as precise as the filesystem's mtime.
  • Cairn ignores the RFC 4918 If header.

Decision needed

  1. After a late 412, drop the body?
  2. Scope: PUT If-Match plus If-None-Match, plus the WOPI timestamp. DELETE/MOVE/COPY preconditions get a separate issue.
  3. Weak ETags: document only?
## Deep research (2026-10-17) The full write-up, with sources, is in `~/cairn-work/scratch/b7e/backlog/research-951.md`. **Standards.** - RFC 9110 §13.1.1: when If-Match is false, the server must not carry out the request. The stated purpose is to prevent lost updates. - Neither RFC 9110 nor RFC 4918 says the check has to be atomic, so checking early and again at the commit step meets both. - Collabora's spec says the host "should not save" when the timestamp differs, and should answer 409 with code 1010. **Products that close the window.** - oCIS/OpenCloud: reva re-checks If-Match, If-None-Match and If-Unmodified-Since under the node lock after the upload. - AWS S3 checks the condition when the write completes. - Seafile merges at commit. - Nextcloud holds a lock from the check to the rename, so the losing writer gets 423. It still has gaps for new files and for locks that expire during long uploads. **Products with Cairn's window today.** - Apache mod_dav and WsgiDAV/SeafDAV check before the body arrives. - nginx dav and golang.org/x/net/webdav don't check If-Match on PUT at all. **What broke for others.** - super-productivity #10590: three clients sent the same If-Match, all got 201, and tracked time was lost. - rmail PR #38 fixed exactly this bug by moving the check inside the write transaction. **Clients affected.** - Nextcloud desktop sends If-Match on PUT, and on 412 makes a "conflicted copy" at its next sync. - Collabora is affected through its timestamp. - rclone, Cyberduck and macOS Finder don't send If-Match, so they aren't affected. **Recommendation.** - Keep the early check, and run the same check again in `write.commit` right after the path lock is taken, before any snapshot. - A mismatch answers 412 and publishes nothing. The other writer only waits for one commit, and no one gets 423. - Drop the body after a late 412. The client still has it, and every client reviewed handles 412 itself. Keeping refused bodies as versions would fill the default 10-version limit and push out real history. - Include If-None-Match (also `*`) on PUT. - Include the WOPI timestamp: 409 with code 1010, no rescue copy, no size hint. - File DELETE/MOVE/COPY preconditions as a separate low-priority issue. No client reviewed sends them, and deletes go to trash. **What users would see.** A sync client that loses the race gets 412 and makes a conflicted copy, instead of silently replacing someone's save. Collabora shows its "changed in storage" prompt. Nothing changes for anyone else. **Side findings.** - Cairn accepts weak ETags (`W/`) in If-Match, which the RFC forbids. I recommend documenting this rather than changing it, because a proxy that weakens ETags would otherwise turn every conditional PUT into a 412. - posix ETags are only as precise as the filesystem's mtime. - Cairn ignores the RFC 4918 `If` header. ## Decision needed 1. After a late 412, drop the body? 2. Scope: PUT If-Match plus If-None-Match, plus the WOPI timestamp. DELETE/MOVE/COPY preconditions get a separate issue. 3. Weak ETags: document only?
Author
Owner

Decided by Nikola (2026-10-17):

  • Re-check at commit. Re-check If-Match at the commit step. When it fails, answer 412 and drop the body.
  • Scope: If-Match and If-None-Match (* included) on PUT, plus the WOPI timestamp. For WOPI, answer 409/1010 with no rescue copy and no size hint.
  • Split out: preconditions on DELETE, MOVE and COPY, and the RFC 4918 If header, go to #957.
  • Weak ETags: documented, not changed.

Implementation: batch 2.

**Decided by Nikola (2026-10-17):** - **Re-check at commit.** Re-check If-Match at the commit step. When it fails, answer 412 and drop the body. - **Scope:** If-Match and If-None-Match (`*` included) on PUT, plus the WOPI timestamp. For WOPI, answer 409/1010 with no rescue copy and no size hint. - **Split out:** preconditions on DELETE, MOVE and COPY, and the RFC 4918 `If` header, go to #957. - **Weak ETags:** documented, not changed. Implementation: batch 2.
Cordy closed this issue 2026-10-17 20:40:29 +00:00
Author
Owner

Shipped in v0.6.349 (PR #959). Both dogfoods run it.

If-Match and If-None-Match (including *) are now checked again at the commit step, under the path lock.

  • WebDAV: a save that loses the race gets a 412 and its body is dropped.
  • WOPI: answers 409 with code 1010, without a rescue copy or a size hint.
  • Weak ETags: accepted on both sides.
  • Log line: WARN versions: precondition failed at commit.

Live functional checks on the dogfoods will follow the next sign-in.

**Shipped in v0.6.349 (PR #959). Both dogfoods run it.** If-Match and If-None-Match (including `*`) are now checked again at the commit step, under the path lock. - **WebDAV:** a save that loses the race gets a 412 and its body is dropped. - **WOPI:** answers 409 with code 1010, without a rescue copy or a size hint. - **Weak ETags:** accepted on both sides. - **Log line:** WARN `versions: precondition failed at commit`. Live functional checks on the dogfoods will follow the next sign-in.
Author
Owner

Live result (both dogfoods, v0.6.349, 2026-10-18; recorded on PR #959, copied here): PASS.

WebDAV:

  • PUT with the current If-Match: 204.
  • The same PUT again, now with a stale If-Match: 412.
  • If-None-Match: * on an existing file: 412.
  • The file kept the accepted content.

WOPI:

  • PutFile with the current X-COOL-WOPI-Timestamp: 200.
  • The same PutFile again, now with a stale timestamp: 409 {"COOLStatusCode":1010}, and no rescue copy was made.

Content: the version list still held all four earlier contents.

Not tested live: the race at the commit step itself, where a save lands during the upload. It can't be timed by hand, so it is covered by rig tests on every backend.

**Live result (both dogfoods, v0.6.349, 2026-10-18; recorded on PR #959, copied here): PASS.** **WebDAV:** - PUT with the current `If-Match`: 204. - The same PUT again, now with a stale `If-Match`: 412. - `If-None-Match: *` on an existing file: 412. - The file kept the accepted content. **WOPI:** - PutFile with the current `X-COOL-WOPI-Timestamp`: 200. - The same PutFile again, now with a stale timestamp: 409 `{"COOLStatusCode":1010}`, and no rescue copy was made. **Content:** the version list still held all four earlier contents. **Not tested live:** the race at the commit step itself, where a save lands during the upload. It can't be timed by hand, so it is covered by rig tests on every backend.
Sign in to join this conversation.
No labels
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Cordy/Cairn#951
No description provided.