(url: string, dsn: DsnComponents | undefined)
| 22 | } |
| 23 | |
| 24 | function checkDsn(url: string, dsn: DsnComponents | undefined): boolean { |
| 25 | // Requests to Sentry's ingest endpoint must have a `sentry_key` in the query string |
| 26 | // This is equivalent to the public_key which is required in the DSN |
| 27 | // see https://develop.sentry.dev/sdk/overview/#parsing-the-dsn |
| 28 | // Therefore, a request to the same host and with a `sentry_key` in the query string |
| 29 | // can be considered a request to the ingest endpoint. |
| 30 | const urlParts = parseStringToURLObject(url); |
| 31 | if (!urlParts || isURLObjectRelative(urlParts)) { |
| 32 | return false; |
| 33 | } |
| 34 | |
| 35 | if (!dsn) { |
| 36 | return false; |
| 37 | } |
| 38 | |
| 39 | return hostnameMatchesDsnHost(urlParts.hostname, dsn.host) && /(^|&|\?)sentry_key=/.test(urlParts.search); |
| 40 | } |
| 41 | |
| 42 | function hostnameMatchesDsnHost(hostname: string, dsnHost: string): boolean { |
| 43 | return hostname === dsnHost || (dsnHost.length > 0 && hostname.endsWith(`.${dsnHost}`)); |
no test coverage detected