Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Keep the isIframeable API in @dub/utils

Rafi03b8d87b9d2b
diff --git a/apps/web/app/api/links/iframeable/route.ts b/apps/web/app/api/links/iframeable/route.ts
index 71202c24c9..620db032c7 100644
--- a/apps/web/app/api/links/iframeable/route.ts
+++ b/apps/web/app/api/links/iframeable/route.ts
@@ -5,7 +5,7 @@ import {
getDomainQuerySchema,
getUrlQuerySchema,
} from "@/lib/zod/schemas/links";
-import { getSearchParams, isIframeable } from "@dub/utils";
+import { getSearchParams, isIframeableFromHeaders } from "@dub/utils";
import { NextRequest, NextResponse } from "next/server";
export const runtime = "edge";
@@ -19,7 +19,7 @@ export async function GET(req: NextRequest) {
await ratelimitOrThrow(req, "iframeable");
const res = await safeFetch(url);
- const iframeable = isIframeable({
+ const iframeable = isIframeableFromHeaders({
headers: res.headers,
requestDomain: domain,
});
diff --git a/packages/utils/src/functions/is-iframeable.ts b/packages/utils/src/functions/is-iframeable.ts
index 836d51c43e..9c06876f07 100644
--- a/packages/utils/src/functions/is-iframeable.ts
+++ b/packages/utils/src/functions/is-iframeable.ts
@@ -1,7 +1,7 @@
// Determine whether a fetched page can be displayed in an iframe by the
// requesting domain, given the response's CSP / X-Frame-Options headers.
// The caller is responsible for fetching the URL (use an SSRF-safe fetcher).
-export const isIframeable = ({
+export const isIframeableFromHeaders = ({
headers,
requestDomain,
}: {
@@ -37,3 +37,20 @@ export const isIframeable = ({
return true;
};
+
+/**
+ * Fetches `url` and checks whether it can be displayed in an iframe.
+ *
+ * @deprecated This fetches `url` with no SSRF guards. Fetch the URL with an
+ * SSRF-safe fetcher and pass the response headers to `isIframeableFromHeaders`.
+ */
+export const isIframeable = async ({
+ url,
+ requestDomain,
+}: {
+ url: string;
+ requestDomain: string;
+}) => {
+ const res = await fetch(url);
+ return isIframeableFromHeaders({ headers: res.headers, requestDomain });
+};