Skip to content

guestlinks: rate-limit for redeem/renewal endpoints #3617

Closed

Description

@aduffeck

The guest link feature (unauthenticated) endpoints for redeeming a token/pin or creating a new token/pin pair when the previous token or session was expired need to be rate-limited in order to prevent spamming and brute-force attacks.

Endpoints to protect:

  • verify/token
  • verify/pin
  • renew

Activity

  1. aduffeck commented on Oct 6, 2026

    @aduffeck
    MemberAuthor

    here's a proposal after a brainstorming session with my llm:


    Two things make this harder than "put a rate limiter in front of it":

    • The PIN space is small. A 6-digit PIN has 10⁶ values, so a per-IP limit alone doesn't stop a distributed brute-force.
    • The share ID is not a secret. It's returned in the 401 and redeem responses. If we count failures or lock per share, anyone who knows a share ID can lock the real guest out.

    Proposal

    1. Bind PIN verification to a browser-held nonce

    • renew creates a challenge holding a random nonce, the PIN hash, a short expiry and a failure counter. The nonce goes only to the browser that called renew, as an HttpOnly cookie. The PIN goes to the guest by email.
    • verify/pin requires the PIN and the nonce. Failures are counted per challenge, and the challenge is invalidated after N attempts (e.g. 5).
    • An attacker who calls renew gets a nonce, but the matching PIN goes to the guest's inbox. The attacker can only guess against their own challenge and can't touch the real guest's. Each challenge gives at most 5 guesses in 10⁶, and the per-share renew limit (point 4) caps how many challenges they get.
    • ⚠️ This changes the verify/pin contract (it now needs a cookie or nonce), so it needs a decision with the web team before the endpoints get built.

    2. Short PIN lifetime and backoff instead of hard locks

    • PINs expire after about 15 minutes, and the wait between failed attempts grows exponentially up to a cap (e.g. 30 s). That allows only a few dozen guesses per PIN, so we don't need permanent lockouts.

    3. Lockouts never affect the magic link

    • Every renew mail also contains the magic link, and its token is far too long to guess. An invalidated PIN only removes the shortcut of typing the PIN into the open tab; clicking the link still works.

    4. Per-share cooldown on renew

    • This stops attackers from flooding a guest's inbox, e.g. 1 mail per minute plus a daily cap.
    • Known trade-off: an attacker can use up the renew quota and stop the guest from getting a new mail for a while. We limit that by keeping the cooldown short, keeping the last link valid until it expires, and adding a per-IP limit in front. As long as renew must work without authentication, this can't be eliminated completely.

    5. Coarse per-IP limit in the proxy (optional)

    • A configurable per-IP limiter for unprotected routes, e.g. go-chi/httprate. It lives in the proxy because only the proxy sees the client IP.
    • Prerequisite: the proxy currently uses chimiddleware.RealIP, which accepts X-Forwarded-For, X-Real-IP and True-Client-IP from anyone. If the proxy is exposed directly, any IP-based limit can be bypassed by setting those headers. We need a trusted-proxies (CIDR) setting first.
    • The counters live in memory per replica, which is fine for a coarse limit.

    6. Rate limiting at the edge (docs only)

    We'd document optional rules for each deployment type:

    • Docker Compose / Traefik: a RateLimit middleware on a dedicated router for PathPrefix(/graph/v1beta1/extensions/org.libregraph/guestLinks), with the right ipStrategy.depth.
    • nginx: limit_req_zone / limit_req on that location.
    • Kubernetes: this depends on the controller.
      • ingress-nginx's limit-rps applies per Ingress object, so the path needs its own Ingress.
      • Traefik uses a Middleware CRD.
      • Gateway API has no standard rate-limit field, so it's implementation-specific (e.g. Envoy Gateway BackendTrafficPolicy).
      • Make sure client IPs are preserved (externalTrafficPolicy: Local or PROXY protocol). Otherwise every client looks like the node IP.

    Summary

    Endpoint Main risk Protection
    verify/token Spam / load (the token can't be guessed) Per-IP limit
    verify/pin Brute-force Per-challenge counter with nonce binding, short TTL, backoff, per-IP limit
    renew Mail bombing Per-share cooldown, per-IP limit

    All per-share and per-challenge state lives in the existing token records, which are file-based and written under a lock. So it holds across replicas as long as the storage directory is shared.


    For this ticket I would omit #5., we can create a follow-up ticket if needed but I feel like the other measures might be good enough already.

  2. aduffeck commented on Oct 6, 2026

    @aduffeck
    MemberAuthor

    @kulmann wdyt about point 1?

  3. self-assigned this
    on Oct 6, 2026
  4. kulmann commented on Oct 6, 2026

    @kulmann
    Member

    @kulmann wdyt about point 1?

    Actually sounds like a good idea 👍

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions