Skip to content

fix: Exclude the possibility to book events with invalid email addresses#9898

Merged
emrysal merged 4 commits intocalcom:mainfrom
jemiluv8:fix-invalid-guest-email-address
Jul 5, 2023
Merged

fix: Exclude the possibility to book events with invalid email addresses#9898
emrysal merged 4 commits intocalcom:mainfrom
jemiluv8:fix-invalid-guest-email-address

Conversation

@jemiluv8
Copy link
Copy Markdown
Contributor

@jemiluv8 jemiluv8 commented Jul 3, 2023

What does this PR do?

Fixes #5972 by introducing email refinement on z.string().email() that uses an emailRegex used
in newer versions of the zod package that we currently use
(This is a short term solution and ought to be removed after upgrading the zod npm package).

Refer to https://github.com/colinhacks/zod/pull/2157/files#diff-c54113cf61ec99691748a3890bfbeb00e10efb3f0a76f03a0fd9ec49072e410a
for the email regex used here

https://www.loom.com/share/d309f330f9ba4ffe893300cd5a936088

Fixes #5972
/claim #5972

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How should this be tested?

For each of the emails below

あいうえお@example.com
email@-example.com
email@111.222.333.44444
just”not”@example.com
  • Visit a booking screen
  • Enter any of the above emails either in the email field or in the guests list
  • Verify that you cannot book with any of the above emails either as guest or "booker"

Mandatory Tasks

  • Make sure you have self-reviewed the code. A decent size PR without self-review might be rejected.

Checklist

  • I haven't read the contributing guide
  • My code doesn't follow the style guidelines of this project
  • I haven't commented my code, particularly in hard-to-understand areas
  • I haven't checked if my PR needs changes to the documentation
  • I haven't checked if my changes generate no new warnings
  • I haven't added tests that prove my fix is effective or that my feature works
  • I haven't checked if new and existing unit tests pass locally with my changes

@vercel
Copy link
Copy Markdown

vercel Bot commented Jul 3, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ui ❌ Failed (Inspect) Jul 3, 2023 5:56pm

@vercel
Copy link
Copy Markdown

vercel Bot commented Jul 3, 2023

@jemiluv8 is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added booking-page area: booking page, public booking page, booker Medium priority Created by Linear-GitHub Sync ✨ feature New feature or request 💎 Bounty A bounty on Algora.io labels Jul 3, 2023
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jul 3, 2023

Thank you for following the naming conventions! 🙏

@jemiluv8 jemiluv8 changed the title fix:Exclude the possibility to book events with invalid email addresses fix: Exclude the possibility to book events with invalid email addresses Jul 3, 2023
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jul 3, 2023

📦 Next.js Bundle Analysis for @calcom/web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

Copy link
Copy Markdown
Contributor Author

@jemiluv8 jemiluv8 left a comment

Choose a reason for hiding this comment

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

@alannnc, I've completed the self review.

// The PR at https://github.com/colinhacks/zod/pull/2157 addresses this issue and improves email validation
// I introduced this refinement(to be used with z.email()) as a short term solution until we upgrade to a zod
// version that will include updates in the above PR.
export const emailSchemaRefinement = (value: string) => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

en email refinement that is based on a regex in a planned update to the zod
built in email validator. Refer to the PR in the comment above for more
details.

The update to the validator improves email validation to catch 4/5 of these
"invalid" emails (In the issue)

const value = responses[bookingField.name];
const stringSchema = z.string();
const emailSchema = isPartialSchema ? z.string() : z.string().email();
const emailSchema = isPartialSchema ? z.string() : z.string().refine(emailSchemaRefinement);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

replaced email validation with the refinement

I originally had

z.string().email().refine(emailSchemaRefinement);

but felt it was redundant. This refinment is effectively the email validator
so no need to specify the build in zod validator prior to applying the refinement

Copy link
Copy Markdown
Contributor

@emrysal emrysal left a comment

Choose a reason for hiding this comment

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

Looks good to me, thank you 👍

@emrysal emrysal merged commit bfc2b8d into calcom:main Jul 5, 2023
fritterhoff pushed a commit to hm-edu/cal.com that referenced this pull request Jul 25, 2023
…ses (calcom#9898)

* Introduce email refinement based on the updated email regex in newer zod versions at https://github.com/colinhacks/zod/pull/2157/files#diff-c54113cf61ec99691748a3890bfbeb00e10efb3f0a76f03a0fd9ec49072e410a

* fix import bug

* fix lint issue

* update emailSchemaRefinement comment to reflect the state of play for the zod fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

booking-page area: booking page, public booking page, booker 💎 Bounty A bounty on Algora.io ✨ feature New feature or request Medium priority Created by Linear-GitHub Sync

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exclude the possibility to book events with invalid email addresses

2 participants