Skip to content

feat(security): per-IP rate limits on Register, Login, SendOtp #9

@MarkCesium

Description

@MarkCesium

Summary

backend/auth/src/services/otp.py:39 enforces a per-email cooldown but nothing per-IP. An attacker spraying emails across accounts hits no limit. Same for Register and Login.

Gateway issue PlaceBrain/gateway#7 covers the outer wall; this is defence-in-depth at the gRPC layer, useful if the gateway is bypassed in a future deployment (e.g. mTLS sidecar).

Changes

  • backend/auth/src/infra/grpc/interceptors.py — new rate-limit interceptor keyed off peer address passed via gateway metadata (x-peer-addr).
  • Buckets in Redis (re-use the devices redis instance): 10/min Login, 5/min Register, 3/min SendOtp.
  • Exceeded → return RESOURCE_EXHAUSTED.
  • Config via env: AUTH__RL__LOGIN=10/minute etc.

Verification

  • 11 logins from same IP in under a minute — 11th returns RESOURCE_EXHAUSTED.
  • Different IPs remain independent.

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