Skip to content

[MEDIUM] — createCampaign accepts milestones with targetAmount = 0 via implicit as any coercion, silently producing inert milestones #12

Description

@ibrahimmosouf-png

Severity: Medium
Type: Bug
Scope: Campaigns
Labels: bug, good first issue

Description

CampaignsService.createCampaign (src/campaigns/campaigns.service.ts, line ~37) maps incoming milestone DTOs as targetAmount: (m.targetAmount ?? 0) as any. A missing or zero-valued targetAmount therefore becomes 0 (often a Prisma.Decimal) instead of triggering validation. Because milestones are tracked as MilestoneStatus, a milestone with a 0 target can be created and immediately be considered "satisfied" once any donation arrives, unlocking funds prematurely.

A class-validator decorator such as @IsNumber / @Min(0.0000001) is also absent from the inferred DTO shape (the field is typed via (m.targetAmount ?? 0) as any rather than properly declared).

Recommendation

  • Define a typed CreateMilestoneDto class with @IsNumber and @Min(0.0000001), and validate it via class-validator at the controller boundary.
  • Remove the as any cast; let Prisma receive a properly typed Decimal.
  • Add unit tests asserting that zero / negative / non-numeric milestone targets are rejected with 400 Bad Request.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial CampaignAudit finding under the Official CampaignbugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions