MCPcopy Index your code
hub / github.com/inkeep/open-knowledge / rejectUpgradeIfNotLoopback

Function rejectUpgradeIfNotLoopback

packages/cli/src/commands/ui-proxy.ts:76–92  ·  view source on GitHub ↗
(req: IncomingMessage, clientSocket: Duplex)

Source from the content-addressed store, hash-verified

74const DEFAULT_REQUEST_TIMEOUT_MS = 30_000;
75
76export function rejectUpgradeIfNotLoopback(req: IncomingMessage, clientSocket: Duplex): boolean {
77 const peerAddress = req.socket?.remoteAddress;
78 if (peerAddress !== undefined && !isLoopbackAddress(peerAddress)) {
79 clientSocket.destroy();
80 return true;
81 }
82 if (!isAllowedWorkspaceHostHeader(req.headers.host)) {
83 clientSocket.destroy();
84 return true;
85 }
86 const origin = req.headers.origin;
87 if (typeof origin === 'string' && !isAllowedApiOrigin(origin)) {
88 clientSocket.destroy();
89 return true;
90 }
91 return false;
92}
93
94export function proxyUpgrade(
95 req: IncomingMessage,

Callers 2

handleUpgradeFunction · 0.90
startProxyServerFunction · 0.85

Calls 4

isLoopbackAddressFunction · 0.85
isAllowedApiOriginFunction · 0.85
destroyMethod · 0.65

Tested by

no test coverage detected