( domain: string, )
| 174 | | { status: 'check_failed'; error: Error } |
| 175 | |
| 176 | export async function checkDomainBlocklist( |
| 177 | domain: string, |
| 178 | ): Promise<DomainCheckResult> { |
| 179 | if (DOMAIN_CHECK_CACHE.has(domain)) { |
| 180 | return { status: 'allowed' } |
| 181 | } |
| 182 | try { |
| 183 | const response = await axios.get( |
| 184 | `https://api.anthropic.com/api/web/domain_info?domain=${encodeURIComponent(domain)}`, |
| 185 | { timeout: DOMAIN_CHECK_TIMEOUT_MS }, |
| 186 | ) |
| 187 | if (response.status === 200) { |
| 188 | if (response.data.can_fetch === true) { |
| 189 | DOMAIN_CHECK_CACHE.set(domain, true) |
| 190 | return { status: 'allowed' } |
| 191 | } |
| 192 | return { status: 'blocked' } |
| 193 | } |
| 194 | // Non-200 status but didn't throw |
| 195 | return { |
| 196 | status: 'check_failed', |
| 197 | error: new Error(`Domain check returned status ${response.status}`), |
| 198 | } |
| 199 | } catch (e) { |
| 200 | logError(e) |
| 201 | return { status: 'check_failed', error: e as Error } |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Check if a redirect is safe to follow |
no test coverage detected