Skip to content

🔒 Fix potential SSRF/Header Injection in githubViewer#96

Merged
is0692vs merged 3 commits intomainfrom
security/fix-githubviewer-token-validation-3622457549627757320
Mar 21, 2026
Merged

🔒 Fix potential SSRF/Header Injection in githubViewer#96
is0692vs merged 3 commits intomainfrom
security/fix-githubviewer-token-validation-3622457549627757320

Conversation

@is0692vs
Copy link
Contributor

🎯 What: The fetchViewerLogin function in src/lib/githubViewer.ts passed the session token directly into the Authorization header of a fetch request without any validation. I added strict regex validation (/^[A-Za-z0-9_.-]+$/) to reject tokens containing invalid characters.

⚠️ Risk: If an attacker could somehow manipulate their session token, they could potentially inject malicious characters (like CRLF \r\n) to perform HTTP Header Injection or exploit Server-Side Request Forgery (SSRF) by manipulating the outgoing request.

🛡️ Solution: The implemented fix introduces a validation check before any API call is made. If the token fails the regex match, the function throws a GitHubApiError with a status code of 400. This safely neutralizes any attempts to inject line breaks or other payloads into the HTTP headers, while naturally allowing all standard GitHub token formats (PATs, OAuth, etc.). Test cases were also added in githubViewer.test.ts to verify the fix works as intended.


PR created automatically by Jules for task 3622457549627757320 started by @is0692vs

Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@vercel
Copy link

vercel bot commented Mar 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
github-user-summary Ready Ready Preview, Comment Mar 20, 2026 7:29am

@coderabbitai
Copy link

coderabbitai bot commented Mar 20, 2026

Warning

Rate limit exceeded

@is0692vs has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 7 minutes and 40 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d23826fb-9910-458e-b62e-e9fee2fa6f8c

📥 Commits

Reviewing files that changed from the base of the PR and between da454ed and 14689a0.

📒 Files selected for processing (1)
  • src/lib/__tests__/githubViewer.test.ts
📝 Walkthrough

Walkthrough

fetchViewerLogin関数にトークン形式の検証ロジックを追加し、正規表現パターンマッチにより無効なトークン形式を事前にチェックします。同時に、包括的なテストスイートを実装して、成功ケース、無効なトークン形式、APIエラーレスポンスをカバーしています。

Changes

Cohort / File(s) Summary
Token Validation Logic
src/lib/githubViewer.ts
トークンパラメータに対して正規表現^[A-Za-z0-9_.-]+$による検証を追加。無効な形式の場合はGitHubApiError("Invalid token format", 400)を投げ、ネットワーク呼び出しをスキップします。
Test Suite
src/lib/__tests__/githubViewer.test.ts
fetchグローバルのモック化、成功ケース(ログイン取得)、無効なトークン形式のパラメータ化テスト、APIエラーレスポンスハンドリングをカバーする包括的なテストスイートを実装。

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 トークンの検証、ぴょんぴょん!
正規表現で守るセキュリティ
テストも綺麗に揃いました
バグなく安心、APIコール
ウサギも満足のご変更

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed タイトルは修正対象の主要な変更(SSRF/ヘッダーインジェクションの脆弱性修正)を正確に要約しており、変更セットの主な目的と一致しています。
Description check ✅ Passed 説明は変更セット全体に関連しており、脆弱性の詳細、リスク、実装されたソリューション、テストケースについて具体的に記述されています。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch security/fix-githubviewer-token-validation-3622457549627757320
📝 Coding Plan
  • Generate coding plan for human review comments

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 and usage tips.

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical security vulnerability by introducing robust validation for GitHub session tokens. The changes ensure that tokens used in API requests adhere to a strict format, effectively mitigating risks of header injection and server-side request forgery, thereby enhancing the application's overall security posture.

Highlights

  • Security Fix: Implemented strict regex validation for session tokens in the fetchViewerLogin function to prevent potential HTTP Header Injection and Server-Side Request Forgery (SSRF) vulnerabilities.
  • Error Handling: Introduced a GitHubApiError with a 400 status code for invalid token formats, ensuring API calls are not made with malformed tokens.
  • Testing: Added comprehensive test cases to githubViewer.test.ts to verify the new token validation logic and error handling for various token scenarios.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses a potential security vulnerability (SSRF/Header Injection) in fetchViewerLogin by adding validation to the session token. The use of a regular expression to whitelist allowed characters is a solid approach to prevent malicious inputs. The accompanying tests verify the fix and cover both valid and invalid token scenarios. My review includes a couple of suggestions to improve the new tests by making them more concise and robust.

Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/lib/__tests__/githubViewer.test.ts`:
- Line 2: The test import uses a relative path; update the import to use the
repository's `@/` alias (pointing to the same module) so it follows the src import
convention — replace the "../githubViewer" import with "@/lib/githubViewer" (the
module that exports fetchViewerLogin) so fetchViewerLogin is imported via the `@/`
alias.
- Line 3: Remove the unused import GitHubApiError from the top-level import list
in the githubViewer.test.ts test file (the import that currently reads "import {
GitHubApiError } ..."); delete that symbol from the import statement (or remove
the entire import if it becomes empty) so the linter warning is resolved, then
run the linter/tests to confirm no remaining unused-import warnings.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: e26ca6d1-9b3d-4679-876f-11df15a188d7

📥 Commits

Reviewing files that changed from the base of the PR and between 87d145d and da454ed.

📒 Files selected for processing (2)
  • src/lib/__tests__/githubViewer.test.ts
  • src/lib/githubViewer.ts

@is0692vs
Copy link
Contributor Author

レビュー内容を整理します。

全体所感

  • gemini-code-assist: This pull request effectively addresses a potential security vulnerability (SSRF/Header Injection) in fetchViewerLogin by adding validation to the session token. The use of a regular expression to whitelist allowed characters is a solid approach to prevent malicious inputs.
  • coderabbitai: actionable comment が 2 件あります。

主な未解決指摘

  • [high] src/lib/tests/githubViewer.test.ts:2 coderabbitai: Refactor suggestion | 🟠 Major import は @/ エイリアスに統一してください。
  • [medium/outdated] src/lib/tests/githubViewer.test.ts:43 gemini-code-assist: These two tests for invalid tokens can be combined into a single, more robust parameterized test using it.each.
  • [medium] src/lib/tests/githubViewer.test.ts:3 coderabbitai: Potential issue | 🟡 Minor 未使用の GitHubApiError import を削除してください。
  • [medium] src/lib/tests/githubViewer.test.ts:50 gemini-code-assist: This test is inefficient as it mocks fetch twice and calls fetchViewerLogin twice to test the same scenario.

@gemini-code-assist
Copy link

Hello @is0692vs,

Thank you for organizing the review comments. I appreciate you taking the time to summarize the feedback.

Regarding the points attributed to gemini-code-assist:

  • [medium/outdated] src/lib/__tests__/githubViewer.test.ts:43 gemini-code-assist: These two tests for invalid tokens can be combined into a single, more robust parameterized test using it.each.
    I see that you have already addressed this point by refactoring the invalid token tests to use it.each. This is a great improvement for test conciseness and maintainability.

  • [medium] src/lib/__tests__/githubViewer.test.ts:50 gemini-code-assist: This test is inefficient as it mocks fetch twice and calls fetchViewerLogin twice to test the same scenario.
    My apologies if my previous comment was unclear or based on an earlier state of the code. Looking at the current implementation of the test at src/lib/__tests__/githubViewer.test.ts:42-50 (the test for should throw a GitHubApiError when the fetch response is not ok), it appears to be testing a distinct error scenario where the fetch call itself fails. As written, it mocks fetch once and calls fetchViewerLogin once for this specific test, which seems appropriate and efficient for this particular case. The it.each refactoring you performed for the invalid token formats has significantly improved the overall efficiency for those similar test cases.

Please let me know if you have any further questions or if I misunderstood anything.

@google-labs-jules
Copy link
Contributor

レビュー内容を整理します。

全体所感

  • gemini-code-assist: This pull request effectively addresses a potential security vulnerability (SSRF/Header Injection) in fetchViewerLogin by adding validation to the session token. The use of a regular expression to whitelist allowed characters is a solid approach to prevent malicious inputs.
  • coderabbitai: actionable comment が 2 件あります。

主な未解決指摘

  • [high] src/lib/tests/githubViewer.test.ts:2 coderabbitai: Refactor suggestion | 🟠 Major import は @/ エイリアスに統一してください。
  • [medium/outdated] src/lib/tests/githubViewer.test.ts:43 gemini-code-assist: These two tests for invalid tokens can be combined into a single, more robust parameterized test using it.each.
  • [medium] src/lib/tests/githubViewer.test.ts:3 coderabbitai: Potential issue | 🟡 Minor 未使用の GitHubApiError import を削除してください。
  • [medium] src/lib/tests/githubViewer.test.ts:50 gemini-code-assist: This test is inefficient as it mocks fetch twice and calls fetchViewerLogin twice to test the same scenario.

ご指摘ありがとうございます。src/lib/__tests__/githubViewer.test.tsのインポートパスを@/lib/githubViewerに統一し、未使用のGitHubApiErrorのインポートを削除しました。また、前回のコミットでテストの冗長な部分(it.eachの使用や重複したfetchモックの削除)は修正済みです。

Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
@is0692vs is0692vs merged commit dd0bbf3 into main Mar 21, 2026
7 checks passed
@is0692vs is0692vs deleted the security/fix-githubviewer-token-validation-3622457549627757320 branch March 21, 2026 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant