Skip to content

refactor: remove hashed ipAddress from verification token #1401

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions pages/api/views-dataroom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -253,7 +253,7 @@ export default async function handle(

await prisma.verificationToken.deleteMany({
where: {
identifier: `otp:${linkId}:${hashToken(ipAddress)}:${email}`,
identifier: `otp:${linkId}:${email}`,
},
});

Expand All @@ -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,
},
});
Expand All @@ -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) {
Expand All @@ -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}`,
},
});

Expand Down Expand Up @@ -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,
},
});
Expand All @@ -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) {
Expand All @@ -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}`,
},
});

Expand Down
16 changes: 8 additions & 8 deletions pages/api/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -214,7 +214,7 @@ export default async function handle(

await prisma.verificationToken.deleteMany({
where: {
identifier: `otp:${linkId}:${hashToken(ipAddress)}:${email}`,
identifier: `otp:${linkId}:${email}`,
},
});

Expand All @@ -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,
},
});
Expand All @@ -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) {
Expand All @@ -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}`,
},
});

Expand Down Expand Up @@ -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,
},
});
Expand All @@ -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) {
Expand All @@ -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}`,
},
});

Expand Down
Loading