Skip to content

Add length limit to userId parameter to mitigate DoS attack risk #7375

Description

@Iriko0606

Is your feature request related to a problem? Please describe.

The userId parameter in the POST /api/v1/client/{environmentId}/displays endpoint lacks explicit length validation in the Zod schema.
While Next.js's default 4MB request body limit provides some protection, the current implementation allows user IDs up to 4MB (~4
million characters), which is far beyond any reasonable use case.

This creates several issues:

  • Unclear design intent: The code doesn't explicitly define what length of userId is expected
  • Database inefficiency: The ContactAttribute.value field is a TEXT type that can store up to ~1GB, allowing unnecessarily large data
  • Lack of defense in depth: The protection relies solely on framework defaults rather than explicit application-level validation
  • Future risk: If the framework configuration changes or the application is migrated, this could become a vulnerability

Normal user IDs (UUIDs, email addresses, custom IDs) are typically tens to hundreds of characters, not millions.

Describe the solution you'd like

Add explicit length validation to the userId parameter in the Zod schema with a reasonable maximum of 255 characters:

// packages/types/displays.ts
export const ZDisplayCreateInput = z.object({
environmentId: z.string().cuid2(),
surveyId: z.string().cuid2(),
userId: z.string().max(255, {
message: "User ID must not exceed 255 characters"
}).optional(),
responseId: z.string().cuid2().optional(),
});

Why 255 characters:

  • UUID: 36 characters
  • Email address: max 254 characters (RFC 5321)
  • Custom IDs: typically tens to hundreds of characters
  • Covers all common use cases while preventing abuse

Benefits:

  1. Makes the expected userId format explicit in code
  2. Implements defense in depth (application + framework level)
  3. Improves database efficiency and query performance
  4. Prevents potential issues during framework migration or configuration changes
  5. Follows OWASP input validation best practices

Additional context

This same issue likely exists in other endpoints that accept userId parameters. A comprehensive review and fix across all relevant Zod schemas would be beneficial.

Activity

  1. changed the issue type fromtoon Feb 27, 2026
  2. jobenjada commented on Feb 27, 2026

    @jobenjada
    Member

    hey @Iriko0606 thanks for raising this issue, we will get it resolved as soon as possible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions