Skip to content

fix: return 400 instead of 500 for invalid eventTypeId in booking flow#26732

Merged
keithwillcode merged 3 commits intomainfrom
devin/fix-eventTypeId-validation-400-1768208791
Jan 12, 2026
Merged

fix: return 400 instead of 500 for invalid eventTypeId in booking flow#26732
keithwillcode merged 3 commits intomainfrom
devin/fix-eventTypeId-validation-400-1768208791

Conversation

@hbjORbj
Copy link
Contributor

@hbjORbj hbjORbj commented Jan 12, 2026

What does this PR do?

Fixes SQL injection attempts on the booking endpoint (/api/book/event) returning 500 errors instead of 400.

When invalid eventTypeId values (like SQL injection strings) are passed to the booking endpoint, the BotDetectionService.checkBotDetection() method was throwing a generic Error, which resulted in a 500 Internal Server Error. This PR changes it to throw an HttpError with statusCode 400, properly indicating a bad request.

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. N/A - no documentation changes needed.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

Unit tests have been added covering:

  • SQL injection strings as eventTypeId
  • Negative numbers
  • Float numbers
  • Verification that the error statusCode is 400

Co-Authored-By: benny@cal.com <sldisek783@gmail.com>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Co-Authored-By: benny@cal.com <sldisek783@gmail.com>
@hbjORbj hbjORbj marked this pull request as ready for review January 12, 2026 09:37
@graphite-app graphite-app bot added core area: core, team members only foundation labels Jan 12, 2026
@graphite-app graphite-app bot requested a review from a team January 12, 2026 09:37
Comment on lines +39 to +42
throw new ErrorWithCode(
ErrorCode.BadRequest,
`Invalid eventTypeId: ${eventTypeId}. Must be a positive integer.`
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gets converted to HttpError later:

  1. BotDetectionService throws ErrorWithCode(ErrorCode.BadRequest, "Invalid eventTypeId...")
  2. defaultResponder catches the error and calls getServerErrorFromUnknown()
  3. getServerErrorFromUnknown detects ErrorWithCode and calls getHttpStatusCode(cause)
  4. getHttpStatusCode maps ErrorCode.BadRequest to status 400
  5. Response is sent with status 400

@hbjORbj hbjORbj requested a review from keithwillcode January 12, 2026 09:38
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

…ests

Co-Authored-By: benny@cal.com <sldisek783@gmail.com>
@keithwillcode keithwillcode enabled auto-merge (squash) January 12, 2026 10:07
@keithwillcode keithwillcode added this to the v6.1 milestone Jan 12, 2026
@keithwillcode keithwillcode merged commit e3eaa69 into main Jan 12, 2026
46 of 47 checks passed
@keithwillcode keithwillcode deleted the devin/fix-eventTypeId-validation-400-1768208791 branch January 12, 2026 10:07
Anshumancanrock pushed a commit to Anshumancanrock/cal.com that referenced this pull request Jan 12, 2026
calcom#26732)

* fix: return 400 instead of 500 for invalid eventTypeId in booking flow

Co-Authored-By: benny@cal.com <sldisek783@gmail.com>

* refactor: use ErrorWithCode instead of HttpError in BotDetectionService

Co-Authored-By: benny@cal.com <sldisek783@gmail.com>

* refactor: use vi.stubEnv for safer environment variable handling in tests

Co-Authored-By: benny@cal.com <sldisek783@gmail.com>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@vercel vercel bot temporarily deployed to Preview – cal-companion January 13, 2026 08:56 Inactive
@vercel vercel bot temporarily deployed to Preview – dev January 13, 2026 08:59 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants