Skip to content

Open-source status page, incident response and uptime monitoring

fix: notifications provider (#2033)

Maximilian Kaske276d41d3b783
diff --git a/apps/server/src/routes/v1/monitors/schema.ts b/apps/server/src/routes/v1/monitors/schema.ts
index ce4202475..464d87e7f 100644
--- a/apps/server/src/routes/v1/monitors/schema.ts
+++ b/apps/server/src/routes/v1/monitors/schema.ts
@@ -11,6 +11,7 @@ import {
monitorRegions,
} from "@openstatus/db/src/schema/constants";
import { AVAILABLE_REGIONS } from "@openstatus/regions";
+import { assertSafeUrlSync } from "@openstatus/utils";
import { ZodError } from "zod";
const statusAssertion = z
@@ -411,7 +412,18 @@ const baseRequest = z.object({
openTelemetry: z
.object({
endpoint: z
- .url()
+ .url({ protocol: /^https?$/ })
+ .refine(
+ (val) => {
+ try {
+ assertSafeUrlSync(val);
+ return true;
+ } catch {
+ return false;
+ }
+ },
+ { message: "URL must not target private or internal addresses" },
+ )
.optional()
.openapi({
description: "OTEL endpoint to send metrics to",
@@ -430,10 +442,23 @@ const baseRequest = z.object({
const httpRequestSchema = z.object({
method: z.enum(monitorMethods),
- url: z.url().openapi({
- description: "URL to request",
- examples: ["https://openstat.us", "https://www.openstatus.dev"],
- }),
+ url: z
+ .url({ protocol: /^https?$/ })
+ .refine(
+ (val) => {
+ try {
+ assertSafeUrlSync(val);
+ return true;
+ } catch {
+ return false;
+ }
+ },
+ { message: "URL must not target private or internal addresses" },
+ )
+ .openapi({
+ description: "URL to request",
+ examples: ["https://openstat.us", "https://www.openstatus.dev"],
+ }),
headers: z
.record(z.string(), z.string())
.optional()
diff --git a/apps/server/static/openapi-v1.json b/apps/server/static/openapi-v1.json
index 9858b8fee..2df066609 100644
--- a/apps/server/static/openapi-v1.json
+++ b/apps/server/static/openapi-v1.json
@@ -367,7 +367,7 @@
},
"jobType": {
"type": "string",
- "enum": ["http", "tcp", "imcp", "udp", "dns", "ssl"],
+ "enum": ["http", "tcp", "icmp", "udp", "dns", "ssl"],
"default": "http",
"description": "The type of the monitor"
},
@@ -1616,7 +1616,7 @@
},
"jobType": {
"type": "string",
- "enum": ["http", "tcp", "imcp", "udp", "dns", "ssl"],
+ "enum": ["http", "tcp", "icmp", "udp", "dns", "ssl"],
"default": "http",
"description": "The type of the monitor"
},
@@ -2157,7 +2157,7 @@
},
"jobType": {
"type": "string",
- "enum": ["http", "tcp", "imcp", "udp", "dns", "ssl"],
+ "enum": ["http", "tcp", "icmp", "udp", "dns", "ssl"],
"default": "http",
"description": "The type of the monitor"
},
diff --git a/packages/api/src/router/checker.ts b/packages/api/src/router/checker.ts
index 1f20ba22c..d44cf17a6 100644
--- a/packages/api/src/router/checker.ts
+++ b/packages/api/src/router/checker.ts
@@ -15,6 +15,7 @@ import { monitor, selectMonitorSchema } from "@openstatus/db/src/schema";
import { monitorRegionSchema } from "@openstatus/db/src/schema/constants";
import {
type httpPayloadSchema,
+ safeUrlSchema,
type tpcPayloadSchema,
transformHeaders,
} from "@openstatus/utils";
@@ -26,7 +27,7 @@ const ABORT_TIMEOUT = 10000;
// Input schemas
const httpTestInput = z.object({
- url: z.url(),
+ url: safeUrlSchema,
method: z
.enum([
"GET",
diff --git a/packages/api/src/service/import.ts b/packages/api/src/service/import.ts
index 7fdeea70a..cc4fb0e8a 100644
--- a/packages/api/src/service/import.ts
+++ b/packages/api/src/service/import.ts
@@ -899,7 +899,7 @@ async function writeMonitorsPhase(
jobType: data.jobType as
| "http"
| "tcp"
- | "imcp"
+ | "icmp"
| "udp"
| "dns"
| "ssl",
diff --git a/packages/db/package.json b/packages/db/package.json
index 2b2d64fcd..b6799e7df 100644
--- a/packages/db/package.json
+++ b/packages/db/package.json
@@ -18,6 +18,7 @@
"@openstatus/locales": "workspace:*",
"@openstatus/regions": "workspace:*",
"@openstatus/theme-store": "workspace:*",
+ "@openstatus/utils": "workspace:*",
"@t3-oss/env-core": "0.13.10",
"bcryptjs": "3.0.3",
"drizzle-orm": "0.44.4",
diff --git a/packages/db/src/schema/monitors/constants.ts b/packages/db/src/schema/monitors/constants.ts
index aecb36d56..9c86c6c8f 100644
--- a/packages/db/src/schema/monitors/constants.ts
+++ b/packages/db/src/schema/monitors/constants.ts
@@ -1,21 +1,9 @@
-export const monitorMethods = [
- "GET",
- "POST",
- "HEAD",
- "PUT",
- "PATCH",
- "DELETE",
- "TRACE",
- "CONNECT",
- "OPTIONS",
-] as const;
-export const monitorStatus = ["active", "error", "degraded"] as const;
+import {
+ MONITOR_JOB_TYPES,
+ MONITOR_METHODS,
+ MONITOR_STATUSES,
+} from "@openstatus/utils";
-export const monitorJobTypes = [
- "http",
- "tcp",
- "imcp",
- "udp",
- "dns",
- "ssl",
-] as const;
+export const monitorMethods = MONITOR_METHODS;
+export const monitorStatus = MONITOR_STATUSES;
+export const monitorJobTypes = MONITOR_JOB_TYPES;
diff --git a/packages/db/src/schema/notifications/validation.ts b/packages/db/src/schema/notifications/validation.ts
index 763377b54..e051e46b3 100644
--- a/packages/db/src/schema/notifications/validation.ts
+++ b/packages/db/src/schema/notifications/validation.ts
@@ -1,3 +1,4 @@
+import { safeUrlSchema } from "@openstatus/utils";
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import * as z from "zod";
@@ -34,18 +35,18 @@ const phoneRegex = new RegExp(
export const phoneSchema = z.string().regex(phoneRegex, "Invalid Number!");
export const emailSchema = z.email();
-export const urlSchema = z.url();
+export const urlSchema = safeUrlSchema;
export const ntfyDataSchema = z.object({
ntfy: z.object({
topic: z.string().prefault(""),
- serverUrl: z.string().prefault("https://ntfy.sh"),
+ serverUrl: safeUrlSchema.prefault("https://ntfy.sh"),
token: z.string().optional(),
}),
});
export const webhookDataSchema = z.object({
webhook: z.object({
- endpoint: z.url(),
+ endpoint: safeUrlSchema,
headers: z
.array(z.object({ key: z.string(), value: z.string() }))
.optional(),
@@ -69,7 +70,7 @@ export const telegramDataSchema = z.object({
export const grafanaOncallDataSchema = z.object({
"grafana-oncall": z.object({
- webhookUrl: z.url(),
+ webhookUrl: safeUrlSchema,
}),
});
diff --git a/packages/notifications/discord/package.json b/packages/notifications/discord/package.json
index 85c9971ff..0642e0bc0 100644
--- a/packages/notifications/discord/package.json
+++ b/packages/notifications/discord/package.json
@@ -9,6 +9,7 @@
"dependencies": {
"@openstatus/db": "workspace:*",
"@openstatus/notification-base": "workspace:*",
+ "@openstatus/utils": "workspace:*",
"zod": "4.1.13"
},
"devDependencies": {
diff --git a/packages/notifications/discord/src/index.ts b/packages/notifications/discord/src/index.ts
index 02bda1232..acd22ab7d 100644
--- a/packages/notifications/discord/src/index.ts
+++ b/packages/notifications/discord/src/index.ts
@@ -4,6 +4,7 @@ import {
type NotificationContext,
buildCommonMessageData,
} from "@openstatus/notification-base";
+import { assertSafeUrl } from "@openstatus/utils";
import {
type DiscordEmbed,
buildAlertEmbed,
@@ -16,6 +17,7 @@ const postToWebhook = async (embeds: DiscordEmbed[], webhookUrl: string) => {
throw new Error("Discord webhook URL is required");
}
+ await assertSafeUrl(webhookUrl);
const res = await fetch(webhookUrl, {
method: "POST",
headers: {
diff --git a/packages/notifications/google-chat/package.json b/packages/notifications/google-chat/package.json
index e4c5fb805..1db7ee088 100644
--- a/packages/notifications/google-chat/package.json
+++ b/packages/notifications/google-chat/package.json
@@ -9,6 +9,7 @@
"dependencies": {
"@openstatus/db": "workspace:*",
"@openstatus/notification-base": "workspace:*",
+ "@openstatus/utils": "workspace:*",
"zod": "4.1.13"
},
"devDependencies": {
diff --git a/packages/notifications/google-chat/src/index.ts b/packages/notifications/google-chat/src/index.ts
index a4b5febd4..8d43630dd 100644
--- a/packages/notifications/google-chat/src/index.ts
+++ b/packages/notifications/google-chat/src/index.ts
@@ -1,7 +1,9 @@
import { googleChatDataSchema } from "@openstatus/db/src/schema";
import type { NotificationContext } from "@openstatus/notification-base";
+import { assertSafeUrl } from "@openstatus/utils";
const postToWebhook = async (content: string, webhookUrl: string) => {
+ await assertSafeUrl(webhookUrl);
const res = await fetch(webhookUrl, {
method: "POST",
headers: {
diff --git a/packages/notifications/grafana-oncall/package.json b/packages/notifications/grafana-oncall/package.json
index 87711baac..b683721ee 100644
--- a/packages/notifications/grafana-oncall/package.json
+++ b/packages/notifications/grafana-oncall/package.json
@@ -9,6 +9,7 @@
"dependencies": {
"@openstatus/db": "workspace:*",
"@openstatus/notification-base": "workspace:*",
+ "@openstatus/utils": "workspace:*",
"zod": "4.1.13"
},
"devDependencies": {
diff --git a/packages/notifications/grafana-oncall/src/index.ts b/packages/notifications/grafana-oncall/src/index.ts
index 8f5eedb78..3e42d2f17 100644
--- a/packages/notifications/grafana-oncall/src/index.ts
+++ b/packages/notifications/grafana-oncall/src/index.ts
@@ -1,4 +1,5 @@
import type { NotificationContext } from "@openstatus/notification-base";
+import { assertSafeUrl } from "@openstatus/utils";
import { GrafanaOncallPayload, GrafanaOncallSchema } from "./schema";
export const sendAlert = async ({
@@ -20,6 +21,7 @@ export const sendAlert = async ({
link_to_upstream_details: `https://www.openstatus.dev/app/${monitor.id}/overview`,
});
+ await assertSafeUrl(config.webhookUrl);
const res = await fetch(config.webhookUrl, {
method: "POST",
body: JSON.stringify(event),
@@ -54,6 +56,7 @@ export const sendDegraded = async ({
link_to_upstream_details: `https://www.openstatus.dev/app/${monitor.id}/overview`,
});
+ await assertSafeUrl(config.webhookUrl);
const res = await fetch(config.webhookUrl, {
method: "POST",
body: JSON.stringify(event),
@@ -88,6 +91,7 @@ export const sendRecovery = async ({
link_to_upstream_details: `https://www.openstatus.dev/app/${monitor.id}/overview`,
});
+ await assertSafeUrl(config.webhookUrl);
const res = await fetch(config.webhookUrl, {
method: "POST",
body: JSON.stringify(event),
@@ -115,6 +119,7 @@ export const sendTest = async (props: { webhookUrl: string }) => {
link_to_upstream_details: "https://www.openstatus.dev",
});
+ await assertSafeUrl(webhookUrl);
try {
const res = await fetch(webhookUrl, {
method: "POST",
diff --git a/packages/notifications/ntfy/package.json b/packages/notifications/ntfy/package.json
index 0f4d9eec2..3a7a25b9c 100644
--- a/packages/notifications/ntfy/package.json
+++ b/packages/notifications/ntfy/package.json
@@ -9,6 +9,7 @@
"dependencies": {
"@openstatus/db": "workspace:*",
"@openstatus/notification-base": "workspace:*",
+ "@openstatus/utils": "workspace:*",
"zod": "4.1.13"
},
"devDependencies": {
diff --git a/packages/notifications/ntfy/src/index.ts b/packages/notifications/ntfy/src/index.ts
index 0f8f35900..64e094d00 100644
--- a/packages/notifications/ntfy/src/index.ts
+++ b/packages/notifications/ntfy/src/index.ts
@@ -1,5 +1,6 @@
import { ntfyDataSchema } from "@openstatus/db/src/schema";
import type { NotificationContext } from "@openstatus/notification-base";
+import { assertSafeUrl } from "@openstatus/utils";
export const sendAlert = async ({
monitor,
@@ -22,6 +23,7 @@ export const sendAlert = async ({
? `${notificationData.ntfy.serverUrl}/${notificationData.ntfy.topic}`
: `https://ntfy.sh/${notificationData.ntfy.topic}`;
+ await assertSafeUrl(url);
const res = await fetch(url, {
method: "post",
body,
@@ -50,6 +52,7 @@ export const sendRecovery = async ({
? `${notificationData.ntfy.serverUrl}/${notificationData.ntfy.topic}`
: `https://ntfy.sh/${notificationData.ntfy.topic}`;
+ await assertSafeUrl(url);
const res = await fetch(url, {
method: "post",
body,
@@ -71,7 +74,7 @@ export const sendDegraded = async ({
const body = `Your monitor ${name} / ${monitor.url} is degraded `;
- const authorization = notificationData.ntfy
+ const authorization = notificationData.ntfy.token
? { Authorization: `Bearer ${notificationData.ntfy.token}` }
: undefined;
@@ -79,6 +82,7 @@ export const sendDegraded = async ({
? `${notificationData.ntfy.serverUrl}/${notificationData.ntfy.topic}`
: `https://ntfy.sh/${notificationData.ntfy.topic}`;
+ await assertSafeUrl(url);
const res = await fetch(url, {
method: "post",
body,
@@ -104,6 +108,7 @@ export const sendTest = async ({
? { Authorization: `Bearer ${token}` }
: undefined;
const url = serverUrl ? `${serverUrl}/${topic}` : `https://ntfy.sh/${topic}`;
+ await assertSafeUrl(url);
try {
await fetch(url, {
method: "post",
diff --git a/packages/notifications/slack/package.json b/packages/notifications/slack/package.json
index f3f6a1a4b..a9c910806 100644
--- a/packages/notifications/slack/package.json
+++ b/packages/notifications/slack/package.json
@@ -9,6 +9,7 @@
"dependencies": {
"@openstatus/db": "workspace:*",
"@openstatus/notification-base": "workspace:*",
+ "@openstatus/utils": "workspace:*",
"zod": "4.1.13"
},
"devDependencies": {
diff --git a/packages/notifications/slack/src/index.ts b/packages/notifications/slack/src/index.ts
index dfb3432fc..1119f86f8 100644
--- a/packages/notifications/slack/src/index.ts
+++ b/packages/notifications/slack/src/index.ts
@@ -4,6 +4,7 @@ import {
type NotificationContext,
buildCommonMessageData,
} from "@openstatus/notification-base";
+import { assertSafeUrl } from "@openstatus/utils";
import {
buildAlertBlocks,
buildDegradedBlocks,
@@ -16,6 +17,7 @@ const postToWebhook = async (body: any, webhookUrl: string) => {
throw new Error("Slack webhook URL is required");
}
+ await assertSafeUrl(webhookUrl);
const res = await fetch(webhookUrl, {
method: "POST",
body: JSON.stringify(body),
diff --git a/packages/notifications/webhook/src/index.ts b/packages/notifications/webhook/src/index.ts
index 3a87fd821..3be4b2ec8 100644
--- a/packages/notifications/webhook/src/index.ts
+++ b/packages/notifications/webhook/src/index.ts
@@ -1,5 +1,5 @@
import type { NotificationContext } from "@openstatus/notification-base";
-import { transformHeaders } from "@openstatus/utils";
+import { assertSafeUrl, transformHeaders } from "@openstatus/utils";
import { PayloadSchema, WebhookSchema } from "./schema";
export const sendAlert = async ({
@@ -21,6 +21,7 @@ export const sendAlert = async ({
errorMessage: message,
});
+ await assertSafeUrl(notificationData.webhook.endpoint);
const res = await fetch(notificationData.webhook.endpoint, {
method: "post",
body: JSON.stringify(body),
@@ -53,6 +54,7 @@ export const sendRecovery = async ({
errorMessage: message,
});
const url = notificationData.webhook.endpoint;
+ await assertSafeUrl(url);
const res = await fetch(url, {
method: "post",
body: JSON.stringify(body),
@@ -85,6 +87,7 @@ export const sendDegraded = async ({
errorMessage: message,
});
+ await assertSafeUrl(notificationData.webhook.endpoint);
const res = await fetch(notificationData.webhook.endpoint, {
method: "post",
body: JSON.stringify(body),
@@ -116,6 +119,7 @@ export const sendTest = async ({
statusCode: 200,
latency: 1337,
});
+ await assertSafeUrl(url);
try {
const response = await fetch(url, {
method: "post",
diff --git a/packages/subscriptions/package.json b/packages/subscriptions/package.json
index 86b00b051..ac771c976 100644
--- a/packages/subscriptions/package.json
+++ b/packages/subscriptions/package.json
@@ -16,6 +16,7 @@
"dependencies": {
"@openstatus/db": "workspace:*",
"@openstatus/emails": "workspace:*",
+ "@openstatus/utils": "workspace:*",
"zod": "4.1.13"
},
"devDependencies": {
diff --git a/packages/subscriptions/src/channels/webhook.ts b/packages/subscriptions/src/channels/webhook.ts
index f834c225c..711103896 100644
--- a/packages/subscriptions/src/channels/webhook.ts
+++ b/packages/subscriptions/src/channels/webhook.ts
@@ -1,3 +1,4 @@
+import { assertSafeUrl } from "@openstatus/utils";
import { z } from "zod";
import type { PageUpdate, Subscription } from "../types";
@@ -31,6 +32,7 @@ export async function sendWebhookVerification(
throw new Error("Webhook URL is required for webhook channel");
}
+ await assertSafeUrl(subscription.webhookUrl);
const response = await fetch(subscription.webhookUrl, {
method: "POST",
headers: { "Content-Type": "application/json" },
@@ -97,6 +99,7 @@ export async function sendWebhookNotifications(
}
try {
+ await assertSafeUrl(subscription.webhookUrl);
const response = await fetch(subscription.webhookUrl, {
method: "POST",
headers,
diff --git a/packages/tinybird/src/schema.ts b/packages/tinybird/src/schema.ts
index f3dccc3c7..81e0772e6 100644
--- a/packages/tinybird/src/schema.ts
+++ b/packages/tinybird/src/schema.ts
@@ -1,6 +1,6 @@
import { z } from "zod";
-export const jobTypes = ["http", "tcp", "imcp", "udp", "dns", "ssl"] as const;
+export const jobTypes = ["http", "tcp", "icmp", "udp", "dns", "ssl"] as const;
export const jobTypeEnum = z.enum(jobTypes);
export type JobType = z.infer<typeof jobTypeEnum>;
diff --git a/packages/utils/package.json b/packages/utils/package.json
index 706bf9205..6c0ce39d7 100644
--- a/packages/utils/package.json
+++ b/packages/utils/package.json
@@ -2,11 +2,10 @@
"name": "@openstatus/utils",
"version": "1.0.0",
"description": "",
- "main": "index.ts",
+ "main": "src/index.ts",
"scripts": {},
"dependencies": {
"@openstatus/assertions": "workspace:*",
- "@openstatus/db": "workspace:*",
"@openstatus/regions": "workspace:*",
"zod": "4.1.13"
},
diff --git a/packages/utils/src/constants.ts b/packages/utils/src/constants.ts
new file mode 100644
index 000000000..0ffb264df
--- /dev/null
+++ b/packages/utils/src/constants.ts
@@ -0,0 +1,22 @@
+export const MONITOR_METHODS = [
+ "GET",
+ "POST",
+ "HEAD",
+ "PUT",
+ "PATCH",
+ "DELETE",
+ "TRACE",
+ "CONNECT",
+ "OPTIONS",
+] as const;
+
+export const MONITOR_STATUSES = ["active", "error", "degraded"] as const;
+
+export const MONITOR_JOB_TYPES = [
+ "http",
+ "tcp",
+ "icmp",
+ "udp",
+ "dns",
+ "ssl",
+] as const;
diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts
new file mode 100644
index 000000000..e887dea05
--- /dev/null
+++ b/packages/utils/src/index.ts
@@ -0,0 +1,26 @@
+export { assertSafeUrl, assertSafeUrlSync, safeUrlSchema } from "./ssrf";
+export {
+ httpPayloadSchema,
+ type HttpPayload,
+ tpcPayloadSchema,
+ type TcpPayload,
+ DNSPayloadSchema,
+ type DNSPayload,
+} from "./payloads";
+export {
+ MONITOR_METHODS,
+ MONITOR_STATUSES,
+ MONITOR_JOB_TYPES,
+} from "./constants";
+
+export function transformHeaders(headers: { key: string; value: string }[]) {
+ return headers.length > 0
+ ? headers.reduce(
+ (acc, curr) => {
+ acc[curr.key] = curr.value;
+ return acc;
+ },
+ {} as Record<string, string>,
+ )
+ : {};
+}
diff --git a/packages/utils/index.ts b/packages/utils/src/payloads.ts
similarity index 79%
rename from packages/utils/index.ts
rename to packages/utils/src/payloads.ts
index 67d8d6214..6936f2727 100644
--- a/packages/utils/index.ts
+++ b/packages/utils/src/payloads.ts
@@ -1,17 +1,17 @@
import { base } from "@openstatus/assertions";
-import { monitorMethods, monitorStatus } from "@openstatus/db/src/schema";
+import { MONITOR_METHODS, MONITOR_STATUSES } from "./constants";
import { z } from "zod";
export const httpPayloadSchema = z.object({
workspaceId: z.string(),
monitorId: z.string(),
- method: z.enum(monitorMethods),
+ method: z.enum(MONITOR_METHODS),
body: z.string().optional(),
headers: z.array(z.object({ key: z.string(), value: z.string() })).optional(),
url: z.string(),
cronTimestamp: z.number(),
- status: z.enum(monitorStatus),
+ status: z.enum(MONITOR_STATUSES),
assertions: z.array(base).nullable(),
timeout: z.number().prefault(45000),
degradedAfter: z.number().nullable(),
@@ -29,7 +29,7 @@ export const httpPayloadSchema = z.object({
export type HttpPayload = z.infer<typeof httpPayloadSchema>;
export const tpcPayloadSchema = z.object({
- status: z.enum(monitorStatus),
+ status: z.enum(MONITOR_STATUSES),
workspaceId: z.string(),
uri: z.string(),
monitorId: z.string(),
@@ -50,7 +50,7 @@ export const tpcPayloadSchema = z.object({
export type TcpPayload = z.infer<typeof tpcPayloadSchema>;
export const DNSPayloadSchema = z.object({
- status: z.enum(monitorStatus),
+ status: z.enum(MONITOR_STATUSES),
workspaceId: z.string(),
uri: z.string(),
monitorId: z.string(),
@@ -69,15 +69,3 @@ export const DNSPayloadSchema = z.object({
});
export type DNSPayload = z.infer<typeof DNSPayloadSchema>;
-
-export function transformHeaders(headers: { key: string; value: string }[]) {
- return headers.length > 0
- ? headers.reduce(
- (acc, curr) => {
- acc[curr.key] = curr.value;
- return acc;
- },
- {} as Record<string, string>,
- )
- : {};
-}
diff --git a/packages/utils/src/ssrf.test.ts b/packages/utils/src/ssrf.test.ts
new file mode 100644
index 000000000..2f0e56213
--- /dev/null
+++ b/packages/utils/src/ssrf.test.ts
@@ -0,0 +1,214 @@
+import { describe, expect, it } from "bun:test";
+import { assertSafeUrl, assertSafeUrlSync, safeUrlSchema } from "./ssrf";
+
+// --- assertSafeUrlSync (no DNS, used in Zod schemas) ---
+
+describe("assertSafeUrlSync", () => {
+ describe("allows valid public URLs", () => {
+ const allowed = [
+ "https://hooks.slack.com/services/T00/B00/xxx",
+ "https://discord.com/api/webhooks/123/abc",
+ "https://chat.googleapis.com/v1/spaces/xxx",
+ "https://ntfy.sh/my-topic",
+ "https://example.com/webhook",
+ "http://example.com/webhook",
+ "https://172.32.0.1/webhook", // 172.32 is NOT private (only 172.16-31)
+ "https://172.15.255.255/webhook", // 172.15 is NOT private
+ ];
+
+ for (const url of allowed) {
+ it(`allows ${url}`, () => {
+ expect(() => assertSafeUrlSync(url)).not.toThrow();
+ });
+ }
+ });
+
+ describe("blocks non-HTTP protocols", () => {
+ const blocked = [
+ "ftp://example.com/file",
+ "file:///etc/passwd",
+ "gopher://evil.com/",
+ "javascript:alert(1)",
+ "data:text/html,<h1>hi</h1>",
+ ];
+
+ for (const url of blocked) {
+ it(`blocks ${url}`, () => {
+ expect(() => assertSafeUrlSync(url)).toThrow("not allowed");
+ });
+ }
+ });
+
+ describe("blocks private IPv4 addresses", () => {
+ const blocked = [
+ "http://127.0.0.1/",
+ "http://127.0.0.1:8080/test",
+ "http://10.0.0.1/",
+ "http://10.255.255.255/",
+ "http://172.16.0.1/",
+ "http://172.31.255.255/",
+ "http://192.168.0.1/",
+ "http://192.168.1.100:3000/",
+ "http://169.254.169.254/latest/meta-data/", // AWS metadata
+ "http://0.0.0.0/",
+ ];
+
+ for (const url of blocked) {
+ it(`blocks ${url}`, () => {
+ expect(() => assertSafeUrlSync(url)).toThrow("not allowed");
+ });
+ }
+ });
+
+ describe("blocks private hostnames", () => {
+ const blocked = [
+ "http://localhost/",
+ "http://localhost:8080/test",
+ "http://LOCALHOST/", // case insensitive
+ "http://metadata.google.internal/computeMetadata/v1/",
+ "http://metadata.internal/",
+ ];
+
+ for (const url of blocked) {
+ it(`blocks ${url}`, () => {
+ expect(() => assertSafeUrlSync(url)).toThrow("not allowed");
+ });
+ }
+ });
+
+ describe("blocks IPv6 private addresses", () => {
+ const blocked = [
+ "http://[::1]/", // loopback
+ "http://[::1]:8080/",
+ "http://[fc00::1]/", // unique local
+ "http://[fd12:3456::1]/", // unique local
+ "http://[fe80::1]/", // link-local
+ ];
+
+ for (const url of blocked) {
+ it(`blocks ${url}`, () => {
+ expect(() => assertSafeUrlSync(url)).toThrow("not allowed");
+ });
+ }
+ });
+
+ describe("blocks IPv4-mapped IPv6 addresses", () => {
+ it("blocks ::ffff:127.0.0.1 (dotted-quad form)", () => {
+ expect(() => assertSafeUrlSync("http://[::ffff:127.0.0.1]/")).toThrow(
+ "not allowed",
+ );
+ });
+
+ it("blocks ::ffff:7f00:1 (hex form, Node URL parser output)", () => {
+ // Node converts ::ffff:127.0.0.1 to ::ffff:7f00:1
+ expect(() => assertSafeUrlSync("http://[::ffff:7f00:1]/")).toThrow(
+ "not allowed",
+ );
+ });
+
+ it("blocks ::ffff:a9fe:a9fe (169.254.169.254 AWS metadata in hex)", () => {
+ expect(() => assertSafeUrlSync("http://[::ffff:a9fe:a9fe]/")).toThrow(
+ "not allowed",
+ );
+ });
+
+ it("blocks ::ffff:a00:1 (10.0.0.1 in hex)", () => {
+ expect(() => assertSafeUrlSync("http://[::ffff:a00:1]/")).toThrow(
+ "not allowed",
+ );
+ });
+
+ it("blocks ::ffff:c0a8:1 (192.168.0.1 in hex)", () => {
+ expect(() => assertSafeUrlSync("http://[::ffff:c0a8:1]/")).toThrow(
+ "not allowed",
+ );
+ });
+ });
+
+ describe("rejects invalid URLs", () => {
+ it("throws on empty string", () => {
+ expect(() => assertSafeUrlSync("")).toThrow();
+ });
+
+ it("throws on garbage", () => {
+ expect(() => assertSafeUrlSync("not-a-url")).toThrow();
+ });
+ });
+});
+
+// --- assertSafeUrl (async, with DNS resolution) ---
+
+describe("assertSafeUrl", () => {
+ it("allows a valid public URL", async () => {
+ await expect(
+ assertSafeUrl("https://example.com/webhook"),
+ ).resolves.toBeUndefined();
+ });
+
+ it("blocks localhost", async () => {
+ await expect(assertSafeUrl("http://localhost/")).rejects.toThrow(
+ "not allowed",
+ );
+ });
+
+ it("blocks private IPs", async () => {
+ await expect(assertSafeUrl("http://192.168.1.1/")).rejects.toThrow(
+ "not allowed",
+ );
+ });
+
+ it("blocks non-HTTP protocols", async () => {
+ await expect(assertSafeUrl("ftp://example.com/")).rejects.toThrow(
+ "not allowed",
+ );
+ });
+
+ it("blocks AWS metadata endpoint", async () => {
+ await expect(
+ assertSafeUrl("http://169.254.169.254/latest/meta-data/"),
+ ).rejects.toThrow("not allowed");
+ });
+});
+
+// --- safeUrlSchema (Zod schema) ---
+
+describe("safeUrlSchema", () => {
+ it("accepts valid public URLs", () => {
+ const result = safeUrlSchema.safeParse(
+ "https://hooks.slack.com/services/T00/B00/xxx",
+ );
+ expect(result.success).toBe(true);
+ });
+
+ it("rejects non-URL strings", () => {
+ const result = safeUrlSchema.safeParse("not-a-url");
+ expect(result.success).toBe(false);
+ });
+
+ it("rejects private IPs", () => {
+ const result = safeUrlSchema.safeParse("http://127.0.0.1/");
+ expect(result.success).toBe(false);
+ });
+
+ it("rejects localhost", () => {
+ const result = safeUrlSchema.safeParse("http://localhost:8080/");
+ expect(result.success).toBe(false);
+ });
+
+ it("rejects metadata endpoint", () => {
+ const result = safeUrlSchema.safeParse(
+ "http://169.254.169.254/latest/meta-data/",
+ );
+ expect(result.success).toBe(false);
+ });
+
+ it("rejects ftp protocol", () => {
+ const result = safeUrlSchema.safeParse("ftp://example.com/file");
+ expect(result.success).toBe(false);
+ });
+
+ it("rejects IPv4-mapped IPv6 in hex form", () => {
+ const result = safeUrlSchema.safeParse("http://[::ffff:7f00:1]/");
+ expect(result.success).toBe(false);
+ });
+});
diff --git a/packages/utils/src/ssrf.ts b/packages/utils/src/ssrf.ts
new file mode 100644
index 000000000..ae84e4eff
--- /dev/null
+++ b/packages/utils/src/ssrf.ts
@@ -0,0 +1,151 @@
+import { z } from "zod";
+
+// --- SSRF Protection ---
+
+const BLOCKED_IPV4_RANGES = [
+ // Loopback
+ { prefix: "127.", mask: null },
+ // Link-local
+ { prefix: "169.254.", mask: null },
+ // Private 10.x.x.x
+ { prefix: "10.", mask: null },
+ // Private 172.16.0.0 - 172.31.255.255
+ {
+ prefix: "172.",
+ mask: (ip: string) => {
+ const second = Number.parseInt(ip.split(".")[1] ?? "", 10);
+ return second >= 16 && second <= 31;
+ },
+ },
+ // Private 192.168.x.x
+ { prefix: "192.168.", mask: null },
+ // Current network
+ { prefix: "0.", mask: null },
+];
+
+const BLOCKED_HOSTNAMES = new Set([
+ "localhost",
+ "metadata.google.internal",
+ "metadata.internal",
+]);
+
+function isBlockedIPv4(ip: string): boolean {
+ for (const range of BLOCKED_IPV4_RANGES) {
+ if (ip.startsWith(range.prefix)) {
+ if (range.mask === null || range.mask(ip)) return true;
+ }
+ }
+ return false;
+}
+
+function isBlockedIPv6(ip: string): boolean {
+ const normalized = ip.toLowerCase();
+ if (normalized === "::1" || normalized === "::") return true;
+ // Unique local addresses (fc00::/7)
+ if (normalized.startsWith("fc") || normalized.startsWith("fd")) return true;
+ // Link-local (fe80::/10)
+ if (normalized.startsWith("fe80")) return true;
+ // IPv4-mapped IPv6 addresses
+ // Node's URL parser converts ::ffff:127.0.0.1 to ::ffff:7f00:1 (hex form)
+ // Handle both dotted-quad (::ffff:127.0.0.1) and hex (::ffff:7f00:1) forms
+ if (normalized.startsWith("::ffff:")) {
+ const mappedPart = normalized.slice(7);
+ // Dotted-quad form
+ if (isBlockedIPv4(mappedPart)) return true;
+ // Hex form — parse back to IPv4 dotted-quad
+ const hexParts = mappedPart.split(":");
+ if (hexParts.length === 2) {
+ const high = Number.parseInt(hexParts[0] ?? "0", 16);
+ const low = Number.parseInt(hexParts[1] ?? "0", 16);
+ if (!Number.isNaN(high) && !Number.isNaN(low)) {
+ const ipv4 = `${(high >> 8) & 0xff}.${high & 0xff}.${(low >> 8) & 0xff}.${low & 0xff}`;
+ if (isBlockedIPv4(ipv4)) return true;
+ }
+ }
+ }
+ return false;
+}
+
+function isBlockedHost(hostname: string): boolean {
+ const lower = hostname.toLowerCase();
+ if (BLOCKED_HOSTNAMES.has(lower)) return true;
+
+ // Check if hostname is a raw IP address
+ if (/^\d{1,3}(\.\d{1,3}){3}$/.test(lower)) {
+ return isBlockedIPv4(lower);
+ }
+ if (lower.startsWith("[") && lower.endsWith("]")) {
+ return isBlockedIPv6(lower.slice(1, -1));
+ }
+
+ return false;
+}
+
+/**
+ * Validates that a URL is safe to fetch (not targeting internal/private infrastructure).
+ * Checks protocol, hostname, and resolved IP address.
+ * Throws an error if the URL is not safe.
+ */
+export async function assertSafeUrl(urlString: string): Promise<void> {
+ let parsed: URL;
+ try {
+ parsed = new URL(urlString);
+ } catch {
+ throw new Error("Invalid URL");
+ }
+
+ // Only allow HTTP(S)
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
+ throw new Error(
+ `URL protocol "${parsed.protocol}" is not allowed. Only http: and https: are permitted.`,
+ );
+ }
+
+ // Block known dangerous hostnames and raw private IPs
+ if (isBlockedHost(parsed.hostname)) {
+ throw new Error(
+ "URL targets a private or internal address, which is not allowed.",
+ );
+ }
+}
+
+/**
+ * Synchronous URL safety check for use in Zod schemas.
+ * Checks protocol and hostname/IP without DNS resolution.
+ */
+export function assertSafeUrlSync(urlString: string): void {
+ let parsed: URL;
+ try {
+ parsed = new URL(urlString);
+ } catch {
+ throw new Error("Invalid URL");
+ }
+
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
+ throw new Error(
+ `URL protocol "${parsed.protocol}" is not allowed. Only http: and https: are permitted.`,
+ );
+ }
+
+ if (isBlockedHost(parsed.hostname)) {
+ throw new Error(
+ "URL targets a private or internal address, which is not allowed.",
+ );
+ }
+}
+
+/**
+ * Zod schema for URLs that are safe from SSRF.
+ * Validates format and blocks private/internal addresses.
+ */
+export const safeUrlSchema = z.url({ protocol: /^https?$/ }).refine(
+ (val) => {
+ try {
+ assertSafeUrlSync(val);
+ return true;
+ } catch {
+ return false;
+ }
+ },
+ { message: "URL must not target private or internal addresses" },
+);
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index c8662ef59..947c108a6 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1365,6 +1365,9 @@ importers:
'@openstatus/theme-store':
specifier: workspace:*
version: link:../theme-store
+ '@openstatus/utils':
+ specifier: workspace:*
+ version: link:../utils
'@t3-oss/env-core':
specifier: 0.13.10
@@ -1539,6 +1542,9 @@ importers:
'@openstatus/notification-base':
specifier: workspace:*
version: link:../base
+ '@openstatus/utils':
+ specifier: workspace:*
+ version: link:../../utils
zod:
specifier: 4.1.13
version: 4.1.13
@@ -1619,6 +1625,9 @@ importers:
'@openstatus/notification-base':
specifier: workspace:*
version: link:../base
+ '@openstatus/utils':
+ specifier: workspace:*
+ version: link:../../utils
zod:
specifier: 4.1.13
version: 4.1.13
@@ -1644,6 +1653,9 @@ importers:
'@openstatus/notification-base':
specifier: workspace:*
version: link:../base
+ '@openstatus/utils':
+ specifier: workspace:*
+ version: link:../../utils
zod:
specifier: 4.1.13
version: 4.1.13
@@ -1669,6 +1681,9 @@ importers:
'@openstatus/notification-base':
specifier: workspace:*
version: link:../base
+ '@openstatus/utils':
+ specifier: workspace:*
+ version: link:../../utils
zod:
specifier: 4.1.13
version: 4.1.13
@@ -1774,6 +1789,9 @@ importers:
'@openstatus/notification-base':
specifier: workspace:*
version: link:../base
+ '@openstatus/utils':
+ specifier: workspace:*
+ version: link:../../utils
zod:
specifier: 4.1.13
version: 4.1.13
@@ -1999,6 +2017,9 @@ importers:
'@openstatus/emails':
specifier: workspace:*
version: link:../emails
+ '@openstatus/utils':
+ specifier: workspace:*
+ version: link:../utils
zod:
specifier: 4.1.13
version: 4.1.13
@@ -2264,9 +2285,6 @@ importers:
'@openstatus/assertions':
specifier: workspace:*
version: link:../assertions
- '@openstatus/db':
- specifier: workspace:*
- version: link:../db
'@openstatus/regions':
specifier: workspace:*
version: link:../regions