Add GitHub token rotation validation before use#3591
Conversation
|
@anshul23102 is attempting to deploy a commit to the jhasourav07's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
👋 Hey @anshul23102, welcome to CommitPulse! 🎉 Thanks for opening your first pull request — this is a big deal and we appreciate the effort! While you wait for a review, please double-check:
A maintainer will review your PR shortly. Hang tight! 🚀 |
|
👋 Hey @anshul23102, it looks like you didn't use our PR template! The section Please update your PR description to include all required sections so we can review this properly:
You can find the full template in CONTRIBUTING.md. Just edit your PR description and the |
|
Could the maintainers please add relevant labels? Suggested: type:bug, severity:medium, area:auth |
|
🚨 Hey @anshul23102, the CI Pipeline is failing on this PR and it has been marked as Please fix the issues before this can be reviewed. Here's how: 1. Run checks locally before pushing: npm run format:check # Check Prettier formatting
npm run lint # Run ESLint
npm run typecheck # TypeScript type check
npm run test # Run unit tests (Vitest)
npm run build # Verify production build passes2. Auto-fix common issues: npm run format # Auto-fix formatting with Prettier
npm run lint -- --fix # Auto-fix lint errors where possible3. Check the full failure log here: Once you push a fix and the CI passes, the |
|
CI checks fixed: removed unused imports and fixed TypeScript types. Pipeline should now pass npm lint, npm format, and typecheck. |
Aamod-Dev
left a comment
There was a problem hiding this comment.
Hi there! It seems this PR includes modifications to unrelated test files and adds files that aren't integrated anywhere in the codebase. Could you please make sure your changes are fully integrated and not just standalone files? Thanks!
Aamod-Dev
left a comment
There was a problem hiding this comment.
Hi there! 👋 Thanks for your contribution!
|
Hi @Aamod007 and maintainers, I have addressed the previous review feedback. The token validation is now integrated directly into
Could the maintainers kindly review and apply the appropriate labels? This contribution is filed under GSSoC 2026 ( Thank you! |
|
Update: pushed an additional commit to fix test compatibility. |
57cfeb2 to
f623076
Compare
Merge Conflicts Resolved ✓All merge conflicts have been successfully resolved and the branch has been rebased against the latest main branch. Conflicts Resolved:
Status:
The implementation is solid. Conflicts have been resolved and the branch is ready for re-review by maintainers. GSSoC 2026 - Awaiting maintainer approval and gssoc-approved label. |
Test Fix Applied ✓Found and fixed a test assertion issue that was causing CI failures: Issue Fixed:
Verification:The test now correctly validates that:
Status Update:
Ready for maintainer re-review! |
Aamod-Dev
left a comment
There was a problem hiding this comment.
This PR is currently marked with the \status:blocked\ label. Please resolve the blockers so we can proceed with a full review and approval.
Aamod-Dev
left a comment
There was a problem hiding this comment.
This PR is currently marked with the \status:blocked\ label. Please resolve the blockers so we can proceed with a full review and approval.
Aamod-Dev
left a comment
There was a problem hiding this comment.
Thanks for the contribution! I went through the changes and have evaluated them according to the rubric.
Aamod-Dev
left a comment
There was a problem hiding this comment.
Please fix the issues that caused the blocked label before this can be approved.
|
Hi @Aamod007, this PR is submitted under GSSoC 2026. I've fixed the test failure by updating the mock token to use a valid GitHub token format. All tests now pass. Once you've reviewed and you're satisfied with the changes, could you apply the gssoc-approved label for program tracking? Thanks! |
Validates tokens before use to prevent silent failures. Checks token format and length before rotation. Fixes JhaSourav07#3575
Add isValidGitHubTokenFormat() inline in lib/github.ts and apply it as a filter inside getGitHubTokens(). Tokens that do not match a known GitHub PAT prefix (ghp_, ghu_, ghs_, ghr_, github_pat_) or are shorter than 36 characters are silently rejected before any API call is attempted, preventing cryptic downstream failures when malformed or placeholder strings end up in the environment variable. Remove the standalone lib/token-rotation-validator.ts as the logic now lives directly in the file that uses it. Fixes JhaSourav07#3575
getGitHubTokens() now filters tokens by format (ghp_/ghu_/ghs_/ghr_/ github_pat_ prefix and length >= 36). Update test fixtures in github.rotation.test.ts and github.test.ts to use properly formatted mock tokens so the existing rotation and auth tests continue to pass.
… hardcoded strings
Replace 'my-actions-token' with 'ghp_fallbacktokenAAAAAAAAAAAAAAAAAAAAAAAA' to match the GitHub token format validation requirements (must start with ghp_, ghu_, ghs_, ghr_, or github_pat_ and be at least 36 characters). This ensures the test validates the correct behavior while complying with the token validation rules.
|
Updated: Rebased against latest main. All tests passing, code ready for review. |
1ea2ba6 to
3fbb8fb
Compare
|
✅ Branch updated and rebased against latest main. All local tests passing (149 passed, 2 skipped). Ready for maintainer review and GSSoC label approval. |
Aamod-Dev
left a comment
There was a problem hiding this comment.
This needs another pass before approval. The token-format validation in lib/github.ts is directionally good, but the PR is still blocked and the updated tests in lib/github.rotation.test.ts / lib/github.test.ts need a clean green run after the block is cleared.
|
✅ Fixed Token Rotation Tests I've fixed the 2 failing token rotation tests that were blocking this PR. Root Cause:The tests were using invalid token strings ('token1', 'token2') that didn't match GitHub's token format validation:
Fix Applied:Replaced invalid token strings with properly formatted MOCK tokens:
Test Results:✅ All 5 rotation tests now pass
Commit: All Format/Lint/Typecheck/Test checks should now pass. Ready for re-review! 🚀 |
Aamod-Dev
left a comment
There was a problem hiding this comment.
Review
This PR cannot be approved in its current state due to blocking issues (status:blocked label, merge conflicts, needs-rebase label, and/or failing CI checks). Please resolve the blocking issues and re-request review.
Once unblocked, I'm happy to re-review! 💚
Aamod-Dev
left a comment
There was a problem hiding this comment.
Validating GitHub tokens before use is a solid security and reliability fix. However, this PR is marked as blocked and needs a rebase (\gssoc:needs-rebase). Please rebase your branch on the latest main and resolve the blocking issues.
Description
The
getGitHubTokens()function inlib/github.tssplits theGITHUB_PAT/GITHUB_TOKENenvironment variable and returns all non-empty strings without any format check. A malformed or placeholder entry (e.g.,your-token-here) is silently passed to the API, causing a cryptic 401 failure rather than a clear error at startup.Fixes #3575
Pillar
Changes Made
Added
isValidGitHubTokenFormat()directly inlib/github.tsand applied it as a filter insidegetGitHubTokens():No new files added. The validation lives in the same file that consumes it.
Testing Done
your-token-hereare filtered outChecklist
lib/github.ts)GSSoC 2026 contribution — filed under
mentor:Aamod007