Repository navigation
Invites: one target per invite, applied only to verified emails - #1715
Merged
Merged
Conversation
Invite docs are written by clients and the functions trusted them. Firestore rules (invite create): - an invite targets a project or an organization, never both, with a string id; organization roles are Viewer, Editor or Admin - validate the fields: one lowercase plain email address, the creator as originUserId, status 'new', timestamps, bounded names - only verified (or phone) non-anonymous users can create invites, and only a verified invitee can read one Functions: - getInviteTarget is the trigger's single definition of an invite's target; malformed invites are marked as errored, never applied - applyInvites never grants Owner - the invitee is looked up in Firebase Auth instead of the users collection, and invites are applied only once the email is verified; the new userEmailVerified trigger applies them when it becomes so Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Preview for 878d51a (sandbox project open-feedback-hugo, expires in 7 days): https://open-feedback-hugo--pr-1715-ve5opkq3.web.app |
open-feedback
|
||||||||||||||||||||||||||||
| Project |
open-feedback
|
| Branch Review |
main
|
| Run status |
|
| Run duration | 02m 21s |
| Commit |
|
| Committer | Hugo Gresse |
| View all properties for this run ↗︎ | |
| Test results | |
|---|---|
|
|
0
|
|
|
0
|
|
|
0
|
|
|
0
|
|
|
16
|
| View all changes introduced in this branch ↗︎ | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Invite documents are written by clients, and the invite functions trusted their content and the invitee's identity more than they should. This tightens both sides so the rules and the functions agree on what an invite is and who it is for.
What
Firestore rules (
config/firestore.rules, invite create/get):keys().hasOnly, one lowercase plain email address asdestinationUserInfo,originUserIdequal to the creator,status == 'new', timestamps, names up to 1000 characters.Functions (
functions/src/triggers/):getInviteTargetis the functions' single definition of an invite's target. Malformed invites are markedstatus: 'error'and never applied, both when created and when processed later.applyInvitesno longer has an Owner case (Owner was never offered in the UI; ownership moves through the organization settings).admin.auth().getUserByEmailinstead of theuserscollection, and invites are only applied to accounts whose email is verified (phone accounts unchanged).userEmailVerifiedtrigger: when a user doc'semailVerifiedturns true (the admin app writes it at the first sign-in after verification), it re-reads the Firebase Auth record and applies the pending invites.Deploy
Needs both
firestore:rulesandfunctions(new functionuserEmailVerified).Tests
config/firestore.rules.spec.js(49 tests, Firestore emulator). The new cases fail againstmain's rules; the "never both" clauses are each covered (checked by removing them).getInviteTarget.spec.ts,userEmailVerified.spec.ts, updateduserInvite,userCreatedandapplyInvitesspecs.npm run lint,npm run typecheck,npm run build,npx vitest run(291 tests) pass infunctions/on Node 24. Reviewed with/code-review maxbefore opening. No UI change, so no screenshots.🤖 Generated with Claude Code