fix: resolve client IP behind proxy and align upload limits #22

Merged
xhgit merged 1 commits from Morris/webup-cloud:morris into main 2026-11-14 09:35:36 +08:00
Contributor

Bug 1 (high): login rate limiting used request.getRemoteAddr(), which is
always the nginx container address. Every client shared one bucket, so any
anonymous caller could lock the whole platform out of login for 60 seconds.

  • Add ClientIp to resolve the real address, honouring X-Real-IP /
    X-Forwarded-For only when the direct peer is a proxy we operate
    (loopback, private or container range). Public peers cannot spoof.
  • Prefer X-Real-IP, fall back to the right-most X-Forwarded-For entry so
    client-supplied prefixes are ignored. Guard with an IP literal check so
    a malformed header can never trigger a DNS lookup.
  • nginx now overwrites the forwarded headers with $remote_addr instead of
    clearing them, so spoofed values never reach the backend.
  • Add a global login ceiling (600/60s) well above the per-address limit.

Bug 2: the landing page had no login entry point on mobile. The collapsed
menu button was permanently display:none and the login link was hidden
below 550px, leaving no way to reach an account.

  • Show the menu button below 850px, render nav as a dropdown panel.
  • Add a login item inside the collapsed menu.

Bug 3: upload size limits disagreed across three layers. nginx capped
requests at 1m while the backend and UI advertise 25MiB, so any file over
1 MiB failed with nginx's HTML error page.

  • Raise client_max_body_size to 26m to match the backend.
  • Return 413 as JSON matching the API error shape.

Tests: 153 backend tests pass, including 10 new ClientIpTest cases
covering spoofed headers, right-most entry selection, IPv4-mapped IPv6,
and malformed values.

Bug 1 (high): login rate limiting used request.getRemoteAddr(), which is always the nginx container address. Every client shared one bucket, so any anonymous caller could lock the whole platform out of login for 60 seconds. - Add ClientIp to resolve the real address, honouring X-Real-IP / X-Forwarded-For only when the direct peer is a proxy we operate (loopback, private or container range). Public peers cannot spoof. - Prefer X-Real-IP, fall back to the right-most X-Forwarded-For entry so client-supplied prefixes are ignored. Guard with an IP literal check so a malformed header can never trigger a DNS lookup. - nginx now overwrites the forwarded headers with $remote_addr instead of clearing them, so spoofed values never reach the backend. - Add a global login ceiling (600/60s) well above the per-address limit. Bug 2: the landing page had no login entry point on mobile. The collapsed menu button was permanently display:none and the login link was hidden below 550px, leaving no way to reach an account. - Show the menu button below 850px, render nav as a dropdown panel. - Add a login item inside the collapsed menu. Bug 3: upload size limits disagreed across three layers. nginx capped requests at 1m while the backend and UI advertise 25MiB, so any file over 1 MiB failed with nginx's HTML error page. - Raise client_max_body_size to 26m to match the backend. - Return 413 as JSON matching the API error shape. Tests: 153 backend tests pass, including 10 new ClientIpTest cases covering spoofed headers, right-most entry selection, IPv4-mapped IPv6, and malformed values.
Morris added 1 commit 2026-11-14 09:34:21 +08:00
fix: resolve client IP behind proxy and align upload limits
Verify control plane / verify (pull_request) Canceled after 0s
347e723583
Bug 1 (high): login rate limiting used request.getRemoteAddr(), which is
always the nginx container address. Every client shared one bucket, so any
anonymous caller could lock the whole platform out of login for 60 seconds.

- Add ClientIp to resolve the real address, honouring X-Real-IP /
  X-Forwarded-For only when the direct peer is a proxy we operate
  (loopback, private or container range). Public peers cannot spoof.
- Prefer X-Real-IP, fall back to the right-most X-Forwarded-For entry so
  client-supplied prefixes are ignored. Guard with an IP literal check so
  a malformed header can never trigger a DNS lookup.
- nginx now overwrites the forwarded headers with $remote_addr instead of
  clearing them, so spoofed values never reach the backend.
- Add a global login ceiling (600/60s) well above the per-address limit.

Bug 2: the landing page had no login entry point on mobile. The collapsed
menu button was permanently display:none and the login link was hidden
below 550px, leaving no way to reach an account.

- Show the menu button below 850px, render nav as a dropdown panel.
- Add a login item inside the collapsed menu.

Bug 3: upload size limits disagreed across three layers. nginx capped
requests at 1m while the backend and UI advertise 25MiB, so any file over
1 MiB failed with nginx's HTML error page.

- Raise client_max_body_size to 26m to match the backend.
- Return 413 as JSON matching the API error shape.

Tests: 153 backend tests pass, including 10 new ClientIpTest cases
covering spoofed headers, right-most entry selection, IPv4-mapped IPv6,
and malformed values.
xhgit merged commit 5f9e8e52aa into main 2026-11-14 09:35:36 +08:00
xhgit deleted branch morris 2026-11-14 09:35:36 +08:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: xhgit/webup-cloud#22