Fix/rest low severity nits 92#199
Open
James-Z-Zhang00 wants to merge 2 commits into
Open
Conversation
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
Two low-severity follow-up nits from #92 (MCP HTTP server v0.2 polish):
evictOldestswallows close errors — the LRU eviction inSessionsfire-and-forgot the delete withvoid this.delete(id)and, unlike thesibling
gc()/shutdown()paths, never attached a.catch(). A rejectingtransport.close()would surface as an unhandled promise rejection(which can terminate the process under Node's default behavior). Now caught and logged to stderr at warn.
Hardcoded
https://discovery scheme — the OAuth protected-resource discovery URLs (resourcefield andWWW-Authenticate: resource_metadata) were hardcoded tohttps://{Host}, which is correct behind the prod Caddy front but wrong for any non-TLS deployment thatdoesn't set
MCP_PUBLIC_URL. The scheme is now derived fromX-Forwarded-Protovia Express'strust proxy, defaulting to"loopback"(configurable with the new
E2A_TRUST_PROXYenv var).This is a correctness fix, not a security fix: the old hardcoded scheme had no spoofing risk (a constant can't be forged). The
trust proxy: loopbackgate is included so that readingX-Forwarded-Protocan't be abused by a forged header from an untrusted hop — it preserves the oldcode's un-spoofability while gaining accuracy. In prod (Caddy terminates TLS, forwards over localhost with
X-Forwarded-Proto: https) theadvertised URL is unchanged.
Operational risk
Low. No data, auth, billing, or external integrations touched.
MCP_PUBLIC_URLwill now advertisehttp://...in discovery (thereal scheme) instead of
https://.... This is strictly more correct; the only deployments affected were already misconfigured (advertising httpsthey couldn't serve).
MCP_PUBLIC_URLcontinues to override everything.X-Forwarded-Proto: httpsover loopback →trust proxy: "loopback"honors it → advertised URL stayshttps://....E2A_TRUST_PROXY(default"loopback"); operators behind a non-loopback proxy set it to their proxy's address/subnet, a hopcount, or a preset.
X-Forwarded-Proto— thatconfig lives in
e2a-ops, not here. Worth a glance on that side.Test plan
npm run build --workspace @e2a/mcp-server— clean (notscerrors)npm test --workspace @e2a/mcp-server— 126 passing (8 files)evictOldestregression: new test evicts an entry whoseclose()rejects; asserts the entry is still removed and the warning is logged (no unhandled rejection)X-Forwarded-Proto→ falls back to the real connection schemeX-Forwarded-Proto: https→ advertised ashttpstrustProxy: false+ spoofedX-Forwarded-Proto: https→ header dropped, falls back tohttpparseTrustProxyconfig: defaultloopback, booleans, integer hop-count, preset/CIDR passthrough