Skip to content

fix(security): validate and sanitize github usernames in API routes#866

Open
harshitanagpal05 wants to merge 4 commits into
Priyanshu-byte-coder:mainfrom
harshitanagpal05:fix/security-857-username-validation
Open

fix(security): validate and sanitize github usernames in API routes#866
harshitanagpal05 wants to merge 4 commits into
Priyanshu-byte-coder:mainfrom
harshitanagpal05:fix/security-857-username-validation

Conversation

@harshitanagpal05
Copy link
Copy Markdown

Summary

Fixes [Security] GitHub API URL path traversal and search query injection via unsanitized username parameter #857.

Changes

  • Added shared validator: src/lib/validate-github-username.ts
  • Applied validation guard to:
    • src/app/api/metrics/compare/route.ts
    • src/app/api/metrics/contributions/route.ts
    • src/app/api/badge/commits/route.ts
    • src/app/api/badge/streak-shield/route.ts
  • Added URL hardening:
    • encodeURIComponent() for GitHub path segments where username is interpolated
    • URL/URLSearchParams for query construction to prevent injection
  • Added tests:
    • test/validate-github-username.test.js

Security impact

  • Blocks path traversal attempts via username in GitHub API path usage.
  • Blocks search query injection in unauthenticated badge endpoints.

Validation

@vercel
Copy link
Copy Markdown

vercel Bot commented May 23, 2026

@harshitanagpal05 is attempting to deploy a commit to the PRIYANSHU DOSHI's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added gssoc26 GSSoC 2026 contribution type:bug GSSoC type bonus: bug fix type:security GSSoC type bonus: security (+20 pts) type:testing GSSoC type bonus: tests (+10 pts) labels May 23, 2026
@github-actions
Copy link
Copy Markdown

GSSoC Label Checklist 🏷️

@Priyanshu-byte-coder — please apply the appropriate labels before merging:

Difficulty (pick one):

  • level:beginner — 20 pts
  • level:intermediate — 35 pts
  • level:advanced — 55 pts
  • level:critical — 80 pts

Quality (optional):

  • quality:clean — ×1.2 multiplier
  • quality:exceptional — ×1.5 multiplier

Validation (required to score):

  • gssoc:approved — counts for points
  • gssoc:invalid / gssoc:spam / gssoc:ai-slop — does not score

Type labels (type:*) are auto-detected from files and title. Review and adjust if needed.
Points formula: (difficulty × quality_multiplier) + type_bonus

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Thanks for your first PR on DevTrack! 🎉

A maintainer will review it within 48 hours. While you wait:

  • Make sure CI is passing (type-check + lint)
  • Double-check the PR description is filled out and the issue is linked
  • Feel free to ask questions in Discussions if you need help

If you find DevTrack useful, a ⭐ star on the repo is always appreciated — it helps the project grow and attract more contributors!

@Priyanshu-byte-coder
Copy link
Copy Markdown
Owner

Changes needed before merge:

compare/route.ts — cache still uses next: { revalidate: 3600 }
All 4 fetch() calls in the compare route still pass next: { revalidate: 3600 }. This was the root cause of the cross-user data leak fixed in commit 435d85f — Next.js keys the cache by URL, so User A's authenticated GitHub response gets served to User B querying the same username. Please change all 4 to cache: "no-store":

// All fetch() calls in compare/route.ts
{ headers: { Authorization: `Bearer ${session.accessToken}` }, cache: "no-store" }

The validate-github-username.ts utility and URL API injection prevention are excellent — ready to merge once the cache issue is fixed. Please rebase on main first (commit 435d85f is already there).

@Priyanshu-byte-coder Priyanshu-byte-coder added gssoc:approved GSSoC: PR approved for scoring level:intermediate GSSoC: Intermediate difficulty (35 pts) labels May 23, 2026
@harshitanagpal05
Copy link
Copy Markdown
Author

hey! @Priyanshu-byte-coder, I’ve implemented the requested fix in the compare API route and pushed it to the PR branch. All GitHub fetch calls in route.ts now use cache: "no-store" instead of next: { revalidate: 3600 }.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved GSSoC: PR approved for scoring gssoc26 GSSoC 2026 contribution level:intermediate GSSoC: Intermediate difficulty (35 pts) type:bug GSSoC type bonus: bug fix type:security GSSoC type bonus: security (+20 pts) type:testing GSSoC type bonus: tests (+10 pts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Security] GitHub API URL path traversal and search query injection via unsanitized username parameter

2 participants