Skip to content

fix: improve validation and normalization for portfolio URLs - #1950

Open
kumudasrip wants to merge 1 commit into
durdana3105:mainfrom
kumudasrip:improve-validation
Open

fix: improve validation and normalization for portfolio URLs#1950
kumudasrip wants to merge 1 commit into
durdana3105:mainfrom
kumudasrip:improve-validation

Conversation

@kumudasrip

@kumudasrip kumudasrip commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Fixes #1376

This PR introduces robust URL validation and normalization for portfolio-related links (GitHub, LinkedIn, and project URLs) across the platform. Previously, malformed URLs (e.g., missing https:// or typos) were rendered directly, causing broken navigation and potentially unsafe links.

With these changes, URLs are strictly checked for valid domains and protocols, normalized before being saved to the database, and gracefully stripped on the frontend if they are invalid.

Changes Made:

  • URL Utility & Tests: Added a centralized validateAndNormalizeUrl utility in src/utils/urlValidation.ts to automatically prepend https:// to schema-less URLs, filter out unsafe protocols (like javascript:), and strictly enforce specific domains if required (e.g., github.com). Added comprehensive tests in src/utils/urlValidation.test.ts.
  • Pre-Render Validation: Updated PublicPortfolio.tsx to safely intercept and parse URLs before rendering, ensuring that older, un-normalized database entries are handled correctly (or hidden safely if fully invalid).
  • Graceful Form Feedback:
    • Updated Portfolio.tsx to validate GitHub, LinkedIn, and project URLs before saving the payload. The user receives clear error toast notifications if validation fails.
    • Updated MentorForm.tsx to validate GitHub and LinkedIn profiles explicitly, preventing users from moving on to the next form step without valid URLs.
  • Normalization on Save: Ensured that valid URLs inputted without the HTTP protocol are properly formatted (e.g. github.com/user becomes https://github.com/user) when saved to the backend database.

Type of change

  • Bug fix

Checklist:

  • I have performed a self-review of my own code
  • I have added tests that prove my fix is effective or that my feature works
  • My changes generate no new warnings

Summary by CodeRabbit

  • New Features

    • Added consistent URL validation and normalization for mentor profiles and portfolios.
    • GitHub and LinkedIn links are checked against their expected domains.
    • Project links are validated before saving or displaying.
    • URLs are automatically normalized to secure HTTPS format when appropriate.
  • Bug Fixes

    • Invalid, malformed, or unsafe URLs can no longer be saved or rendered.
    • Clearer field-specific validation messages are shown for invalid links.

@vercel

vercel Bot commented Aug 7, 2026

Copy link
Copy Markdown

@kumudasrip is attempting to deploy a commit to the durdana3105's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change adds shared URL validation and normalization. Mentor and portfolio forms validate URLs before saving. Public portfolios validate URLs before rendering. Tests cover empty, normalized, unsafe, malformed, and domain-constrained URLs.

Changes

Portfolio URL validation

Layer / File(s) Summary
URL validation utility and coverage
src/utils/urlValidation.ts, src/utils/urlValidation.test.ts
Adds validateAndNormalizeUrl for HTTP(S) validation, protocol normalization, optional domain checks, and invalid input handling.
Mentor and portfolio save validation
src/components/mentor/MentorForm.tsx, src/pages/Portfolio.tsx
Validates GitHub, LinkedIn, and project URLs before saving. Persists normalized URL values and reports invalid inputs.
Public portfolio URL validation
src/pages/PublicPortfolio.tsx
Validates social and project URLs before storing them for rendering.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Suggested reviewers: arshvermagit, pradeep0153, copperflame14

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: improved validation and normalization for portfolio URLs.
Linked Issues check ✅ Passed The changes implement validation, normalization, safe handling, rendering checks, and tests required by issue #1376.
Out of Scope Changes check ✅ Passed All changes support portfolio URL validation, normalization, safe rendering, user feedback, or related tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kumudasrip

Copy link
Copy Markdown
Contributor Author

Hello @durdana3105 , I have created this PR to close issue #1376
Please do review and merge the PR whenever possible, thank you!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/pages/PublicPortfolio.tsx`:
- Around line 148-152: Update the projects mapping in PublicPortfolio to
normalize or filter nullish project entries before accessing p.url, matching the
established handling in Portfolio.tsx. Preserve valid project entries while
preventing malformed legacy data from throwing and hiding the entire public
portfolio.

In `@src/utils/urlValidation.ts`:
- Around line 15-18: Update the URL normalization logic in the visible
protocol-check block to detect any explicitly supplied URI scheme before adding
the default https prefix. Reject schemes other than http and https, while
preserving normalization for scheme-less URLs and acceptance of valid HTTP(S)
URLs.
- Around line 28-31: Update the requiredDomain validation in the URL validation
function to accept only an exact hostname match or a hostname ending with "."
plus the required domain; replace the substring includes check so lookalike and
attacker-controlled suffix hosts are rejected while legitimate subdomains remain
valid.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 0804f506-3489-41bd-b87f-ad48ac26bc6e

📥 Commits

Reviewing files that changed from the base of the PR and between d0a5116 and b473d5b.

📒 Files selected for processing (5)
  • src/components/mentor/MentorForm.tsx
  • src/pages/Portfolio.tsx
  • src/pages/PublicPortfolio.tsx
  • src/utils/urlValidation.test.ts
  • src/utils/urlValidation.ts

Comment thread src/pages/PublicPortfolio.tsx
Comment thread src/utils/urlValidation.ts
Comment thread src/utils/urlValidation.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve validation for portfolio URLs before rendering

2 participants