Skip to content

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

fix: Validate trimmed inputs and enforce code length server‑side.

Marc Seitza83603c1b4d7
diff --git a/app/api/auth/verify-code/route.ts b/app/api/auth/verify-code/route.ts
index d1f62eb4..6c57c9c3 100644
--- a/app/api/auth/verify-code/route.ts
+++ b/app/api/auth/verify-code/route.ts
@@ -19,16 +19,26 @@ export async function POST(request: NextRequest) {
const body = await request.json();
const { email, code } = body;
- if (!email || !code) {
+ // Type checks first to prevent calling .trim() on non-strings
+ if (typeof email !== "string" || typeof code !== "string") {
return NextResponse.json(
{ error: "Email and code are required." },
{ status: 400 },
);
}
+ // Normalize after type check
const normalizedEmail = email.trim().toLowerCase();
const normalizedCode = code.trim().toUpperCase();
+ // Validate non-empty email and exact code length
+ if (!normalizedEmail || normalizedCode.length !== 10) {
+ return NextResponse.json(
+ { error: "Invalid email or code format." },
+ { status: 400 },
+ );
+ }
+
const ip = getClientIp(request);
// Check both rate limits