Skip to content

Refactor: ordered pre-dispatch guard chain in rpchandler (rate limit, Turnstile, future guards) #674

Description

@CybotTM

Follow-up to the #662 review, sequenced AFTER #662 lands (touching Handle now would conflict with the contributor's rework).

Problem: cross-cutting request guards are scattered — the Turnstile check is an inline block in Handle before method dispatch, the per-IP rate limiter lives inside the per-method handlers. Two guards in two ad-hoc places already produced an ordering bug (Turnstile before rate limiting — #662 review, being fixed there); every future guard would add another scattered if.

Proposal: an ordered guard chain in internal/rpchandlertype guard func(c fiber.Ctx, body *rpcRequest) error, evaluated before dispatch: rate limit → Turnstile (when enabled) → dispatch. Fiber middleware is deliberately NOT the vehicle: there is a single RPC endpoint and the Turnstile token lives in the JSON body, so app-level middleware would have to buffer and double-parse the body.

Benefit: ordering becomes explicit and testable (a unit test can assert the chain order — exactly the class of bug the #662 review caught), and future guards (audit logging, honeypot fields, IP allowlists, additional bot checks) become one list entry with a defined position.

Assisted by claude-code:claude-fable-5 — Session

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