Skip to content

fix(#349): deny self-writes on members badges subcollection#393

Merged
Aditya948351 merged 1 commit into
devpathindcommunity-india:masterfrom
anshul23102:fix/349-badge-firestore-write-rule
May 31, 2026
Merged

fix(#349): deny self-writes on members badges subcollection#393
Aditya948351 merged 1 commit into
devpathindcommunity-india:masterfrom
anshul23102:fix/349-badge-firestore-write-rule

Conversation

@anshul23102
Copy link
Copy Markdown
Contributor

What and Why

Closes #349

The members/{userId}/badges/{badgeId} Firestore rule previously allowed any authenticated user to write badge documents to their own subcollection:

allow write: if isSuperAdmin() || (request.auth != null && request.auth.uid == userId);

Because badge eligibility logic (determineBadges) runs entirely client-side, this rule let any signed-in user award themselves arbitrary badges (including early-adopter, streak-7, and others) by sending a direct Firestore set call without meeting any criteria.

Change

Removed the request.auth.uid == userId branch so the rule becomes:

allow write: if isSuperAdmin();

Badge grants must originate from trusted backend code (Cloud Functions or Admin SDK) that verifies criteria before writing. The allow read condition is unchanged.

Files Changed

  • firestore.rules (1 line changed in the members/{userId}/badges/{badgeId} block)

Test Plan

  • Verify that a regular authenticated user can no longer write to members/<uid>/badges/<anyId> via the Firestore client SDK.
  • Verify that super admin writes (via Admin SDK or the super admin account) still succeed.
  • Confirm that badge reads remain public (no regression on badge display pages).

GSSoC

program: gssoc

…s subcollection

Any authenticated user could previously write to their own
members/<uid>/badges/<badgeId> path because the rule allowed writes
when request.auth.uid == userId. Badge logic runs entirely client-side,
so this let any user award themselves arbitrary badges with a direct
Firestore set call, bypassing all earned-criteria checks.

Restrict the allow write condition to isSuperAdmin() only. Badge grants
should originate exclusively from trusted backend code (Cloud Functions
or Admin SDK) that verifies criteria before writing. The read rule is
unchanged.

Closes devpathindcommunity-india#349
Copy link
Copy Markdown
Collaborator

@Aditya948351 Aditya948351 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! We definitely don't want users arbitrarily granting themselves badges. This Firestore rule fix is solid.

@Aditya948351 Aditya948351 merged commit 15b0d95 into devpathindcommunity-india:master May 31, 2026
@Aditya948351
Copy link
Copy Markdown
Collaborator

Do star the repo! Successfully merging this and loved the changes you did.

@Aditya948351 Aditya948351 added gssoc26 This is a official GirlScript Summer of Code label. level:intermediate Intermediate level issues type:bug type:security gssoc:approved give 50+ base points labels May 31, 2026
@anshul23102
Copy link
Copy Markdown
Contributor Author

Do star the repo! Successfully merging this and loved the changes you did.

Ofc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved give 50+ base points gssoc26 This is a official GirlScript Summer of Code label. level:intermediate Intermediate level issues type:bug type:security

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Firestore badge rule allows users to self-award any badge without earning it

2 participants