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