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.

added blacklisted keys

Steven Tey34098ee91efc
diff --git a/lib/utils.ts b/lib/utils.ts
index edcc454abf..fcd3fd051b 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -341,6 +341,20 @@ export const isBlacklistedDomain = async (domain: string) => {
);
};
+export const getBlacklistedKeys = async () => {
+ try {
+ const domains = await edgeConfig.get("keys");
+ return domains || [];
+ } catch (e) {
+ return [];
+ }
+};
+
+export const isBlacklistedKey = async (key: string) => {
+ const blacklistedKeys = await getBlacklistedKeys();
+ return new RegExp(blacklistedKeys.join("|"), "i").test(key);
+};
+
export const getBlackListedEmails = async () => {
try {
const emails = await edgeConfig.get("emails");
diff --git a/pages/api/links/index.ts b/pages/api/links/index.ts
index c16e3fc1a5..652abd6f4f 100644
--- a/pages/api/links/index.ts
+++ b/pages/api/links/index.ts
@@ -1,7 +1,7 @@
import { NextApiRequest, NextApiResponse } from "next";
import { addLink, getLinksForProject } from "@/lib/api/links";
import { Session, withUserAuth } from "@/lib/auth";
-import { isBlacklistedDomain } from "@/lib/utils";
+import { isBlacklistedDomain, isBlacklistedKey } from "@/lib/utils";
import { log } from "@/lib/utils";
export const config = {
@@ -39,6 +39,10 @@ export default withUserAuth(
if (hostname === "dub.sh" && pathname === `/${key}`) {
return res.status(400).json({ error: "Invalid url" });
}
+ const keyBlacklisted = await isBlacklistedKey(key);
+ if (keyBlacklisted) {
+ return res.status(400).json({ error: "Invalid key" });
+ }
const domainBlacklisted = await isBlacklistedDomain(url);
if (domainBlacklisted) {
return res.status(400).json({ error: "Invalid url" });