Harden network auth: failed-attempt lockout on sensitive routes + weak-key warning (#660)#663
Open
ipezygj wants to merge 1 commit into
Open
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:app.ts) trusts loopback only (isLoopbackAddress).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, connectorexecute/add/remove/open/close, tradingswap/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
gateway-security.ts, wired into the existingonRequesthook): 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) afterGATEWAY_AUTH_FAIL_MAX(default 10) failures withinGATEWAY_AUTH_FAIL_WINDOW_MS(default 15 min). A successful auth clears the counter.GATEWAY_API_KEYis 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.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 typecheckclean.pnpm lintclean on changed files (0 errors).test/services/gateway-security.test.ts: weak-key detection + lockout threshold / per-source isolation / window expiry / clear-on-success.Refs #652, #660.