MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / isForeignLoopbackRequest

Function isForeignLoopbackRequest

scripts/bind-host.mjs:148–167  ·  view source on GitHub ↗
(
  req,
  bindHost,
  { upgrade = false, env = process.env } = {},
)

Source from the content-addressed store, hash-verified

146 * @param {{ upgrade?: boolean, env?: Record<string, string | undefined> }} [options]
147 */
148export function isForeignLoopbackRequest(
149 req,
150 bindHost,
151 { upgrade = false, env = process.env } = {},
152) {
153 if (!isLoopbackBind(bindHost)) return false;
154 const allowedHosts = resolveAllowedHosts(env);
155 const isTrusted = (hostname) =>
156 isLoopbackHostname(hostname) || allowedHosts.has(hostname);
157 const parsedHost = parseHttpHostHeader(req.headers?.host);
158 if (!parsedHost || !isTrusted(parsedHost.hostname)) {
159 return true;
160 }
161 const rawOrigin = req.headers?.origin;
162 if (rawOrigin === undefined) return false;
163 const method = String(req.method ?? "GET").toUpperCase();
164 if (!upgrade && SAFE_HTTP_METHODS.has(method)) return false;
165 const parsedOrigin = parseHttpOriginHeader(rawOrigin);
166 return !parsedOrigin || !isTrusted(parsedOrigin.hostname);
167}
168
169/**
170 * Resolve the listen address.

Callers 5

startStaticServerFunction · 0.90
handleHttpFunction · 0.90
handleUpgradeFunction · 0.90
startIngressFunction · 0.90
bind-host.test.tsFile · 0.90

Calls 5

isLoopbackBindFunction · 0.85
resolveAllowedHostsFunction · 0.85
parseHttpHostHeaderFunction · 0.85
isTrustedFunction · 0.85
parseHttpOriginHeaderFunction · 0.85

Tested by

no test coverage detected