Skip to content

Harden network auth: failed-attempt lockout on sensitive routes + weak-key warning (#660)#663

Open
ipezygj wants to merge 1 commit into
hummingbot:developmentfrom
ipezygj:harden-network-auth-lockout
Open

Harden network auth: failed-attempt lockout on sensitive routes + weak-key warning (#660)#663
ipezygj wants to merge 1 commit into
hummingbot:developmentfrom
ipezygj:harden-network-auth-lockout

Conversation

@ipezygj

@ipezygj ipezygj commented Jul 3, 2026

Copy link
Copy Markdown

Summary

Follow-up to #652 / #660 §2. When API-token auth is enabled (GATEWAY_REQUIRE_AUTH / GATEWAY_API_KEY), the token is the only control on network-reachable fund-moving routes — but the anti-brute-force protection has a gap:

  • The auth hook (app.ts) trusts loopback only (isLoopbackAddress).
  • The global rate limiter allow-lists all private-network sources (isTrustedLocalAddress → 10/8, 172.16/12, 192.168/16).

So a LAN- or compose-adjacent client (a sibling container, another host on the same private network) must present the token (it isn't loopback) but is not rate-limited — it can brute-force the token against sensitive routes (/wallet, /config/update, /restart, connector execute/add/remove/open/close, trading swap/clmm) at unlimited rate. This is the residual #660 §2 describes ("per-route strict limit + lockout after N failed attempts"), and it also contradicts the module's own stated principle that strict rate-limiting/lockout apply only to non-loopback requests.

Change

  • Failed-auth lockout (gateway-security.ts, wired into the existing onRequest hook): keyed on source IP, incremented only on a failed token check. A correctly authenticated client — including a sibling-container bot the rate limiter allow-lists — is never affected; a token-guessing client is locked out (429) after GATEWAY_AUTH_FAIL_MAX (default 10) failures within GATEWAY_AUTH_FAIL_WINDOW_MS (default 15 min). A successful auth clears the counter.
  • Weak-key warning: GATEWAY_API_KEY is currently accepted with no strength check; warn (non-fatal) when it is < 16 chars, since a weak operator key plus the unthrottled private-network path is the realistic risk. The auto-generated key is 256-bit and unaffected.
  • Unit tests for both.

Deliberately does not change the general rate limiter (its private-network allow-list is intended to keep legitimate high-volume bot traffic unthrottled), so normal throughput is unchanged.

Scope / limitations

An IP-keyed lockout is a proportionate mitigation for this local/LAN threat model; it does not by itself stop an attacker who can rotate many source IPs (also noted in #660 §2). The primary defense remains a high-entropy token. Credential-keyed lockout and per-route limits can layer on top later.

Testing

  • pnpm typecheck clean.
  • pnpm lint clean on changed files (0 errors).
  • New tests pass in test/services/gateway-security.test.ts: weak-key detection + lockout threshold / per-source isolation / window expiry / clear-on-success.

Refs #652, #660.

…k-key warning (hummingbot#660 §2)

The global rate limiter allow-lists all private-network sources (isTrustedLocalAddress),
while the API-token auth hook trusts only loopback. A LAN / compose-adjacent client is
therefore required to present the token but is NOT rate-limited, so it can brute-force the
token against sensitive fund-moving routes at unlimited rate — the gap hummingbot#660 §2 describes.

- Add an IP-keyed failed-auth lockout (gateway-security.ts). Only FAILED token checks
  increment it, so a correctly authenticated client — including a sibling-container bot the
  rate limiter allow-lists — is never affected; a guessing client is locked out after
  GATEWAY_AUTH_FAIL_MAX (default 10) failures per GATEWAY_AUTH_FAIL_WINDOW_MS (default 15m).
  Wired into the existing onRequest auth hook; a successful auth clears the counter.
- Warn when an operator-supplied GATEWAY_API_KEY is weak (<16 chars); the auto-generated key
  is 256-bit. Non-fatal, so existing deployments keep working.
- Unit tests for both (isWeakApiKey + lockout threshold / per-source / window-expiry / clear).

Scope note: an IP-keyed lockout is a proportionate mitigation for this local/LAN threat model
and does not by itself stop IP-rotating attackers (hummingbot#660 §2); the primary defense remains a
high-entropy token. Does not touch the general rate limiter, so legitimate bot throughput is
unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant