MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / isAllowedHost

Function isAllowedHost

packages/server/src/middleware/hostnames.ts:119–153  ·  view source on GitHub ↗
(host: string | undefined, opts: HostCheckOptions)

Source from the content-addressed store, hash-verified

117 * when `opts.disable` is set.
118 */
119export function isAllowedHost(host: string | undefined, opts: HostCheckOptions): boolean {
120 if (opts.disable === true) {
121 return true;
122 }
123 if (host === undefined || host.length === 0) {
124 return false;
125 }
126 const h = stripPort(host);
127
128 if (h === 'localhost' || h === '127.0.0.1' || h === '::1' || h === '[::1]') {
129 return true;
130 }
131 if (h.endsWith('.localhost')) {
132 return true;
133 }
134 if (net.isIP(h) !== 0) {
135 return true;
136 }
137 if (opts.boundHost !== undefined && h === stripPort(opts.boundHost)) {
138 return true;
139 }
140 if (opts.extra !== undefined) {
141 for (const entry of opts.extra) {
142 if (entry.startsWith('.')) {
143 const base = entry.slice(1);
144 if (h === base || h.endsWith(entry)) {
145 return true;
146 }
147 } else if (h === entry) {
148 return true;
149 }
150 }
151 }
152 return false;
153}
154
155/**
156 * Build the Fastify `onRequest` hook and the reusable `isAllowed` predicate.

Callers 3

hostnames.test.tsFile · 0.90
onUpgradeMethod · 0.90
isAllowedFunction · 0.85

Calls 1

stripPortFunction · 0.85

Tested by

no test coverage detected