MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / checkDsn

Function checkDsn

packages/core/src/utils/isSentryRequestUrl.ts:24–40  ·  view source on GitHub ↗
(url: string, dsn: DsnComponents | undefined)

Source from the content-addressed store, hash-verified

22}
23
24function 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
42function hostnameMatchesDsnHost(hostname: string, dsnHost: string): boolean {
43 return hostname === dsnHost || (dsnHost.length > 0 && hostname.endsWith(`.${dsnHost}`));

Callers 1

isSentryRequestUrlFunction · 0.85

Calls 4

parseStringToURLObjectFunction · 0.90
isURLObjectRelativeFunction · 0.90
hostnameMatchesDsnHostFunction · 0.85
testMethod · 0.65

Tested by

no test coverage detected