Skip to content

Bug Report: Voting endpoints use inconsistent authorization and reputation checks #6

@RounakChoudhary

Description

@RounakChoudhary

Problem

The project has multiple voting endpoints with different validation behavior.

Older vote routes check reputation before voting, while newer /upvote and /downvote routes do not enforce the same checks.

Additionally, one route attempts to call:

updateReputation()

on an ObjectId instead of a populated user document.


Files Involved

  • server/routes/questions.js
  • server/controllers/answersController.js

Current Behavior

  • Some vote endpoints allow low-reputation users to vote
  • Some routes may fail during reputation updates
  • Voting behavior differs across APIs

Expected Behavior

All voting endpoints should:

  • enforce the same authorization rules
  • validate voting permissions consistently
  • safely update reputation
  • return consistent responses

Steps To Reproduce

  1. Use a low-reputation account
  2. Call newer /upvote or /downvote endpoints
  3. Observe that voting succeeds without proper checks

Root Cause

Voting logic is duplicated across multiple routes/controllers and not centralized.

Some routes use populated user handling while others directly use ObjectIds.


Proposed Fix

  • Create shared vote helper/controller logic
  • Enforce req.user.canVote() consistently
  • Fetch/populate content authors before reputation updates
  • Optionally prevent self-voting

I am selected as a GSSoC contributor and would like to work on this issue. Please assign it to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions