Repository navigation
fix(sdk): add userId length limit to mitigate DoS attack risk - #7378
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 33a4423bba
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
WalkthroughThis pull request implements a maximum length constraint of 255 characters for userId fields across the codebase. Changes include adding runtime validation logic in the user module that checks userId length and returns early if exceeded, adding a corresponding test case to verify this behavior, and updating validation schemas in the types package to enforce the 255-character limit at the schema level for multiple user identification input types. These changes ensure consistent userId length validation throughout the application. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/js-core/src/lib/user/user.ts`:
- Around line 13-17: Currently the userId max length literal (255) is
duplicated; replace the local const MAX_USER_ID_LENGTH in user.ts with an
exported constant (export const MAX_USER_ID_LENGTH = 255) and update the check
in the function that references userId to use that exported symbol; update the
logger.error message to interpolate the exported constant rather than a
hardcoded number; then update any schema/validator modules to import
MAX_USER_ID_LENGTH instead of using their own literal so the runtime check
(user.ts), schema validators, and messages remain in sync.
In `@packages/types/js.ts`:
- Around line 101-104: ZJsActionInput currently allows an unbounded userId
(z.string().optional()), leaving a DoS vector; change the schema to enforce the
same cap as ZJsUserIdentifyInput by replacing the unbounded userId with
z.string().max(255).optional(). Also scan this file for any other schemas that
declare a userId (the other occurrences referenced around lines 147-149) and
apply the same max(255) constraint to them so all userId fields consistently
enforce the length limit.
ℹ️ Review info
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (4)
packages/js-core/src/lib/user/tests/user.test.tspackages/js-core/src/lib/user/user.tspackages/types/displays.tspackages/types/js.ts
|
Hey @Dhruwang! 👋 I've picked up #7375 and implemented the length limit fixes for userId. Included in this PR: Added .max(255) to the Zod schemas (ZDisplayCreateInput, ZResponseInput, ZJsUserIdentifyInput, ZJsPersonSyncParams). Let me know if you need any adjustments or if I missed any other schemas! |
mattinannt
left a comment
There was a problem hiding this comment.
@bharathkumar39293 Thanks you for the PR :-)
The additional validation makes sense and the code looks good 💪
Fixes #7375
Description
The
userIdparameter in endpoints like POST/api/v1/client/{environmentId}/displaysand the JS SDK lacked explicit length validation. This could potentially allow arbitrarily large payloads (up to Next.js's 4MB limit), creating a DoS risk.This PR adds a maximum length limit of 255 characters to the
userIdin both the Zod schemas and the JS SDK early rejection logic.Changes
.max(255)toZDisplayCreateInputin packages/types/displays.ts.max(255)toZResponseInputin packages/types/responses.ts.max(255)toZJsUserIdentifyInputandZJsPersonSyncParamsin packages/types/js.tsTesting
should reject userId longer than 255 characters and not send updatesuserIdexceeds 255 characters, an error is logged andUpdateQueueis not triggered.