Repository navigation
fix(sybil): enforce ownership and admin-only guards on mutation routes - #934
Open
timmyp10111 wants to merge 2 commits into
Open
timmyp10111 wants to merge 2 commits into
timmyp10111 wants to merge 2 commits into
Conversation
The Sybil-resistance controller had no route-level authorization guards — any authenticated user could record or recompute scores for arbitrary user IDs, set Worldcoin verification state via a caller-supplied boolean, and invoke bulk recalculation. Changes: - New SybilOwnershipGuard: enforces :userId route param === JWT subject. Prevents IDOR on appeal submission and appeal-history reads. - Authorization matrix applied per route: POST /users/:userId/score -> JwtAuthGuard + AdminGuard + @adminonly() POST /users/:userId/recompute -> JwtAuthGuard + AdminGuard + @adminonly() POST /recalculate-all -> JwtAuthGuard + AdminGuard + @adminonly() POST /users/:userId/appeal -> JwtAuthGuard + SybilOwnershipGuard (self-service) GET /users/:userId/appeals -> JwtAuthGuard + SybilOwnershipGuard (own account) GET /users/:userId/score -> JwtAuthGuard (authenticated read) GET public-score/history/voting -> PUBLIC (advisory read-only signals) - POST /users/:userId/verify-worldcoin removed: accepted a caller-supplied boolean to mutate Worldcoin verification state without proof verification. Endpoint returns ForbiddenException (410 Gone semantics). Service method retained for internal use; not callable from the API. - Service: one-active-appeal rule — rejects new submissions while a SUBMITTED appeal is pending. - Service: recalculateAllScores accepts actorId for audit logging of bulk operations. - Module: imports AuthModule so JwtAuthGuard, AdminGuard, and RolesGuard are injectable. - Tests: 40 tests covering guard unit tests (SybilOwnershipGuard, AdminGuard), route metadata assertions (AdminOnly decorator presence), controller method logic, verify-worldcoin removal, and service propagation of appeal eligibility.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
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.
Linked task
Closes #852
Summary
Problem
The Sybil-resistance controller had no route-level authorization guards. Any authenticated user could:
POST /sybil/users/:userId/score — record a score for any arbitrary user ID
POST /sybil/users/:userId/recompute — recompute scores with pinned versions/fail-closed options for any user
POST /sybil/users/:userId/appeal — submit appeals targeting other users' accounts (IDOR)
POST /sybil/users/:userId/verify-worldcoin — set Worldcoin verification state to any boolean value without proof verification, for any user
POST /sybil/recalculate-all — trigger bulk score recalculation across the entire user table
The GlobalAuthGuard only requires a valid JWT for POST/PUT/PATCH/DELETE — it does not enforce ownership or role.
Fix
New SybilOwnershipGuard
Enforces request.params.userId === JWT subject. Prevents IDOR: user A cannot trigger score writes or appeal submissions targeting user B. Fails closed (401 when no principal, 403 on mismatch).
Authorization matrix applied per route
Route Before After
POST /users/:userId/score JWT only JwtAuthGuard + AdminGuard + @adminonly()
POST /users/:userId/recompute JWT only JwtAuthGuard + AdminGuard + @adminonly()
POST /recalculate-all JWT only JwtAuthGuard + AdminGuard + @adminonly()
POST /users/:userId/appeal JWT only JwtAuthGuard + SybilOwnershipGuard
GET /users/:userId/appeals PUBLIC JwtAuthGuard + SybilOwnershipGuard
GET /users/:userId/score PUBLIC JwtAuthGuard
GET /users/:userId/public-score PUBLIC PUBLIC (unchanged, privacy-safe)
GET /history, /voting, /models PUBLIC PUBLIC (unchanged, advisory reads)
POST /users/:userId/verify-worldcoin — permanently removed
This endpoint accepted a caller-supplied { verified: boolean } body that mutated Worldcoin verification state directly, completely bypassing proof verification. It now returns ForbiddenException (410 Gone semantics). The only authoritative Worldcoin verification path is POST /identity/worldcoin/verify, which requires a ZK proof and is guarded by JwtAuthGuard + WorldcoinVerificationGuard.
Service: one-active-appeal rule
submitAppeal now rejects a new submission when the user already has a SUBMITTED (pending) appeal. Enforced at the service/persistence boundary, not only at the controller, so it holds regardless of call site.
Service: bulk recalculation audit logging
recalculateAllScores accepts an optional actorId and emits structured log entries (sybil.recalculate_all started/completed [actor=…]) with total/succeeded/failed counts.
Module
SybilResistanceModule now imports AuthModule so JwtAuthGuard, AdminGuard, and RolesGuard are injectable by the controller's per-route guard instances.
Tests (40 total, all passing)
SybilOwnershipGuard unit: 401 on missing principal, 403 on ID mismatch, every cross-user IDOR pair.
AdminGuard unit: anonymous and non-admin roles rejected; admin role allowed.
Route metadata assertions: @adminonly() decorator confirmed present on recordScore, recomputeScore, recalculateAll via Reflect.getMetadata.
Controller input validation: empty userId, missing/empty body on every route.
setWorldcoinVerified removal: ForbiddenException for every caller × boolean value combination; service.setWorldcoinVerified confirmed never called.
One-active-appeal propagation from service rejection to controller response.
verify-worldcoin unreachability: 6-combination matrix (3 actors × 2 boolean values).
Related
Closes the IDOR and Worldcoin boolean-mutation issues described in the security report.
#804 — appeal persistence; this PR enforces the one-active-appeal rule at the service boundary.
#653 — wallet identity binding; ownership guard pattern follows the same IDOR model.
#611 — World ID proof privacy; this PR removes the boolean shortcut that circumvented proof verification.