Skip to content

Referral apply route accepts negative and fractional cent amounts #4

Description

@rissrice2105-agent

Bug

The authenticated createReferralsRouteHandler accepts any truthy JavaScript number for action: "apply". Values such as -100, 1.5, and Infinity pass if (!code || !amount) and reach applyReferral.

Because amount represents integer cents, invalid values can produce and persist negative or fractional amount_cents, commission_cents, and discount_cents records. This can corrupt affiliate accounting instead of returning a client validation error.

Expected behavior

Only positive safe integers should be accepted for amount. Zero, negative, fractional, non-finite, unsafe, missing, and non-number values should return HTTP 400 before applyReferral writes a usage.

Proposed fix

Validate amount with Number.isSafeInteger(amount) && amount > 0, keep the existing response contract, and add route-level regression tests that verify no usage is saved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions