Skip to content

fix(send): protect folder owner from losing access when an invitation is removed#1005

Merged
aaspinwall merged 1 commit into
mainfrom
fix/1004-protect-owner-membership
Jul 20, 2026
Merged

fix(send): protect folder owner from losing access when an invitation is removed#1005
aaspinwall merged 1 commit into
mainfrom
fix/1004-protect-owner-membership

Conversation

@aaspinwall

Copy link
Copy Markdown
Collaborator

What changed?

This fixes a bug where removing a share invitation could lock a folder's owner out of their own folder — permanently.

In plain terms: every folder has an owner who always has full access. When you share a folder, you invite guests. Cancelling an invitation is supposed to remove a guest's access. But if the owner ever ended up on their own folder's invitation list, cancelling that invitation removed the owner's access by mistake, and there was no way to recover from inside the app.

The change makes three things safe:

  1. The owner can never lose access when an invitation is removed. Removing an invitation now leaves the owner's access untouched, no matter what.
  2. The owner can't be added to their own folder's invitation list. They already have full access, so inviting them is blocked.
  3. The owner opening their own share link is now harmless. It's treated as "you already have access" instead of showing an error.

Regression tests were added for all three cases, and the full backend test suite passes.

AI disclosure: This change was written by an AI agent (Claude) working from a bug report, with a human reviewing the approach, the diff, and the results. A separate AI code-review pass was run over the diff and its feedback was incorporated.

Why?

The owner's access and a guest's access were stored the same way internally, so the system couldn't tell them apart. That meant a routine "remove invitation" action could silently delete the owner's own access. Because the owner is the only account guaranteed full access to a folder, losing it left the folder unopenable with no self-service fix — a developer had to repair the account directly. This closes that gap.

How to reproduce (before the fix)

You need one account and a folder you own:

  1. Sign in and open a folder you own.
  2. Get onto your own folder's invitation list (e.g. an invitation where you are both the sender and the recipient).
  3. Remove/cancel that invitation.
  4. Try to open the same folder again → access is denied, even after signing out and back in.

After this fix: step 4 works normally — the folder still opens, and steps 2 and the "open your own share link" case no longer cause an error.

Limitations and Notes

  • This prevents the problem going forward. It does not repair accounts that were already locked out by this bug (those still need a manual database fix).
  • Scope is intentionally limited to this issue. Related sharing/security hardening found during the same testing (missing auth checks and rate limiting on some share endpoints) is tracked separately and is not part of this PR.

Applicable Issues

Closes #1004

… is removed

The owner's access to a folder is stored as a membership row keyed by
(groupId, userId), the same key any invited guest gets. If the owner ended up
on their own folder's invitation list, removing that invitation deleted the
owner's real membership and permanently locked them out of their own folder,
with no in-app recovery.

- removeGroupMember() now no-ops when the target user is the container owner,
  so the owner's membership can never be deleted via the invitation- or
  member-removal paths.
- createInvitation() refuses to create an invitation whose recipient is the
  owner (defense in depth, removes the precondition entirely).
- createInvitationFromAccessLink()/the accept route treat "owner accepts their
  own access link" as a graceful no-op success instead of an error.
- Adds regression tests covering all of the above.

Closes #1004

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@aaspinwall
aaspinwall requested a review from radishmouse July 20, 2026 19:27
@aaspinwall
aaspinwall merged commit ae8e7ec into main Jul 20, 2026
20 checks passed
@aaspinwall
aaspinwall deleted the fix/1004-protect-owner-membership branch July 20, 2026 19:41
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.

[SEND] Removing a share invitation can lock the folder owner out of their own folder

2 participants