SECURITY: share-link limiter trusts X-Forwarded-For from anyone; X-Forwarded-Proto trusted from anyone; cookies not Secure behind a TLS proxy #874

Closed
opened 2026-10-10 20:04:30 +00:00 by Cordy · 1 comment
Owner

Found in the #864 deep research on 2026-10-10. I checked each point against the code on main afa2d1ec.

  • The flaw: internal/share/ratelimit.go:64-77 clientIP() takes the left-most X-Forwarded-For entry from any peer. It ignores auth.trustedProxies.
  • Where it applies: public.go:83 and :368. That is the 10-per-minute limit on share-link password attempts.
  • The attack: sending a different X-Forwarded-For value on each request gets a fresh limit bucket every time. Unlimited online guessing of share passwords follows, on an unauthenticated public route.
  • This is a known bug class: Nextcloud CVE-2023-49792, plus Mastodon, Coolify, Litestar and Gophish advisories (sources in the #864 research).
  • Fix: use auth.ClientAddr (trusted proxies, read from the right). Key IPv6 addresses by /64. Test that a rotating XFF from an untrusted peer stays in one bucket.

2. X-Forwarded-Proto is trusted from anyone

  • internal/auth/oidc.go:108 (requestOrigin, which builds the logout redirect origin) accepts it from any peer.
  • So does internal/api/shares.go:85 (the share link base URL when BaseURL is empty).
  • Fix: honour it only from auth.trustedProxies.

3. Cookies not marked Secure behind a TLS-terminating proxy

  • internal/auth/session.go:391: the session cookie is Secure: r.TLS != nil. Behind Caddy or nginx doing TLS, that is always false.
  • internal/share/public.go:405: the cairn_share cookie never sets Secure.
  • Fix: set Secure when the request came over TLS, or when a trusted proxy says X-Forwarded-Proto: https.
  • Question for the spec: should there also be a config switch that forces it on?
  • The request log records r.RemoteAddr (obs/middleware.go:107).
  • Audit events carry no client address, except the throttle and spray notes.

Planned to ship first in the #864 batch, as its own task with its own tests.

Found in the #864 deep research on 2026-10-10. I checked each point against the code on main afa2d1ec. ## 1. Share-link password limiter can be bypassed (most serious) - **The flaw:** `internal/share/ratelimit.go:64-77` `clientIP()` takes the **left-most** `X-Forwarded-For` entry from **any** peer. It ignores `auth.trustedProxies`. - **Where it applies:** `public.go:83` and `:368`. That is the 10-per-minute limit on share-link password attempts. - **The attack:** sending a different `X-Forwarded-For` value on each request gets a fresh limit bucket every time. Unlimited online guessing of share passwords follows, on an unauthenticated public route. - **This is a known bug class:** Nextcloud CVE-2023-49792, plus Mastodon, Coolify, Litestar and Gophish advisories (sources in the #864 research). - **Fix:** use `auth.ClientAddr` (trusted proxies, read from the right). Key IPv6 addresses by /64. Test that a rotating XFF from an untrusted peer stays in one bucket. ## 2. `X-Forwarded-Proto` is trusted from anyone - `internal/auth/oidc.go:108` (`requestOrigin`, which builds the logout redirect origin) accepts it from any peer. - So does `internal/api/shares.go:85` (the share link base URL when `BaseURL` is empty). - **Fix:** honour it only from `auth.trustedProxies`. ## 3. Cookies not marked `Secure` behind a TLS-terminating proxy - `internal/auth/session.go:391`: the session cookie is `Secure: r.TLS != nil`. Behind Caddy or nginx doing TLS, that is always false. - `internal/share/public.go:405`: the `cairn_share` cookie never sets `Secure`. - **Fix:** set `Secure` when the request came over TLS, or when a **trusted** proxy says `X-Forwarded-Proto: https`. - **Question for the spec:** should there also be a config switch that forces it on? ## Related (part of #864, not a vulnerability) - The request log records `r.RemoteAddr` (`obs/middleware.go:107`). - Audit events carry no client address, except the throttle and spray notes. Planned to ship first in the #864 batch, as its own task with its own tests.
Cordy referenced this issue from a commit 2026-10-12 11:45:07 +00:00
Cordy closed this issue 2026-10-12 11:48:34 +00:00
Author
Owner

Shipped in v0.6.328 (PR #877), and both dogfoods are bumped.

Live check on cairn-enc (2026-10-12): I sent 260 requests to /s/<token>, each with a different X-Forwarded-For, from an untrusted LAN client. The first 240 got 404 and the rest got 429, so all requests now share one limit bucket. Before this fix, each forged header got a fresh bucket. Sign-in on files.c0rdyceps.ch still answers 200.

Note for the dogfoods: their proxies are not in auth.trustedProxies yet; that is handled in #864. Until then:

  • Cookies stay non-Secure there.
  • On files-bao.c0rdyceps.ch, sign-out may land on an http:// origin.
  • files.c0rdyceps.ch keeps https, because its host matches the configured oidcRedirectUrl.
Shipped in v0.6.328 (PR #877), and both dogfoods are bumped. **Live check on cairn-enc (2026-10-12):** I sent 260 requests to `/s/<token>`, each with a different `X-Forwarded-For`, from an untrusted LAN client. The first 240 got 404 and the rest got 429, so all requests now share one limit bucket. Before this fix, each forged header got a fresh bucket. Sign-in on files.c0rdyceps.ch still answers 200. **Note for the dogfoods:** their proxies are not in `auth.trustedProxies` yet; that is handled in #864. Until then: - Cookies stay non-`Secure` there. - On files-bao.c0rdyceps.ch, sign-out may land on an `http://` origin. - files.c0rdyceps.ch keeps https, because its host matches the configured `oidcRedirectUrl`.
Sign in to join this conversation.
No labels
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Cordy/Cairn#874
No description provided.