fix(validation): accept localhost/IP in validateUrl and tighten email regex — #180#215
Merged
Jagadeeshftw merged 2 commits intoJun 23, 2026
Conversation
… regex
validateUrl rejected localhost and bare IPs because of an overly strict
hostname.includes('.') check — legitimate dev/internal URLs were blocked.
Removed that check; the URL constructor already enforces a non-empty hostname.
validateEmail regex upgraded from /[^\s@]+@[^\s@]+\.[^\s@]+/ to
/[^\s@]+@[^\s@.]+(\.[^\s@.]+)+/ to reject double dots in domain (e.g.
user@example..com) and missing domain before the dot (user@.com) while
avoiding catastrophic backtracking.
Adds 8 new edge-case tests covering localhost, IPs, javascript:/data:
scheme rejection, double-dot domain, subdomain email, and missing domain.
Closes Grainlify#180
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
|
accepting localhost/IP in validateUrl while tightening the email regex covers the edge cases that always slip through. rebased on latest main, merged. thanks! |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
validateUrl: removed thehostname.includes('.')check that incorrectly rejectedlocalhost, bare IPs, and other valid hosts. TheURLconstructor already enforces a non-empty hostname;javascript:anddata:schemes are still blocked by the explicit protocol check.validateEmail: upgraded regex from/[^\s@]+@[^\s@]+\.[^\s@]+/to/[^\s@]+@[^\s@.]+(\.[^\s@.]+)+/— rejects double dots in domain (user@example..com), missing domain before dot (user@.com), while supporting subdomains and avoiding catastrophic backtracking.Test plan
npx vitest run src/shared/utils/validation.test.ts)https://localhost,http://localhost:3000,http://192.168.1.1→ acceptedjavascript:alert(1),data:text/html,...→ rejecteduser@example..com,user@.com→ rejecteduser@mail.example.co.uk→ acceptedCloses #180
🤖 Generated with Claude Code