Skip to content

feat(store): scope notes and settings per user - #25

Merged
gnacho merged 1 commit into
mainfrom
feat/issue-24-multiuser-scoping
Sep 13, 2026
Merged

gnacho merged 1 commit into
mainfrom
feat/issue-24-multiuser-scoping

Conversation

@gnacho

@gnacho gnacho commented Sep 13, 2026

Copy link
Copy Markdown
Owner

Closes #24.

The notes and settings tables had no user dimension and the config has no allowlist, so any authenticated user could read and write every note of the instance (verified in the SQL).

Adds versioned migrations with PRAGMA user_version as the source of truth, embedded with embed.FS and applied at startup before serving. A pre-migration VACUUM INTO backup is taken and verified with quick_check. Migration 002 adds the user column to notes and rebuilds settings with a (user, key) primary key; pre-existing rows are backfilled to OCNOTES_OWNER, and the service refuses to start without it rather than leave rows invisible.

The scoping key is the user stable graph id, not the username: this deployment returns a null userPrincipalName, so the username was an empty string for every user. Every note and settings operation is scoped, and cross-user access behaves as not-found (including DELETE, which previously answered 200).

Verification:

  • go build ./..., go vet ./... and go test -race ./... pass (11 store/migration tests)
  • Deployed and verified against the real database: user_version 2, the settings primary key is (user, key), the pre-migration backup verified with quick_check, 4 notes and 4 settings backfilled to the owner
  • Isolation verified through the API and the web app: the owner sees their 4 notes, a second user sees none and their new note stays private, cross-user GET/DELETE return 404, settings are per user, 0 JS errors, ocnews untouched

The notes and settings tables had no user dimension and the config has no
allowlist, so any authenticated user could read and write every note of the
instance.

Add versioned migrations (PRAGMA user_version as the source of truth, embedded
with embed.FS) with a verified VACUUM INTO backup taken before they run.
Migration 002 adds the user column to notes and rebuilds settings with a
(user, key) primary key; rows that predate the change are backfilled to
OCNOTES_OWNER, and the service refuses to start without it rather than leave
them invisible.

The scoping key is the user's stable graph id, not the username: this
deployment returns a null userPrincipalName, which made the username an empty
string for every user. Every note and settings operation is now scoped, and
cross-user access behaves as not-found.

Closes #24
@gnacho
gnacho merged commit d17ca30 into main Sep 13, 2026
@gnacho
gnacho deleted the feat/issue-24-multiuser-scoping branch September 13, 2026 11:23
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.

Scope notes and settings per user

1 participant