Fix: Implement slug validation in TeamIdOrSlugSchema (resolves FIXME)#258
Fix: Implement slug validation in TeamIdOrSlugSchema (resolves FIXME)#258taheerahmed wants to merge 1 commit intoe2b-dev:mainfrom
Conversation
Resolves the FIXME in TeamIdOrSlugSchema by adding a regex that matches the DB slug generation from generate_team_slug(): lowercase alphanumeric characters separated by single hyphens. Previously any string was accepted, allowing special characters, path traversal patterns, and uppercase through schema validation. Added 15 unit tests covering valid UUIDs, valid slugs (including DB-generated suffixes), and rejection of invalid inputs. Closes e2b-dev#257
|
@taheerahmed is attempting to deploy a commit to the E2B Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d5c00aeceb
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| z | ||
| .string() | ||
| .regex( | ||
| /^[a-z0-9]+(-[a-z0-9]+)*$/, |
There was a problem hiding this comment.
Align slug validator with DB-generated slug shapes
The new regex only accepts canonical kebab-case, but generate_team_slug() in migrations/20250205180205.sql (lines 42-54, 70-74, 85-92) can persist other forms (e.g. empty/leading-hyphen/multi-hyphen slugs) because it preserves existing hyphens, doesn't normalize them, and the table only enforces uniqueness. Since getTeamIdFromSegment now gates lookups through TeamIdOrSlugSchema, those already-stored slugs become unresolvable and affected users get unauthorized responses instead of their team data.
Useful? React with 👍 / 👎.
Summary
Resolves the
FIXMEinTeamIdOrSlugSchemaby adding a regex that matches the DB'sgenerate_team_slug()output from the migration inmigrations/20250205180205.sql.Change
src/lib/schemas/team.ts:Note: removed the
iflag from the original commented regex sincegenerate_team_slug()produces lowercase-only output viaLOWER().Tests
Added 15 unit tests in
src/__test__/unit/team-schema.test.ts:acme-incacme-inc-a3f2(DB suffix)singlewordteam-123UPPERCASEhas spaceshas_underscore-leadingtrailing-double--hyphen../../etc/passwdAll unit tests pass (
bun run test:unit— 95/95).Closes #257