( url: string, accessToken: string, requestId: string )
| 75 | } |
| 76 | |
| 77 | async function fetchWithDNSPinning( |
| 78 | url: string, |
| 79 | accessToken: string, |
| 80 | requestId: string |
| 81 | ): Promise<SecureFetchResponse | null> { |
| 82 | try { |
| 83 | const urlValidation = await validateUrlWithDNS(url, 'contentUrl') |
| 84 | if (!urlValidation.isValid) { |
| 85 | logger.warn(`[${requestId}] Invalid content URL: ${urlValidation.error}`, { url }) |
| 86 | return null |
| 87 | } |
| 88 | const headers: Record<string, string> = {} |
| 89 | if (accessToken) { |
| 90 | headers.Authorization = `Bearer ${accessToken}` |
| 91 | } |
| 92 | const response = await secureFetchWithPinnedIP(url, urlValidation.resolvedIP!, { headers }) |
| 93 | return response |
| 94 | } catch (error) { |
| 95 | logger.error(`[${requestId}] Error fetching URL with DNS pinning`, { |
| 96 | error: toError(error).message, |
| 97 | url: sanitizeUrlForLog(url), |
| 98 | }) |
| 99 | return null |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Format Microsoft Teams Graph change notification |
no test coverage detected