Skip to content

Harden validateUrl/validateEmail in shared validation utils and add edge-case tests #180

Description

@Jagadeeshftw

📌 Description

src/shared/utils/validation.ts exposes validateUrl, validateEmail, validateRepoName, and validateRequired. validateUrl requires a dot in the hostname (rejecting localhost/IP), and validateEmail uses a simplistic regex that rejects many valid addresses. Edge cases are not all tested.

💡 Why it matters: Over-strict validators block legitimate input; under-strict ones admit bad input.

🧩 Requirements and context

  • Make validateUrl accept valid hosts (localhost/IP) where appropriate while still rejecting non-http(s) schemes (e.g. javascript:).
  • Improve validateEmail to a sounder pattern without becoming catastrophically backtracking.
  • Add tests covering the corrected and rejected cases for all four validators.
  • Document each regex with a comment.

Non-functional requirements

  • Must be secure, tested, and documented.
  • Should be efficient and easy to review.

🛠️ Suggested execution

1. Fork the repo and create a branch

git checkout -b fix/validation-edge-cases

2. Implement changes

  • Write/modify the relevant source: src/shared/utils/validation.ts
  • Write comprehensive tests: src/shared/utils/validation.test.ts
  • Add documentation: inline regex comments + TSDoc
  • Include TSDoc doc comments
  • Validate security assumptions: reject javascript:/data: URLs; avoid ReDoS

3. Test and commit

  • Run tests:
npm run test
  • Cover edge cases: localhost URL, IP URL, dangerous scheme, plus-tagged email
  • Include test output and security notes in the PR description.

Example commit message

fix(validation): correct URL/email rules + edge-case tests

✅ Acceptance criteria

  • validateUrl accepts localhost/IP, rejects dangerous schemes
  • validateEmail accepts common valid forms
  • No ReDoS-prone patterns
  • Tests cover added cases

🔒 Security notes

Reject javascript:/data: schemes; ensure regexes are not exponential-time.

📋 Guidelines

  • Minimum 95% test coverage
  • Clear documentation
  • Timeframe: 96 hours

Metadata

Metadata

Assignees

Labels

GrantFox OSSGrantFox open-source programMaybe RewardedGrantFox: potentially rewarded contributionOfficial CampaignGrantFox official campaign issuefrontendFrontend / UI worksecuritySecurity hardening / audittestingTests and coverage

Type

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions