Skip to content

fix(core): validate room_id + doc_slug exist in room_add_document - #700

Merged
ajianaz merged 2 commits into
developfrom
fix/698-room-document-validation
Jul 16, 2026
Merged

ajianaz merged 2 commits into
developfrom
fix/698-room-document-validation

Conversation

@ajianaz

@ajianaz ajianaz commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

The room_documents junction table enforces an FK on room_id (→ rooms) but has no FK on doc_slug. As a result POST /room/document/add accepted any doc_slug string — even one with no matching document — and created a dangling room→document link. A bogus room_id also surfaced as a raw FK violation returning 500.

This PR validates that both room_id and doc_slug reference existing rows before the insert, returning Error::Validation (→ 400) for unknown values.

Changes

crates/uteke-core/src/memory/rooms.rs — room_add_document

  • Pre-check SELECT EXISTS(... FROM rooms WHERE id = ?) → Error::validation("Unknown room: …") if missing.
  • Pre-check SELECT EXISTS(... FROM documents WHERE slug = ?) → Error::validation("Unknown document slug: …") if missing.
  • (documents.slug is UNIQUE and COLLATE NOCASE, so the lookup is consistent with how slugs are stored.)

crates/uteke-server/src/handlers.rs — PUT /room/document/add

Behavior

Input Before After
valid room + valid slug 200 linked 200 linked (unchanged)
valid room + bogus slug 200 linked (dangling!) 400 Unknown document slug
bogus room 500 (raw FK error) 400 Unknown room
DB/infra error 500 500 (unchanged)

Idempotent inserts (INSERT OR IGNORE) and the existing room_remove_document are unchanged.

Closes #698

Checklist

The room_documents junction table has an FK on room_id (→ rooms) but
none on doc_slug, so POST /room/document/add accepted any doc_slug and
created dangling room→document links. A bogus room_id also surfaced as
a raw FK violation → 500.

Validate both room_id and doc_slug existence in room_add_document,
returning Error::Validation (→ 400) for unknown values. Update the
PUT /room/document/add handler to map Validation → 400 accordingly.

Closes #698
@github-actions

github-actions Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

🔍 Cora AI Code Review

⚠️ Review recommended — warnings found.

🟡 Warning (1)

  • unknown:? — Cora AI review could not complete: failed to parse LLM JSON response: parse failed (original: EOF while parsing a value at line 1 column 0, after repair: EOF while parsing a value at line 1 column 0). Review was skipped; no code quality issues were found by the automated check.

Review powered by cora-cli · BYOK · MIT

@ajianaz
ajianaz merged commit a2efac5 into develop Jul 16, 2026
9 checks passed
@ajianaz
ajianaz deleted the fix/698-room-document-validation branch July 16, 2026 03:18
ajianaz added a commit that referenced this pull request Aug 13, 2026
…tion

fix(core): validate room_id + doc_slug exist in room_add_document
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.

room_documents.doc_slug has no FK to documents — POST /room/document/add allows dangling links

1 participant