fix: improve validation and normalization for portfolio URLs - #1950
fix: improve validation and normalization for portfolio URLs#1950kumudasrip wants to merge 1 commit into
Conversation
|
@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. |
📝 WalkthroughWalkthroughThe 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. ChangesPortfolio URL validation
Estimated code review effort: 3 (Moderate) | ~25 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
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. Comment |
|
Hello @durdana3105 , I have created this PR to close issue #1376 |
There was a problem hiding this comment.
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
📒 Files selected for processing (5)
src/components/mentor/MentorForm.tsxsrc/pages/Portfolio.tsxsrc/pages/PublicPortfolio.tsxsrc/utils/urlValidation.test.tssrc/utils/urlValidation.ts
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:
validateAndNormalizeUrlutility insrc/utils/urlValidation.tsto automatically prependhttps://to schema-less URLs, filter out unsafe protocols (likejavascript:), and strictly enforce specific domains if required (e.g.,github.com). Added comprehensive tests insrc/utils/urlValidation.test.ts.PublicPortfolio.tsxto safely intercept and parse URLs before rendering, ensuring that older, un-normalized database entries are handled correctly (or hidden safely if fully invalid).Portfolio.tsxto validate GitHub, LinkedIn, and project URLs before saving the payload. The user receives clear error toast notifications if validation fails.MentorForm.tsxto validate GitHub and LinkedIn profiles explicitly, preventing users from moving on to the next form step without valid URLs.github.com/userbecomeshttps://github.com/user) when saved to the backend database.Type of change
Checklist:
Summary by CodeRabbit
New Features
Bug Fixes