Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

refactor: remove hashed ipAddress from verification token

Marc Seitz6e2e5a9d3fac
diff --git a/pages/api/views-dataroom.ts b/pages/api/views-dataroom.ts
index 6a7f650a..03e7eda7 100644
--- a/pages/api/views-dataroom.ts
+++ b/pages/api/views-dataroom.ts
@@ -241,7 +241,7 @@ export default async function handle(
if (link.emailAuthenticated && !code && !token && !dataroomVerified) {
const ipAddress = getIpAddress(req.headers);
- const { success } = await ratelimit(2, "1 m").limit(
+ const { success } = await ratelimit(10, "1 m").limit(
`send-otp:${ipAddress}`,
);
if (!success) {
@@ -253,7 +253,7 @@ export default async function handle(
await prisma.verificationToken.deleteMany({
where: {
- identifier: `otp:${linkId}:${hashToken(ipAddress)}:${email}`,
+ identifier: `otp:${linkId}:${email}`,
},
});
@@ -264,7 +264,7 @@ export default async function handle(
await prisma.verificationToken.create({
data: {
token: otpCode,
- identifier: `otp:${linkId}:${hashToken(ipAddress)}:${email}`,
+ identifier: `otp:${linkId}:${email}`,
expires: expiresAt,
},
});
@@ -281,7 +281,7 @@ export default async function handle(
let hashedVerificationToken: string | null = null;
if (link.emailAuthenticated && code && !dataroomVerified) {
const ipAddress = getIpAddress(req.headers);
- const { success } = await ratelimit(2, "1 m").limit(
+ const { success } = await ratelimit(10, "1 m").limit(
`verify-otp:${ipAddress}`,
);
if (!success) {
@@ -295,7 +295,7 @@ export default async function handle(
const verification = await prisma.verificationToken.findUnique({
where: {
token: code,
- identifier: `otp:${linkId}:${hashToken(ipAddress)}:${email}`,
+ identifier: `otp:${linkId}:${email}`,
},
});
@@ -336,7 +336,7 @@ export default async function handle(
await prisma.verificationToken.create({
data: {
token: hashedVerificationToken,
- identifier: `link-verification:${linkId}:${hashToken(ipAddress)}:${email}`,
+ identifier: `link-verification:${linkId}:${link.teamId}:${email}`,
expires: tokenExpiresAt,
},
});
@@ -346,7 +346,7 @@ export default async function handle(
if (link.emailAuthenticated && token && !dataroomVerified) {
const ipAddress = getIpAddress(req.headers);
- const { success } = await ratelimit(5, "1 m").limit(
+ const { success } = await ratelimit(10, "1 m").limit(
`verify-email:${ipAddress}`,
);
if (!success) {
@@ -360,7 +360,7 @@ export default async function handle(
const verification = await prisma.verificationToken.findUnique({
where: {
token: token,
- identifier: `link-verification:${linkId}:${hashToken(ipAddress)}:${email}`,
+ identifier: `link-verification:${linkId}:${link.teamId}:${email}`,
},
});
diff --git a/pages/api/views.ts b/pages/api/views.ts
index f29196ab..f9abf15f 100644
--- a/pages/api/views.ts
+++ b/pages/api/views.ts
@@ -202,7 +202,7 @@ export default async function handle(
if (link.emailAuthenticated && !code && !token) {
const ipAddress = getIpAddress(req.headers);
- const { success } = await ratelimit(2, "1 m").limit(
+ const { success } = await ratelimit(10, "1 m").limit(
`send-otp:${ipAddress}`,
);
if (!success) {
@@ -214,7 +214,7 @@ export default async function handle(
await prisma.verificationToken.deleteMany({
where: {
- identifier: `otp:${linkId}:${hashToken(ipAddress)}:${email}`,
+ identifier: `otp:${linkId}:${email}`,
},
});
@@ -225,7 +225,7 @@ export default async function handle(
await prisma.verificationToken.create({
data: {
token: otpCode,
- identifier: `otp:${linkId}:${hashToken(ipAddress)}:${email}`,
+ identifier: `otp:${linkId}:${email}`,
expires: expiresAt,
},
});
@@ -242,7 +242,7 @@ export default async function handle(
let hashedVerificationToken: string | null = null;
if (link.emailAuthenticated && code) {
const ipAddress = getIpAddress(req.headers);
- const { success } = await ratelimit(2, "1 m").limit(
+ const { success } = await ratelimit(10, "1 m").limit(
`verify-otp:${ipAddress}`,
);
if (!success) {
@@ -256,7 +256,7 @@ export default async function handle(
const verification = await prisma.verificationToken.findUnique({
where: {
token: code,
- identifier: `otp:${linkId}:${hashToken(ipAddress)}:${email}`,
+ identifier: `otp:${linkId}:${email}`,
},
});
@@ -297,7 +297,7 @@ export default async function handle(
await prisma.verificationToken.create({
data: {
token: hashedVerificationToken,
- identifier: `link-verification:${linkId}:${hashToken(ipAddress)}:${email}`,
+ identifier: `link-verification:${linkId}:${link.teamId}:${email}`,
expires: tokenExpiresAt,
},
});
@@ -307,7 +307,7 @@ export default async function handle(
if (link.emailAuthenticated && token) {
const ipAddress = getIpAddress(req.headers);
- const { success } = await ratelimit(5, "1 m").limit(
+ const { success } = await ratelimit(10, "1 m").limit(
`verify-email:${ipAddress}`,
);
if (!success) {
@@ -321,7 +321,7 @@ export default async function handle(
const verification = await prisma.verificationToken.findUnique({
where: {
token: token,
- identifier: `link-verification:${linkId}:${hashToken(ipAddress)}:${email}`,
+ identifier: `link-verification:${linkId}:${link.teamId}:${email}`,
},
});