MCPcopy Create free account
hub / github.com/Noumena-Network/code / validateURL

Function validateURL

src/tools/WebFetchTool/utils.ts:142–174  ·  view source on GitHub ↗
(url: string)

Source from the content-addressed store, hash-verified

140}
141
142export function validateURL(url: string): boolean {
143 if (url.length > MAX_URL_LENGTH) {
144 return false
145 }
146
147 let parsed
148 try {
149 parsed = new URL(url)
150 } catch {
151 return false
152 }
153
154 if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
155 return false
156 }
157
158 // As long as we aren't supporting aiming to cookies or internal domains,
159 // we should block URLs with usernames/passwords too, even though these
160 // seem exceedingly unlikely.
161 if (parsed.username || parsed.password) {
162 return false
163 }
164
165 // Initial filter that this isn't a privileged, company-internal URL
166 // by checking that the hostname is publicly resolvable
167 const hostname = parsed.hostname
168 const parts = hostname.split('.')
169 if (parts.length < 2) {
170 return false
171 }
172
173 return true
174}
175
176type DomainCheckResult =
177 | { status: 'allowed' }

Callers 2

utils.test.tsFile · 0.85
getURLMarkdownContentFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected