The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
rename Dub.co bot
Steven Teyd6768425e4f5
diff --git a/apps/web/app/api/edge/metatags/utils.ts b/apps/web/app/api/edge/metatags/utils.tsindex c80aa91fbb..9657a1337d 100644--- a/apps/web/app/api/edge/metatags/utils.ts+++ b/apps/web/app/api/edge/metatags/utils.ts@@ -7,7 +7,7 @@ import { internal_runWithWaitUntil as waitUntil } from "next/dist/server/web/intexport const getHtml = async (url: string) => {return await fetchWithTimeout(url, {headers: {- "User-Agent": "dub-bot/1.0",+ "User-Agent": "Dub.co Bot",},}).then((r) => r.text())diff --git a/apps/web/lib/api/links.ts b/apps/web/lib/api/links.tsindex 6cad7e1451..551e3c7016 100644--- a/apps/web/lib/api/links.ts+++ b/apps/web/lib/api/links.ts@@ -14,13 +14,13 @@ import {getParamsFromURL,getUrlFromString,isDubDomain,+ isIframeable,linkConstructor,nanoid,truncate,validKeyRegex,} from "@dub/utils";import cloudinary from "cloudinary";-import { isIframeable } from "../middleware/utils";import { LinkProps, ProjectProps } from "../types";import { Session } from "../auth";import { getLinkViaEdge } from "../planetscale";diff --git a/apps/web/lib/middleware/utils.ts b/apps/web/lib/middleware/utils.tsindex 5c030286d9..dfe736afe9 100644--- a/apps/web/lib/middleware/utils.ts+++ b/apps/web/lib/middleware/utils.ts@@ -64,45 +64,3 @@ export const detectBot = (req: NextRequest) => {}return false;};--// check if a link can be displayed in an iframe-export const isIframeable = async ({- url,- requestDomain,-}: {- url: string;- requestDomain: string;-}) => {- const res = await fetch(url, {- headers: {- "User-Agent": "dub-bot/1.0",- },- });-- // if the request throws a status that's not 200, then it's not iframeable- if (!res.ok) {- return false;- }-- const xFrameOptions = res.headers.get("X-Frame-Options"); // returns null if there is no `X-Frame-Options` header- if (xFrameOptions) {- return false;- }-- const cspHeader = res.headers.get("content-security-policy");- if (!cspHeader) {- return true;- }-- const frameAncestorsMatch = cspHeader.match(- /frame-ancestors\s+([\s\S]+?)(?=;|$)/i,- );- if (frameAncestorsMatch) {- const allowedOrigins = frameAncestorsMatch[1].split(/\s+/);- if (allowedOrigins.includes(requestDomain)) {- return true;- }- }-- return false;-};diff --git a/packages/utils/src/functions/index.ts b/packages/utils/src/functions/index.tsindex aff360c3ed..a866b92bff 100644--- a/packages/utils/src/functions/index.ts+++ b/packages/utils/src/functions/index.ts@@ -8,6 +8,7 @@ export * from "./domains";export * from "./fetch-with-timeout";export * from "./fetcher";export * from "./hash";+export * from "./is-iframeable";export * from "./link-constructor";export * from "./log";export * from "./misc";diff --git a/packages/utils/src/functions/is-iframeable.ts b/packages/utils/src/functions/is-iframeable.tsnew file mode 100644index 0000000000..c034958233--- /dev/null+++ b/packages/utils/src/functions/is-iframeable.ts@@ -0,0 +1,41 @@+// check if a link can be displayed in an iframe+export const isIframeable = async ({+ url,+ requestDomain,+}: {+ url: string;+ requestDomain: string;+}) => {+ const res = await fetch(url, {+ headers: {+ "User-Agent": "Dub.co Bot",+ },+ });++ // if the request throws a status that's not 200, then it's not iframeable+ if (!res.ok) {+ return false;+ }++ const xFrameOptions = res.headers.get("X-Frame-Options"); // returns null if there is no `X-Frame-Options` header+ if (xFrameOptions) {+ return false;+ }++ const cspHeader = res.headers.get("content-security-policy");+ if (!cspHeader) {+ return true;+ }++ const frameAncestorsMatch = cspHeader.match(+ /frame-ancestors\s+([\s\S]+?)(?=;|$)/i,+ );+ if (frameAncestorsMatch) {+ const allowedOrigins = frameAncestorsMatch[1].split(/\s+/);+ if (allowedOrigins.includes(requestDomain)) {+ return true;+ }+ }++ return false;+};