Skip to content

Fix ETag format to prevent WsgiDAV crashes on PUT requests#55

Merged
TheZupZup merged 1 commit intomainfrom
claude/fix-webdav-etag-9MmCf
May 3, 2026
Merged

Fix ETag format to prevent WsgiDAV crashes on PUT requests#55
TheZupZup merged 1 commit intomainfrom
claude/fix-webdav-etag-9MmCf

Conversation

@TheZupZup
Copy link
Copy Markdown
Owner

Summary

This PR fixes a regression where WsgiDAV would crash with a 500 error when handling PUT requests to WebDAV resources (note.json and page_1.ink files) due to improperly formatted ETags. The issue occurred because ETags were being returned as quoted ISO timestamps, which violated WsgiDAV's checked_etag validator.

Key Changes

  • Replaced ISO timestamp-based ETags with hash-based ETags: Changed _safe_etag() to generate SHA256 hex digests from resource identity components (resource type, ID, page number, and last-modified timestamp) instead of returning raw ISO timestamps. Hex digests are guaranteed to be quote-free and satisfy WsgiDAV's validation rules.

  • Updated ETag generation for NoteMetaFile: Modified get_etag() to include the note ID and type identifier in the hash, ensuring the ETag changes only when the note's content actually changes.

  • Updated ETag generation for InkFile: Modified get_etag() to include the page's note ID, page number, and type identifier in the hash for proper cache invalidation.

  • Added comprehensive test coverage:

    • Unit tests verifying ETags pass WsgiDAV's checked_etag validator
    • Tests confirming ETags are never quoted, never weak, and properly formatted
    • Tests verifying ETags change when content changes
    • Integration tests reproducing the original crash scenario and confirming PUT requests now succeed end-to-end

Implementation Details

  • The _safe_etag() function now accepts variable arguments representing resource identity components
  • Each component is converted to a string (with special handling for datetime objects to ensure consistent ISO format)
  • Components are separated by a null byte (0x1f) before hashing to prevent collisions
  • The function returns only the hex digest, never pre-quoted, allowing WsgiDAV to add quotes when emitting the ETag header
  • This approach ensures deterministic, collision-resistant ETags that properly reflect resource state changes

https://claude.ai/code/session_01UCTNs51gDsbdzVXExMUDAg

@TheZupZup TheZupZup merged commit f89ac8f into main May 3, 2026
1 check passed
@TheZupZup TheZupZup deleted the claude/fix-webdav-etag-9MmCf branch May 3, 2026 09:04
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