The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add `typesafe/jev` link scanner (#4528)
Steven Teya8db3fdd1a3e
diff --git a/apps/web/.env.example b/apps/web/.env.exampleindex c8b378c39e..c3ac59d0bc 100644--- a/apps/web/.env.example+++ b/apps/web/.env.example@@ -129,6 +129,7 @@ DUB_SLACK_ASSISTANT_BOT_TOKEN=NEXT_PUBLIC_NGROK_URL=# For AI features+AI_GATEWAY_API_KEY=ANTHROPIC_API_KEY=# Axiom – used for logging and monitoringdiff --git a/apps/web/lib/api/links/malicious-link-check.ts b/apps/web/lib/api/links/malicious-link-check.tsnew file mode 100644index 0000000000..80bba2a9b7--- /dev/null+++ b/apps/web/lib/api/links/malicious-link-check.ts@@ -0,0 +1,86 @@+import { isBlacklistedDomain, updateConfig } from "@/lib/edge-config";+import { getDomainWithoutWWW } from "@dub/utils";+import { waitUntil } from "@vercel/functions";+import { experimental_evaluate as evaluate } from "ai";++export async function maliciousLinkCheck(url: string) {+ const domain = getDomainWithoutWWW(url);++ if (!domain) {+ return false;+ }++ const domainBlacklisted = await isBlacklistedDomain(domain);+ if (domainBlacklisted) {+ return true;+ }++ // run jev check+ try {+ const result = await evaluate({+ model: "typesafe-ai/jev",+ state: { url, domain },+ questions: {+ isMalicious: {+ type: "boolean",+ instructions:+ "Is this destination abusive to publish as a public short link?",+ criteria: {+ true: {+ meaning:+ "Yes if the URL is meant to deceive, steal credentials or funds, deliver malware, or is a category we refuse to shorten. One strong match is enough.",+ matches_any: [+ "Phishing or brand impersonation: login, verify, KYC, billing, shipping, wallet-connect, or support pages mimicking banks/utilities, marketplaces, crypto, Microsoft/Google/Adobe/Apple, carriers, government, or Roblox — including typosquats, hyphenated lookalikes, and extra-TLD hosts like brand.com.evil.tld.",+ "Those same lures on throwaway hosting (Vercel, Netlify, Weebly, Blogspot, Surge, Firebase, serveo, Cloudflare, DuckDNS, Azure blobs, Heroku, tiiny.site, IPFS, AWS lambda URLs, Google Sites, Microsoft Forms).",+ "Another URL shortener, cloaking/redirector, or QR-code hop (nested shortening).",+ "Adult, porn, cam, or dating-spam sites.",+ "Online gambling, betting, slots, or pirate IPTV/streaming.",+ "Malware, fake downloads/updates, scareware, or crypto drainers.",+ "Gibberish, keyboard-smash, punycode/IDN homograph, raw-IP, or random smashed-dictionary domains used for cloaking (yhujykujujk.xyz, concealmentbroad.com).",+ ],+ },+ false: {+ meaning:+ "No if this is a normal site someone would reasonably shorten.",+ even_if: [+ "It has a real login or checkout on the organization's own official domain.",+ "It is a legitimate app on Vercel/Netlify/GitHub Pages with no impersonation signals.",+ "The brand is unfamiliar or new, as long as the name is coherent and not a lookalike, shortener, or gibberish domain.",+ ],+ },+ },+ },+ },+ providerOptions: {+ gateway: {+ zeroDataRetention: true,+ },+ },+ });++ const maliciousProbability = result.answers.isMalicious.probability;++ console.log("typesafe/jev check results:");+ console.log({+ url,+ domain,+ probability: maliciousProbability,+ isMalicious: maliciousProbability > 0.5,+ });++ // if high probability, add to blacklist+ if (maliciousProbability > 0.8) {+ waitUntil(+ updateConfig({+ key: "domains",+ value: domain,+ }),+ );+ }++ return maliciousProbability > 0.5;+ } catch (error) {+ console.error("typesafe/jev check error:", error);+ return false;+ }+}diff --git a/apps/web/lib/api/links/process-link.ts b/apps/web/lib/api/links/process-link.tsindex 9847aaee65..6589be02c0 100644--- a/apps/web/lib/api/links/process-link.ts+++ b/apps/web/lib/api/links/process-link.ts@@ -1,4 +1,3 @@-import { isBlacklistedDomain } from "@/lib/edge-config";import { verifyFolderAccess } from "@/lib/folder/permissions";import { checkIfUserExists, getRandomKey } from "@/lib/planetscale";import { prisma } from "@/lib/prisma";@@ -18,6 +17,7 @@ import {} from "@dub/utils";import { Project, WorkspaceRole } from "@prisma/client";import { combineTagIds } from "../tags/combine-tag-ids";+import { maliciousLinkCheck } from "./malicious-link-check";import {businessFeaturesCheck,dubLinkSubdomainCheck,@@ -601,23 +601,3 @@ export async function processLink<T extends Record<string, any>>({error: null,};}--async function maliciousLinkCheck(url: string) {- // flag for suspicious URL strings- if (["?key=", "&key="].some((param) => url.includes(param))) {- return true;- }-- const domain = getDomainWithoutWWW(url);-- if (!domain) {- return false;- }-- const domainBlacklisted = await isBlacklistedDomain(domain);- if (domainBlacklisted === true) {- return true;- }-- return false;-}diff --git a/apps/web/package.json b/apps/web/package.jsonindex d6892612b2..15641f2e4d 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -20,8 +20,8 @@},"dependencies": {"@ai-sdk/anthropic": "^3.0.1",- "@ai-sdk/react": "^3.0.3",- "@ai-sdk/rsc": "^2.0.3",+ "@ai-sdk/react": "^4.0.110",+ "@ai-sdk/rsc": "^3.0.107","@axiomhq/js": "^1.3.1","@axiomhq/logging": "^0.1.5","@axiomhq/nextjs": "^0.1.6",@@ -76,7 +76,7 @@"@visx/scale": "^3.3.0","@visx/shape": "^2.12.2","@visx/text": "^3.3.0",- "ai": "^6.0.3",+ "ai": "^7.0.107","aws4fetch": "^1.0.19","base-x": "^5.0.0","bcryptjs": "^2.4.3",diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 91b9ef4808..4f8c907c64 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -39,11 +39,11 @@ importers:specifier: ^3.0.1version: 3.0.1([email protected])'@ai-sdk/react':- specifier: ^3.0.3- version: 3.0.3([email protected])([email protected])+ specifier: ^4.0.110+ version: 4.0.110([email protected])([email protected])'@ai-sdk/rsc':- specifier: ^2.0.3- version: 2.0.3([email protected])([email protected])+ specifier: ^3.0.107+ version: 3.0.107([email protected])([email protected])'@axiomhq/js':specifier: ^1.3.1version: 1.3.1@@ -207,8 +207,8 @@ importers:specifier: ^3.3.0version: 3.3.0([email protected])ai:- specifier: ^6.0.3- version: 6.0.3([email protected])+ specifier: ^7.0.107+ version: 7.0.107([email protected])aws4fetch:specifier: ^1.0.19version: 1.0.19@@ -1029,9 +1029,15 @@ packages:peerDependencies:zod: ^3.25.76 || ^4.1.8- '@ai-sdk/[email protected]':- resolution: {integrity: sha512-giJEg9ob45htbu3iautK+2kvplY2JnTj7ir4wZzYSQWvqGatWfBBfDuNCU5wSJt9BCGjymM5ZS9ziD42JGCZBw==}- engines: {node: '>=18'}+ '@ai-sdk/[email protected]':+ resolution: {integrity: sha512-6wJmX/D5OO7tvDJbtFdXdBuRt8AkCnW+FLK+W35UHe/tHgolAa4hclXtJcMSYnlTDy/t5DNRgdesVaoMXtwzow==}+ engines: {node: '>=22'}+ peerDependencies:+ zod: ^3.25.76 || ^4.1.8++ '@ai-sdk/[email protected]':+ resolution: {integrity: sha512-Q9o7KCyPNRrC7VhBtbnZh2OiApNbFhsNupjDQLW6P/y3xV6l9HES2KWeu0905T9IH6HurN6ckJwRXE0PnLL7Mg==}+ engines: {node: '>=22'}peerDependencies:zod: ^3.25.76 || ^4.1.8@@ -1041,19 +1047,29 @@ packages:peerDependencies:zod: ^3.25.76 || ^4.1.8+ '@ai-sdk/[email protected]':+ resolution: {integrity: sha512-gLuaCups8OCIRz3eO6WWz5op7VLYNNtFzyH0sWUr0FE9v7cTxR0qxDpQdrKnGcql+9WWttobjnZsJVsuEbsPQQ==}+ engines: {node: '>=22'}+ peerDependencies:+ zod: ^3.25.76 || ^4.1.8+'@ai-sdk/[email protected]':resolution: {integrity: sha512-m9ka3ptkPQbaHHZHqDXDF9C9B5/Mav0KTdky1k2HZ3/nrW2t1AgObxIVPyGDWQNS9FXT/FS6PIoSjpcP/No8rQ==}engines: {node: '>=18'}- '@ai-sdk/[email protected]':- resolution: {integrity: sha512-mLIgQuBdIX9gxCYQN3Pv/J8ARoFreIKYr/TVQtI+FwEzejuGFimTyhDln7UIBfrnm3Mpn1xENIWZfDfCRF7wkw==}- engines: {node: '>=18'}+ '@ai-sdk/[email protected]':+ resolution: {integrity: sha512-VYMBxIQdcHqbIf1j+YZlI9Ati6LZ4wJe0GGd4z4a5H/KxTggjeOiyaVYTnfF7LHZK5jMQ+rofmzz4QPqf++NUw==}+ engines: {node: '>=22'}++ '@ai-sdk/[email protected]':+ resolution: {integrity: sha512-5WSYzAwdnECdDekICJjj2e83793YYNAcTk8yAEvt/sxme1NXTE3OWr3QLSJPjkyOaa6XAmJ6iE/R9l+2YvcI3Q==}+ engines: {node: '>=22'}peerDependencies:react: ^18 || ~19.0.1 || ~19.1.2 || ^19.2.1- '@ai-sdk/[email protected]':- resolution: {integrity: sha512-1+kZs8+Xkdv/0IuOB98lskb9nEwVufvk+sgMQKFXMgFTMm8gvItFQxiiqfPfcFBHTRgXHOVtb/4KOqdTfLqMnQ==}- engines: {node: '>=18'}+ '@ai-sdk/[email protected]':+ resolution: {integrity: sha512-x8JgLYzKXM0Ql2nSV4rW+4fbCSROlQm8ut+VU1noP4ILv6j27dz8JlWmwKYyhofDyno8kxwKmgHNijeP9Crapg==}+ engines: {node: '>=22'}peerDependencies:react: ^18 || ~19.0.1 || ~19.1.2 || ^19.2.1zod: ^3.25.76 || ^4.1.8@@ -6083,10 +6099,6 @@ packages:resolution: {integrity: sha512-GFXtgid3+TcVHTd668a10vGpzAh4Ty/yBZPRxKf1UicI8Vi8EthfvSxcaLW0KvQBBe1+d7TcjecLZHRT8JzQ4g==}engines: {node: '>=16'}- '@vercel/[email protected]':- resolution: {integrity: sha512-fnYhv671l+eTTp48gB4zEsTW/YtRgRPnkI2nT7x6qw5rkI1Lq2hTmQIpHPgyThI0znLK+vX2n9XxKdXZ7BUbbw==}- engines: {node: '>= 20'}-'@vercel/[email protected]':resolution: {integrity: sha512-UycprH3T6n3jH0k44NHMa7pnFHGu/N05MjojYr+Mc6I7obkoLIJujSWwin1pCvdy/eOxrI/l3uDLQsmcrOb4ug==}engines: {node: '>= 20'}@@ -6235,6 +6247,9 @@ packages:'@vitest/[email protected]':resolution: {integrity: sha512-pdk2phO5NDvEFfUTxcTP8RFYjVj/kfLSPIN5ebP2Mu9kcIMeAQTbknqcFEyBcC4z2pJlJI9aS5UQjcYfhmKAow==}+ '@workflow/[email protected]':+ resolution: {integrity: sha512-pav4F2BoirECWR7Nf1TKt+2eETcBj7jj4cBefQ8VXQCA6NPkaKeLfj/zMgi+3zYV5ZIBT4GuUiphsj0/b9hPQQ==}+'@xmldom/[email protected]':resolution: {integrity: sha512-CJDxIgE5I0FH+ttq/Fxy6nRpxP70+e2O048EPe85J2use3XKdatVM7dDVvFNjQudd9B49NPoZ+8PG49zj4Er8Q==}engines: {node: '>= 16'}@@ -6329,9 +6344,9 @@ packages:resolution: {integrity: sha512-4I7Td01quW/RpocfNayFdFVk1qSuoh0E7JrbRJ16nH01HhKFQ88INq9Sd+nd72zqRySlr9BmDA8xlEJ6vJMrYA==}engines: {node: '>=8'}- resolution: {integrity: sha512-OOo+/C+sEyscoLnbY3w42vjQDICioVNyS+F+ogwq6O5RJL/vgWGuiLzFwuP7oHTeni/MkmX8tIge48GTdaV7QQ==}- engines: {node: '>=18'}+ resolution: {integrity: sha512-PVYQ3W9kR8oYiGQxbg4aFIlhQzKskZm8UV+4E0zB2uKOzFr8ju3bXQncOOZtLsOgJY8vdpgyu3cXtomsfcdQYg==}+ engines: {node: '>=22'}peerDependencies:zod: ^3.25.76 || ^4.1.8@@ -8158,6 +8173,10 @@ packages:resolution: {integrity: sha512-Vo1ab+QXPzZ4tCa8SwIHJFaSzy4R6SHf7BY79rFBDf0idraZWAkYrDjDj8uWaSm3S2TK+hJ7/t1CEmZ7jXw+pg==}engines: {node: '>=18.0.0'}+ resolution: {integrity: sha512-EKN1vKAMcZ8MlYMpaNuxN6R9yakzH6uajHcHVTqWJzvu5pWw9DyhbP35HH8MVBQ+dZjAfDxk+A8NiR9KWaXiyQ==}+ engines: {node: '>=18.0.0'}+resolution: {integrity: sha512-CRT1WTyuQoD771GW56XEZFQ/ZoSfWid1alKGDYMmkt2yl8UXrVR4pspqWNEcqKvVIzg6PAltWjxcSSPrboA4iA==}engines: {node: '>=18.0.0'}@@ -9656,6 +9675,11 @@ packages:engines: {node: ^18.0.0 || >=20.0.0}hasBin: true+ resolution: {integrity: sha512-zE9+AXFq+MkTolDor2Cw1nJzLC0aleqPkYf52Kb4Kn4mJcka/gFHpGI2JBVEJCfWOvBl0OoxZS+wuLdislQcqg==}+ engines: {node: ^18.0.0 || >=20.0.0}+ hasBin: true+resolution: {integrity: sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==}@@ -10926,6 +10950,10 @@ packages:resolution: {integrity: sha512-ueGLflrrnvwB3xuo/uGob5pd5FN7l0MsLf0Z87o/UQmRtwjvfylfc9MurIxRAWywCYTgrvpXBcqjV4OfCYGCIQ==}engines: {node: '>=16.20.0'}+ resolution: {integrity: sha512-wQ0b/W4Fr01qtpHlqSqspcj3EhBvimsdh0KlHhH8HRZnMsEa0ea2fTULOXOS9ccQr3om+GcGRk4e+isrZWV8qQ==}+ engines: {node: '>=16.20.0'}+resolution: {integrity: sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==}engines: {node: '>=8'}@@ -12330,10 +12358,10 @@ packages:peerDependencies:react: ^16.11.0 || ^17.0.0 || ^18.0.0- resolution: {integrity: sha512-QtxqyclFeAsxEUeZIYmsaQ0UjimSq1RZ9Un7I68/0ClKK/U3LoyQunwkQfJZr2fc22DfIXLNDc2wFyTEikCUpg==}+ resolution: {integrity: sha512-BRw55e8r0B7SpDN20CAzoQAHl7y1yP7/Zt7oqUjMv0vSt2u2Xnkm88Ws+VypbV9BXHQVuSuyVq7zMjO16wSExw==}peerDependencies:- react: ^16.11.0 || ^17.0.0 || ^18.0.0+ react: ^16.11.0 || ^17.0.0 || ^18.0.0 || ^19.0.0resolution: {integrity: sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==}@@ -13102,6 +13130,11 @@ packages:peerDependencies:react: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0+ resolution: {integrity: sha512-6L+EeigHMQhdaIPNIFUKwfWJSwWFQ8gJbJ2DLOs5sDIegTwR9fRxvnM3uciHKjIZhFz+KAv2emhWMRvDmMcY8A==}+ peerDependencies:+ react: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0+resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==}@@ -13114,6 +13147,7 @@ packages:resolution: {integrity: sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==}+ deprecated: uuid@10 and below is no longer supported. For ESM codebases, update to uuid@latest. For CommonJS codebases, use uuid@11 (but be aware this version will likely be deprecated in 2028).hasBin: true@@ -13126,15 +13160,17 @@ packages:resolution: {integrity: sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==}- deprecated: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.+ deprecated: uuid@10 and below is no longer supported. For ESM codebases, update to uuid@latest. For CommonJS codebases, use uuid@11 (but be aware this version will likely be deprecated in 2028).hasBin: trueresolution: {integrity: sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==}+ deprecated: uuid@10 and below is no longer supported. For ESM codebases, update to uuid@latest. For CommonJS codebases, use uuid@11 (but be aware this version will likely be deprecated in 2028).hasBin: trueresolution: {integrity: sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==}+ deprecated: uuid@10 and below is no longer supported. For ESM codebases, update to uuid@latest. For CommonJS codebases, use uuid@11 (but be aware this version will likely be deprecated in 2028).hasBin: true@@ -13691,11 +13727,19 @@ snapshots:'@ai-sdk/provider-utils': 4.0.1([email protected])zod: 4.3.5- '@ai-sdk/[email protected]([email protected])':+ '@ai-sdk/[email protected]([email protected])':dependencies:- '@ai-sdk/provider': 3.0.0- '@ai-sdk/provider-utils': 4.0.1([email protected])- '@vercel/oidc': 3.0.5+ '@ai-sdk/provider': 4.0.17+ '@ai-sdk/provider-utils': 5.0.45([email protected])+ '@vercel/oidc': 3.2.0+ zod: 4.3.5++ '@ai-sdk/[email protected]([email protected])':+ dependencies:+ '@ai-sdk/provider': 4.0.17+ '@ai-sdk/provider-utils': 5.0.45([email protected])+ cross-spawn: 7.0.6+ pkce-challenge: 5.0.1zod: 4.3.5'@ai-sdk/[email protected]([email protected])':@@ -13705,26 +13749,41 @@ snapshots:eventsource-parser: 3.0.6zod: 4.3.5+ '@ai-sdk/[email protected]([email protected])':+ dependencies:+ '@ai-sdk/provider': 4.0.17+ '@standard-schema/spec': 1.1.0+ '@workflow/serde': 4.1.0+ eventsource-parser: 3.1.1+ undici: 7.29.0+ zod: 4.3.5+'@ai-sdk/[email protected]':dependencies:json-schema: 0.4.0+ '@ai-sdk/[email protected]':dependencies:- '@ai-sdk/provider-utils': 4.0.1([email protected])- ai: 6.0.3([email protected])+ json-schema: 0.4.0++ dependencies:+ '@ai-sdk/mcp': 2.0.54([email protected])+ '@ai-sdk/provider': 4.0.17+ '@ai-sdk/provider-utils': 5.0.45([email protected])+ ai: 7.0.107([email protected])react: 19.1.3- swr: 2.2.5([email protected])+ swr: 2.5.1([email protected])throttleit: 2.1.0transitivePeerDependencies:- zoddependencies:- '@ai-sdk/provider': 3.0.0- '@ai-sdk/provider-utils': 4.0.1([email protected])- ai: 6.0.3([email protected])- jsondiffpatch: 0.7.3+ '@ai-sdk/provider': 4.0.17+ '@ai-sdk/provider-utils': 5.0.45([email protected])+ ai: 7.0.107([email protected])+ jsondiffpatch: 0.7.6react: 19.1.3optionalDependencies:zod: 4.3.5@@ -19831,8 +19890,6 @@ snapshots:satori: 0.12.1yoga-wasm-web: 0.3.3- '@vercel/[email protected]': {}-'@vercel/[email protected]': {}'@veriff/[email protected]':@@ -20104,6 +20161,8 @@ snapshots:'@vitest/pretty-format': 4.0.8tinyrainbow: 3.0.3+ '@workflow/[email protected]': {}+'@xmldom/[email protected]': {}'@xmldom/[email protected]': {}@@ -20177,12 +20236,11 @@ snapshots:indent-string: 4.0.0optional: truedependencies:- '@ai-sdk/gateway': 3.0.2([email protected])- '@ai-sdk/provider': 3.0.0- '@ai-sdk/provider-utils': 4.0.1([email protected])- '@opentelemetry/api': 1.9.0+ '@ai-sdk/gateway': 4.0.87([email protected])+ '@ai-sdk/provider': 4.0.17+ '@ai-sdk/provider-utils': 5.0.45([email protected])zod: 4.3.5@@ -22335,6 +22393,8 @@ snapshots:+ [email protected]: {}+dependencies:eventsource-parser: 3.0.6@@ -22690,7 +22750,7 @@ snapshots:dependencies:- cross-spawn: 7.0.3+ cross-spawn: 7.0.6signal-exit: 4.1.0@@ -24411,6 +24471,10 @@ snapshots:dependencies:'@dmsnell/diff-match-patch': 1.1.0+ dependencies:+ '@dmsnell/diff-match-patch': 1.1.0+optionalDependencies:graceful-fs: 4.2.11@@ -25881,6 +25945,8 @@ snapshots:optional: true+ [email protected]: {}+dependencies:find-up: 4.1.0@@ -27706,11 +27772,11 @@ snapshots:react: 19.1.3use-sync-external-store: 1.2.0([email protected])dependencies:- client-only: 0.0.1+ dequal: 2.0.3react: 19.1.3- use-sync-external-store: 1.5.0([email protected])+ use-sync-external-store: 1.7.0([email protected])@@ -28748,6 +28814,10 @@ snapshots:dependencies:react: 19.1.3+ dependencies:+ react: 19.1.3+