Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email Validation Hangs at 100% CPU usage #2580

Closed
arthurbelair opened this issue Jul 14, 2023 · 3 comments
Closed

Email Validation Hangs at 100% CPU usage #2580

arthurbelair opened this issue Jul 14, 2023 · 3 comments

Comments

@arthurbelair
Copy link

Hello,

I came across an issue with the email validation for a specific input string (a long and complex email address).
When attempting to validate/parse the string, the process immediately goes to 100% CPU usage, and never actually finishes parsing. I have waited for ~15 minutes max.

Here's some code to reproduce, which also shows 2 other RegExes for which the problem doesn't occur:

import {z} from "zod"

const email = "noreply1@1-90y790o645vz81zq6287dhb9x1x28ab4q521nuv7b1og4y9c3q.5r-h8uter0.sc016.case.sandbox.salesforce.com"

const otherRegex1 = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/gi
const otherRegex2 = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/gi

console.log(otherRegex1.test(email)) // true
console.log(otherRegex2.test(email)) // true

const parsed = z.string().email().parse(email) // hangs at 100% CPU

console.log(parsed) // never reached

Screenshot 2023-07-14 at 10 58 23 AM

Using Zod v3.21.4
on a 2023 M2 Macbook Pro

@ghost
Copy link

ghost commented Sep 13, 2023

Here is another example

 youdonothavemypermission.tostoremyinfo.com

@callmeberzerker
Copy link

const otherRegex1 = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/gi
const otherRegex2 = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/gi

This is definitely a big issue. Can we replace the email regex with one of those 2 which are described in the first post?

@colinhacks
Copy link
Owner

Fixed by #2824

Landed in Zod v3.22.3

istarkov added a commit to webstudio-is/webstudio that referenced this issue Mar 12, 2024
## Description

fixes email validation hangs
colinhacks/zod#2580


## Steps for reproduction

1. click button
2. expect xyz

## Code Review

- [ ] hi @kof, I need you to do
  - conceptual review (architecture, feature-correctness)
  - detailed review (read every line)
  - test it on preview

## Before requesting a review

- [ ] made a self-review
- [ ] added inline comments where things may be not obvious (the "why",
not "what")

## Before merging

- [ ] tested locally and on preview environment (preview dev login:
5de6)
- [ ] updated [test
cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md)
document
- [ ] added tests
- [ ] if any new env variables are added, added them to `.env.example`
and the `builder/env-check.js` if mandatory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants