@sentry/core
Version:
Base implementation for all Sentry JavaScript SDKs
31 lines (30 loc) • 1.1 kB
JavaScript
import { isURLObjectRelative, parseStringToURLObject } from "./url.js";
// src/utils/isSentryRequestUrl.ts
/**
* Checks whether given url points to Sentry server
*
* @param url url to verify
*/
function isSentryRequestUrl(url, client) {
const dsn = client?.getDsn();
const tunnel = client?.getOptions().tunnel;
return checkDsn(url, dsn) || checkTunnel(url, tunnel);
}
function checkTunnel(url, tunnel) {
if (!tunnel) return false;
return removeTrailingSlash(url) === removeTrailingSlash(tunnel);
}
function checkDsn(url, dsn) {
const urlParts = parseStringToURLObject(url);
if (!urlParts || isURLObjectRelative(urlParts)) return false;
if (!dsn) return false;
return hostnameMatchesDsnHost(urlParts.hostname, dsn.host) && /(^|&|\?)sentry_key=/.test(urlParts.search);
}
function hostnameMatchesDsnHost(hostname, dsnHost) {
return hostname === dsnHost || dsnHost.length > 0 && hostname.endsWith(`.${dsnHost}`);
}
function removeTrailingSlash(str) {
return str[str.length - 1] === "/" ? str.slice(0, -1) : str;
}
export { isSentryRequestUrl };
//# sourceMappingURL=isSentryRequestUrl.js.map