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.

dub link checks

Steven Tey1ab83bdc01fa
diff --git a/apps/web/app/api/cron/links/event/route.ts b/apps/web/app/api/cron/links/event/route.ts
index 71c499148c..1f85438d5d 100644
--- a/apps/web/app/api/cron/links/event/route.ts
+++ b/apps/web/app/api/cron/links/event/route.ts
@@ -33,21 +33,6 @@ export async function POST(req: Request) {
return new Response("Link not found", { status: 200 });
}
- // if the link is a dub.sh link (and is not a transfer event), do some checks
- if (link.domain === "dub.sh" && type !== "transfer") {
- const invalidFavicon = await fetch(
- `${GOOGLE_FAVICON_URL}${getApexDomain(link.url)}`,
- ).then((res) => !res.ok);
-
- if (invalidFavicon) {
- await log({
- message: `Suspicious link detected: ${link.domain}/${link.key} → ${link.url}`,
- type: "links",
- mention: true,
- });
- }
- }
-
// increment links usage and send alert if needed
if (type === "create" && link.projectId) {
const workspace = await prisma.project.update({
diff --git a/apps/web/lib/api/links/create-link.ts b/apps/web/lib/api/links/create-link.ts
index 535decae11..f2116db54f 100644
--- a/apps/web/lib/api/links/create-link.ts
+++ b/apps/web/lib/api/links/create-link.ts
@@ -11,7 +11,7 @@ import {
truncate,
} from "@dub/utils";
import { Prisma } from "@prisma/client";
-import { combineTagIds } from "./utils";
+import { combineTagIds, dubLinkChecks } from "./utils";
export async function createLink(link: LinkWithTagIdsProps) {
let { key, url, expiresAt, title, description, image, proxy, geo } = link;
@@ -118,6 +118,8 @@ export async function createLink(link: LinkWithTagIdsProps) {
},
},
}),
+ // if the link is a dub.sh link, do some checks
+ link.domain === "dub.sh" && dubLinkChecks(link),
]);
const shortLink = linkConstructor({
diff --git a/apps/web/lib/api/links/utils.ts b/apps/web/lib/api/links/utils.ts
index ddb9e72a37..3b4715ab1e 100644
--- a/apps/web/lib/api/links/utils.ts
+++ b/apps/web/lib/api/links/utils.ts
@@ -1,10 +1,13 @@
import { isReservedKey, isReservedUsername } from "@/lib/edge-config";
import { checkIfKeyExists } from "@/lib/planetscale";
-import { WorkspaceProps } from "@/lib/types";
+import { SimpleLinkProps, WorkspaceProps } from "@/lib/types";
import {
DEFAULT_REDIRECTS,
+ GOOGLE_FAVICON_URL,
SHORT_DOMAIN,
+ getApexDomain,
isDubDomain,
+ log,
validKeyRegex,
} from "@dub/utils";
@@ -99,3 +102,18 @@ export function processKey(key: string) {
return key;
}
+
+export async function dubLinkChecks(link: SimpleLinkProps) {
+ const invalidFavicon = await fetch(
+ `${GOOGLE_FAVICON_URL}${getApexDomain(link.url)}`,
+ ).then((res) => !res.ok);
+
+ if (invalidFavicon) {
+ return await log({
+ message: `Suspicious link detected: ${link.domain}/${link.key} → ${link.url}`,
+ type: "links",
+ mention: true,
+ });
+ }
+ return null;
+}