Skip to content

feat: per-IP HTTP rate limiting and concurrency limiting - #59

Merged
fclairamb merged 22 commits into
mainfrom
feat/http-ip-rate-limiting
May 16, 2026
Merged

fclairamb merged 22 commits into
mainfrom
feat/http-ip-rate-limiting

Conversation

@fclairamb

Copy link
Copy Markdown
Owner

Summary

  • Adds two independent per-IP middlewares on every route of mainGroup: a token-bucket rate limiter and an in-flight concurrency semaphore
  • Excluded routes: /api/v1/workers/, /api/v1/heartbeat/, /api/mgmt/health, /metrics
  • Over-limit responses are 429 immediately (no queuing), with Retry-After: 60
  • Adds GET /api/mgmt/limits introspection endpoint so operators can verify active limits without restarting

Configuration (all optional, sane defaults)

Env var Default Purpose
SP_SERVER_RATE_LIMITING_REQUESTS_PER_MINUTE 300 Token-bucket refill per client IP; 0 disables
SP_SERVER_RATE_LIMITING_BURST 60 Instantaneous burst above sustained rate
SP_SERVER_RATE_LIMITING_MAX_CONCURRENT 20 In-flight semaphore per IP; 0 disables
SP_SERVER_RATE_LIMITING_TRUSTED_PROXIES 0 Trusted reverse-proxy hops for X-Forwarded-For; set 1 behind nginx

Observability

429 events are counted in solidping_http_rate_limited_total{reason="rate"|"concurrency"} for operator alerting.

Reviewer notes

  • TRUSTED_PROXIES=0 (default) uses RemoteAddr directly — trusting the header without this set is an IP-spoofing vector, intentionally documented
  • Tests cover both limiters, including a deflaked concurrency-limit test
  • CLAUDE.md updated with the full env-var reference

🤖 Generated with Claude Code

fclairamb and others added 16 commits May 12, 2026 07:44
Adds two independent middlewares applied to mainGroup with path
exclusions for /api/v1/workers/, /api/v1/heartbeat/, /api/mgmt/health,
and /metrics:

- Rate limiter: token bucket (golang.org/x/time/rate), default
  300 req/min with burst 60. Returns 429 + Retry-After: 60 + code
  RATE_LIMITED when exhausted.
- Concurrency limiter: per-IP semaphore, default 20 in-flight. Returns
  429 + code CONCURRENCY_LIMITED when full (no delay — sheds load
  rather than holding goroutines).

Per-IP state lives in a sync.Map keyed by client IP; a 2-minute
cleanup goroutine evicts entries idle >5 min so an attacker can't
grow the map unbounded. extractIP() honors a TrustedProxies count
to parse X-Forwarded-For safely behind reverse proxies without
opening an IP-spoofing vector when run directly.

solidping_http_rate_limited_total{reason="rate"|"concurrency"}
exposes 429 counts for operator alerting.

Both limits opt out by setting RequestsPerMinute=0 or MaxConcurrent=0
independently via SP_SERVER_RATE_LIMITING_* env vars.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
The original 016_org_entitlements migration was edited in-place after
some dev databases had already applied the old column-per-limit schema.
Those databases now drift from the model. Migration 022 drops and
recreates the table with the payload-text shape the code expects. No
data migration needed — entitlements are seeded lazily on first access,
so the table is always empty at migration time.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Moves the translate="no" / google notranslate hints from the #root div
up to <html>, so browser translation extensions (Chrome auto-translate,
etc.) don't garble status labels and check names before the React app
mounts.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
The original test signalled "ready" before calling the handler and
then closed the release channel as soon as all three goroutines had
signalled. Under sequential goroutine scheduling, the first two
handlers could acquire the semaphore, see release already closed,
exit, and free the slot before the third goroutine ever called the
handler — so all three ended up returning 200.

Switched to a signal-after-acquire pattern: the holders publish on
`inside` once they're past the semaphore, the test waits for both
acquisitions to land, then runs the overflow request synchronously
and asserts 429 before releasing the holders.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Public endpoint that returns the configured rate-limit and concurrency
limits plus the calling IP's current token balance and in-flight count.
Rate-limited clients can hit it to discover when their bucket refills.

The whole /api/mgmt/ prefix is now exempt from both middlewares
(was just /api/mgmt/health) so a 429'd client can still introspect.

Implementation:
- middleware.RateLimiter.StateFor(ip) takes a read-only snapshot of
  rate.Limiter.Tokens() and len(sem) without mutating either.
- Fresh IPs (no entry yet) report a full burst and zero in-flight.
- callerRemaining / callerInFlight are omitted when their respective
  limiter is disabled (RequestsPerMinute=0 or MaxConcurrent=0).
- Server holds a *RateLimiter reference so getLimits can call StateFor;
  RateLimiter.ExtractIP exposes the same trusted-proxy logic the
  middlewares use, so callers and limits agree on the IP.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@fclairamb
fclairamb enabled auto-merge (squash) May 16, 2026 00:46
fclairamb and others added 6 commits May 16, 2026 02:55
Playwright runs from one runner IP and fans out parallel requests far
above the new defaults (300 req/min, 60 burst, 20 concurrent), causing
widespread 429s and login-form timeouts. Production defaults stay
unchanged; only the CI E2E job opts out.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
The koanf env loader replaces every underscore in SP_*-prefixed names
with a dot, so SP_SERVER_RATE_LIMITING_REQUESTS_PER_MINUTE mapped to
server.rate.limiting.requests.per.minute and never matched the
snake_case koanf tags (server.rate_limiting.requests_per_minute).
Defaults applied on startup, but operator overrides documented in
CLAUDE.md were silently ignored. Added manual env reads next to the
existing SP_SHUTDOWN_TIMEOUT shim so all four knobs work as documented.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Manual env-var reads pushed Load() past gocognit's threshold. The
function is intentionally a long sequence of independent setters; the
existing funlen+cyclop suppressions cover the same shape.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
Inlining the four manual env reads pushed Load() over gocognit. The
helper hosts its own intEnv closure so there's one decode path, and
keeps Load() within the existing complexity budget without widening
nolint suppressions.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
varnamelen flagged the two-letter parameter. cfg is the receiver name
already used elsewhere in the file for the surrounding Config struct,
so it reads naturally and stays under the linter's threshold.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@fclairamb
fclairamb merged commit f9cc273 into main May 16, 2026
10 checks passed
@fclairamb
fclairamb deleted the feat/http-ip-rate-limiting branch May 16, 2026 01:56
@fclairamb fclairamb mentioned this pull request May 16, 2026
fclairamb added a commit that referenced this pull request Jun 23, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.1.0](v0.0.0...v0.1.0)
(2026-06-22)


### Features

* add check type registry, sample configs, notification senders, and
observability integrations
([eea049e](eea049e))
* batch — Warning/Degraded statuses, SSL/Docker check upgrades, MCP
OAuth 2.1, config-as-code
([#85](#85))
([936d830](936d830))
* batch spec implementations (dashboard UI, jobs, notifications, SaaS,
perf) ([#78](#78))
([fe003e4](fe003e4))
* bulk feature integration (discovery, web push, badges, webhooks, and
more) ([#73](#73))
([a976856](a976856))
* custom user-agent, refresh checks, vite plugin switch, CI updates
([#1](#1))
([cc00858](cc00858))
* documentation site served at /docs (co-located in web/docs)
([#88](#88))
([27d9ccd](27d9ccd))
* email check frontend (spec 03)
([#30](#30))
([aebd106](aebd106))
* email inbox foundation via JMAP (spec 01)
([#24](#24))
([0f3b0c1](0f3b0c1))
* email passive checks (spec 02)
([#27](#27))
([ba5536f](ba5536f))
* **entitlements:** trim to MaxSSOUsers + MaxChecksPerMinute + status
page history fixes
([#50](#50))
([a007de0](a007de0))
* **entitlements:** trim to MaxSSOUsers + MaxChecksPerMinute, enforce
both ([#49](#49))
([d25cc5f](d25cc5f))
* group incident correlation (spec 04 backend v1)
([#31](#31))
([1883986](1883986))
* **observability:** instrument hot path + add bench harness
([#60](#60))
([c6604cc](c6604cc))
* **oncall:** searchable timezone dropdown + sidebar logo polish
([#46](#46))
([4396898](4396898))
* per-IP HTTP rate limiting and concurrency limiting
([#59](#59))
([f9cc273](f9cc273))
* soften HTTP rate limits with bounded queues + request timeout
([#63](#63))
([025501b](025501b))
* SolidPing — distributed uptime monitoring platform
([eef4383](eef4383))
* **statuspages:** drag-and-drop resource reordering + dash conventions
([#41](#41))
([cf910d4](cf910d4))


### Bug Fixes

* **deps:** update dependency i18next to v26
([#26](#26))
([d5d1b7e](d5d1b7e))
* **deps:** update dependency lucide-react to v1
([#28](#28))
([cdc8e8c](cdc8e8c))
* **deps:** update dependency react-i18next to v17
([#29](#29))
([13135d8](13135d8))
* **deps:** update dependency recharts to v3.8.1
([#14](#14))
([5d95a3b](5d95a3b))
* **deps:** update go dependencies (non-major)
([#16](#16))
([2450f13](2450f13))
* **deps:** update go dependencies (non-major)
([#19](#19))
([f842310](f842310))
* **deps:** update go dependencies (non-major)
([#37](#37))
([c020eca](c020eca))
* **deps:** update go dependencies (non-major)
([#44](#44))
([ff0bcd0](ff0bcd0))
* **deps:** update go dependencies (non-major)
([#52](#52))
([2e3bc28](2e3bc28))
* **deps:** update go dependencies (non-major)
([#69](#69))
([a65ed4c](a65ed4c))
* **deps:** update go dependencies (non-major)
([#77](#77))
([a0920ff](a0920ff))
* **deps:** update go dependencies (non-major) to v1.4.2
([#86](#86))
([1eb7504](1eb7504))
* **deps:** update module github.com/aws/aws-sdk-go-v2/config to
v1.32.18 ([#72](#72))
([6406537](6406537))
* **deps:** update module github.com/aws/aws-sdk-go-v2/service/s3 to
v1.101.0 ([#39](#39))
([f9c9563](f9c9563))
* **deps:** update module github.com/go-webauthn/webauthn to v0.17.3
([#45](#45))
([593931a](593931a))
* **deps:** update module github.com/go-webauthn/webauthn to v0.17.4
([#70](#70))
([fca1c97](fca1c97))
* **deps:** update module github.com/ibm/sarama to v1.48.1
([#47](#47))
([93ccf3a](93ccf3a))
* **deps:** update module github.com/ibm/sarama to v1.48.2
([#54](#54))
([e84d868](e84d868))
* **deps:** update module github.com/ibm/sarama to v1.49.0
([#64](#64))
([fd61bd7](fd61bd7))
* **deps:** update module github.com/oapi-codegen/runtime to v1.4.1
([#65](#65))
([a3a3e9f](a3a3e9f))
* **deps:** update module github.com/prometheus/common to v0.67.5
([#61](#61))
([095dd6f](095dd6f))
* **deps:** update module github.com/slack-go/slack to v0.24.0
([#75](#75))
([6e86d5b](6e86d5b))
* **deps:** update module golang.org/x/sys to v0.44.0
([#42](#42))
([a245730](a245730))
* **deps:** update module golang.org/x/sys to v0.45.0
([#67](#67))
([49c3d90](49c3d90))
* **deps:** update module golang.org/x/term to v0.43.0
([#43](#43))
([4a934f1](4a934f1))
* **deps:** update module google.golang.org/grpc to v1.81.0
([#36](#36))
([1be183a](1be183a))
* **deps:** update module google.golang.org/grpc to v1.81.1
([#55](#55))
([6bfac2d](6bfac2d))
* status lifecycle improvements and created/running result handling
([#5](#5))
([fc64c7d](fc64c7d))
* **status0:** white page header and de-duplicated footer
([#48](#48))
([77506a7](77506a7))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
This was referenced Sep 8, 2026
fclairamb added a commit that referenced this pull request Oct 11, 2026
## What & why

Deals with every open alert on the Security tab.

**Fixed in this PR**
- Dependabot #9: `github.com/moby/go-archive` v0.2.0 → v0.3.0 (tar
archive can write outside the extraction dir).
- Dependabot #10: `github.com/moby/sys/user` v0.4.0 → v0.4.1 (unbounded
parsing DoS).
- CodeQL #65 (clear-text logging, grdp `sec.go`): `sendFlagged` logged
the plaintext PDU in hex at debug level, and the client info PDU carries
the RDP password. It now logs the length only. Also removed the debug
logs of the client random and the four NTLM signing/sealing keys (same
class of leak, not flagged).
- CodeQL #61 (allocation-size overflow, `credentials/secret_fields.go`):
map size hint is now `max(a, b)` instead of `a + b`. Same change on
`MergePatch`.

**Dismissed (no code change)**
- #72-#81, #68-#71 (weak crypto / weak hashing in vendored
`third_party/grdp`): RC4, MD4, MD5, SHA-1 and DES are mandated by RDP
standard security and NTLM. Same reasoning as the VNC DES alerts
#94/#95.
- #31 (MD5 in `checksip`): SIP digest auth (RFC 3261/2617) is MD5.
- #33 (SHA-256 on password, `passwords/bcrypt.go`): pre-hash before
bcrypt to bypass the 72-byte limit. bcrypt is the slow hash.
- #54 (InsecureSkipVerify, `checkrdp`): leaf-only certificate inspection
by design, same as #62/#93.
- #47/#48 (cookie Secure, `statuspagelock`): `Secure: httpx.IsTLS(req)`,
same as #44/#59.
- #39 (request forgery, `jmap/client.go`): the JMAP session URL is set
by a super admin (instance operator), and reaching their own mail
server, often on the LAN, is the feature. Same as the Freebox alert #35.
- #17 (clear-text logging, `slack/commands.go`): map-value taint through
the check config, the password never reaches the log. Same as #18.

## How to test

- `go build ./...` and `go test ./internal/crypto/credentials/
./internal/checkers/checkrdp/...` in `server/`
- `go test ./...` in `server/third_party/grdp`
- `golangci-lint` v2.14.0 on `internal/crypto/...`: 0 issues

## Checklist
- [x] `go build`, lint and tests pass on the touched packages (full
`make test` left to CI)
- [ ] Tests added or updated for the change (log-only and size-hint
changes, existing tests cover behaviour)
- [ ] Docs updated (not user-visible)
- [ ] Schema changes (none)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
fclairamb added a commit that referenced this pull request Nov 9, 2026
…e fixes (#824)

## What changed
- **Dashboard glance strips** (#58): the "Checks at a glance" 24h strips
were always grey because they read hourly summary rows that don't exist
for the last 24h. New org endpoint `GET /orgs/:org/availability/buckets`
serves bucketed availability from raw results; the dashboard uses it.
- **Failed sign-ins** (#59): events now show the email tried (and retry
count); admins also see the member's name when it matches; members see
failed attempts against their own account (never the source IP).
- **Log noise** (#57): stale incident acks log at WARN, report schedules
of deleted orgs are ignored (and disabled on org deletion), retryable
SMTP errors log at WARN and sends are limited to 2 concurrent
(`email.max_concurrent_sends`).

Batch gate: build, lint, full Go tests, dash0 typecheck/lint and
Playwright (1005 passed) all green.

Closes fclairamb/solidping-business#57
Closes fclairamb/solidping-business#58
Closes fclairamb/solidping-business#59

## Decided by autopilot
- #59 (failed sign-in display): email as typed, plus member name for
admins when it matches.
- #57 (SMTP burst): concurrency limit rather than a pooled connection.

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant