fix(agent): exempt direct loopback callers from the IP whitelist#1744
Open
Scra3 wants to merge 1 commit into
Open
fix(agent): exempt direct loopback callers from the IP whitelist#1744Scra3 wants to merge 1 commit into
Scra3 wants to merge 1 commit into
Conversation
|
Coverage Impact ⬆️ Merging this pull request will increase total coverage on Modified Files with Diff Coverage (1)
🛟 Help
|
27ef873 to
df8902f
Compare
df8902f to
206ab05
Compare
206ab05 to
071d76b
Compare
071d76b to
4f2ddf5
Compare
The IP whitelist evaluated `x-forwarded-for ?? request.ip` on all /forest. The embedded workflow-executor reaches /forest over a loopback socket with no real client IP, so with the whitelist enabled it was rejected as 127.0.0.1 (403 at probe → the executor never started). ip-whitelist `checkIp` now exempts a trusted internal caller before the rule check: one reaching us directly over a loopback socket with no proxy hop (no `x-forwarded-for`). It keys on `req.socket.remoteAddress` (the true peer), never request.ip / x-forwarded-for (spoofable, and request.ip follows the header once the host app sets app.proxy). The check is feature-agnostic — a caller behind a same-host reverse proxy carries `x-forwarded-for` and is not exempted, so its real IP is still checked; and `checkIp` runs after koa-jwt, so an exempted request is already authenticated. Scope: the executor case only. Whether the MCP channel should be subject to the IP whitelist is a deferred product decision (PRD-752) — mounted-MCP in-process calls remain 403 when the whitelist is enabled, documented as a known limitation (PRD-753) rather than silently exempted here. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
4f2ddf5 to
5306eaa
Compare
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.

What
The agent's IP whitelist evaluated
x-forwarded-for ?? request.ipon all/forestroutes. The embedded workflow-executor reaches/forestover a loopback socket with no real client IP, so once a customer enabled the whitelist the executor was rejected as127.0.0.1→ 403 at its probe → the executor never started.Fix
IpWhitelist.checkIpnow exempts a trusted internal caller before the rule check: one reaching us directly over a loopback socket with no proxy hop (nox-forwarded-for).req.socket.remoteAddress(the true socket peer) — neverrequest.ip/x-forwarded-for, which are spoofable once the host app setsapp.proxy.x-forwarded-for, so it is not exempted and its real IP is still checked normally.checkIpruns after koa-jwt, so an exempted request is already authenticated; a remote attacker can neither forge the socket peer nor pass koa-jwt without theauthSecret.Scope (deliberately narrow)
Fixes only the executor case. Whether the MCP channel should be subject to the IP whitelist is a deferred product decision (Slack thread, PRD-752). Consequences, documented (PRD-753), not changed here:
403(known limitation, not silently exempted).Tests
packages/agent/test/routes/security/ip-whitelist.test.ts— exemption for the 3 loopback socket forms with no proxy hop; not exempt for a non-loopback socket, nor for a loopback socket carryingx-forwarded-for(proxied user); anti-spoof (external socket +x-forwarded-for: 127.0.0.1-> 403 on the header IP); non-regression (proxied user from a whitelisted IP passes the normal check).Note
Exempt direct loopback callers from IP whitelist checks in agent
Requests originating from a loopback socket (
127.0.0.1,::1,::ffff:127.0.0.1) with nox-forwarded-forheader now bypass IP whitelist validation inIpWhitelist.checkIp. ADebuglog line is emitted for each exempted request. Loopback sockets that carry anx-forwarded-forheader are still subject to normal IP rule checks using the header value.Macroscope summarized 5306eaa.