Skip to content

feat: Prevent implicit document creation via If-Match header#105

Merged
bosschaert merged 3 commits intomainfrom
delete
Nov 24, 2025
Merged

feat: Prevent implicit document creation via If-Match header#105
bosschaert merged 3 commits intomainfrom
delete

Conversation

@karlpauls
Copy link
Collaborator

Problem

Currently, da-collab can implicitly create documents in da-admin through the first PUT request. This creates issues when documents are deleted or never existed - we end up recreating them
unintentionally.

Solution

This PR enforces explicit document existence checks at two levels:

1. Authorization Phase

Reject connections to non-existent documents immediately. Previously, 404 responses during the HEAD request were allowed (anticipating document creation). Now they fail fast at the edge.

2. Write Phase

Added If-Match: * header to all PUT requests. This tells da-admin "only write if document exists" - the server returns 412 if it doesn't.

3. Cleanup on Conflict

When we get 412 (document was deleted), we now:

  • Clean the Durable Object storage cache via storage.deleteAll()
  • Close all active WebSocket sessions
  • Remove the ydoc from the global cache

4. Error Propagation

persistence.get now throws on 404 instead of returning null. This catches the edge case where a document is deleted between authorization and content fetch.

Error details are stored in the Yjs document's error map before connections close, so clients receive the error via the sync protocol.

Deployment

⚠️ da-admin must deploy If-Match support before this goes out

The header needs to be recognized and 412 returned when documents don't exist. See adobe/da-admin#187

@karlpauls karlpauls marked this pull request as draft November 14, 2025 18:37
@github-actions
Copy link

github-actions bot commented Nov 14, 2025

LCOV of commit daa15df during Install, lint, and test #260

Summary coverage rate:
  lines......: 99.1% (2094 of 2112 lines)
  functions..: 95.9% (71 of 74 functions)
  branches...: no data found

Files changed coverage rate:
                  |Lines       |Functions  |Branches    
  Filename        |Rate     Num|Rate    Num|Rate     Num
  ======================================================
  src/edge.js     | 2.7%    339| 0.0%     9|    -      0
  src/shareddoc.js| 3.0%    642| 0.0%    19|    -      0

@auniverseaway auniverseaway self-requested a review November 19, 2025 05:27
@karlpauls karlpauls marked this pull request as ready for review November 21, 2025 10:49
@karlpauls karlpauls requested a review from bosschaert November 21, 2025 10:49
@bosschaert bosschaert merged commit b33ae65 into main Nov 24, 2025
3 checks passed
@bosschaert bosschaert deleted the delete branch November 24, 2025 11:45
adobe-bot pushed a commit that referenced this pull request Dec 8, 2025
# 1.0.0 (2025-12-08)

### Bug Fixes

* add check for shared secret ([#108](#108)) ([a79731f](a79731f))
* add span to known HTML tags ([#101](#101)) ([fbf016d](fbf016d))
* do not empty document if error ([#90](#90)) ([a406add](a406add))
* encode HTML brackets ([#100](#100)) ([6c5b5fd](6c5b5fd))
* encode HTML brackets ([#74](#74)) ([015163e](015163e))
* keep content if no main found in html ([#85](#85)) ([9fd25ac](9fd25ac))
* null doc crashes aem2doc ([#84](#84)) ([6197114](6197114))
* ommit stacktraces in error map for non-dev ([#110](#110)) ([1f896ac](1f896ac))
* remove html comments ([#68](#68)) ([cf05aae](cf05aae))

### Features

* disable stack traces on production ([#109](#109)) ([79c40bd](79c40bd))
* Prevent implicit document creation via If-Match header ([#105](#105)) ([b33ae65](b33ae65))
adobe-bot pushed a commit that referenced this pull request Dec 8, 2025
# 1.0.0 (2025-12-08)

### Bug Fixes

* add check for shared secret ([#108](#108)) ([a79731f](a79731f))
* add span to known HTML tags ([#101](#101)) ([fbf016d](fbf016d))
* do not empty document if error ([#90](#90)) ([a406add](a406add))
* encode HTML brackets ([#100](#100)) ([6c5b5fd](6c5b5fd))
* encode HTML brackets ([#74](#74)) ([015163e](015163e))
* keep content if no main found in html ([#85](#85)) ([9fd25ac](9fd25ac))
* null doc crashes aem2doc ([#84](#84)) ([6197114](6197114))
* ommit stacktraces in error map for non-dev ([#110](#110)) ([1f896ac](1f896ac))
* remove html comments ([#68](#68)) ([cf05aae](cf05aae))
* trigger release ([ca061d4](ca061d4))

### Features

* disable stack traces on production ([#109](#109)) ([79c40bd](79c40bd))
* Prevent implicit document creation via If-Match header ([#105](#105)) ([b33ae65](b33ae65))
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