-
Notifications
You must be signed in to change notification settings - Fork 0
🔒 Fix potential Server-Side DoS via Unauthenticated GitHub API Call #516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,7 @@ | |
| try { | ||
| const res = await fetch(`https://api.github.com/users/${encodeURIComponent(username)}`, { | ||
| headers: { | ||
| ...(process.env.GITHUB_TOKEN && { Authorization: `Bearer ${process.env.GITHUB_TOKEN}` }), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. No tests for github_token The new conditional Authorization header branch is not covered by tests, so regressions (missing/always-sent auth header) could go unnoticed. Add tests that assert request headers with and without process.env.GITHUB_TOKEN. Agent Prompt
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2. Untrimmed github token The OG route sends Authorization: Bearer ${process.env.GITHUB_TOKEN} without trimming/validating,
so a whitespace-padded secret (common when copy/pasting) will produce an invalid auth header and the
call will still be effectively unauthenticated—undermining the PR’s DoS mitigation. The current
...(process.env.GITHUB_TOKEN && {...}) pattern is also brittle; prefer a normalized token +
explicit ternary/object construction.
Agent Prompt
|
||
| Accept: "application/vnd.github.v3+json", | ||
| "User-Agent": "github-user-summary", | ||
| }, | ||
|
|
@@ -84,7 +85,7 @@ | |
| }} | ||
| > | ||
| {avatarUrl && ( | ||
| <img | ||
|
Check warning on line 88 in src/app/api/og/[username]/route.tsx
|
||
| src={sanitizeUrl(avatarUrl)} | ||
| alt="" | ||
| width={120} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
複数の送信元IPからキャッシュされていない異なるユーザー名へ毎分50件ずつ要求すると、IP単位の制限を通過した合計リクエストが単一の
GITHUB_TOKENに集中し、通常の認証済み時間クォータを超えます。クォータ枯渇後のGitHubの403応答はデフォルト値へフォールスルーするため、アバターや統計が欠落したOG画像が200で返され、最大24時間キャッシュされます。How this was verified: IP単位の毎分50件制限から、異なるユーザー名への共有トークン付きAPI呼び出しと非OK応答時のフォールバックまでを追跡しました。
Context Used: 日本語で!!! (source)
Knowledge Base Used: Card Data Pipeline
Prompt To Fix With AI