🔒 Fix missing authentication on card API endpoint#380
Conversation
Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
Warning Review limit reached
More reviews will be available in 16 minutes and 3 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more credits in the billing tab to continue. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the 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 include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 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 |
There was a problem hiding this comment.
Code Review
This pull request introduces authentication checks to the GET /api/card/[username] API route using getAuthenticatedUser, returning a 401 Unauthorized response if the user is not authenticated. It also adds corresponding unit tests to verify this behavior and updates existing tests to mock a successful authentication. Additionally, the Edge runtime configuration was removed from the route. Feedback indicates that a temporary test execution artifact (test-results/.last-run.json) was accidentally committed and should be removed and added to .gitignore.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| { | ||
| "status": "failed", | ||
| "failedTests": [] | ||
| } No newline at end of file |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
| const user = await getAuthenticatedUser(); | ||
| if (!user) { | ||
| return renderErrorCardResponse({ | ||
| message: "Unauthorized", | ||
| options, | ||
| status: 401, | ||
| cacheControl: ERROR_CACHE, | ||
| fontUrl, | ||
| allowedOrigin, | ||
| }); | ||
| } |
There was a problem hiding this comment.
ERROR_CACHE = "public, s-maxage=60, stale-while-revalidate=120" を 401 レスポンスにそのまま使用しています。Vercel の Edge Network など CDN は s-maxage が明示的に指定されている場合に 401 レスポンスをキャッシュする場合があります。認証していないリクエストが先に届くと、その CDN キャッシュが 60 秒間残り、同じ URL を後からリクエストした認証済みユーザーにも 401 が返ってしまいます。認証の成否はリクエストごとの Session 依存なので、401 には no-store または private を使うべきです。
| const user = await getAuthenticatedUser(); | |
| if (!user) { | |
| return renderErrorCardResponse({ | |
| message: "Unauthorized", | |
| options, | |
| status: 401, | |
| cacheControl: ERROR_CACHE, | |
| fontUrl, | |
| allowedOrigin, | |
| }); | |
| } | |
| const user = await getAuthenticatedUser(); | |
| if (!user) { | |
| return renderErrorCardResponse({ | |
| message: "Unauthorized", | |
| options, | |
| status: 401, | |
| cacheControl: "no-store", | |
| fontUrl, | |
| allowedOrigin, | |
| }); | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/app/api/card/[username]/route.ts
Line: 24-34
Comment:
**401レスポンスへのパブリックキャッシュ適用が危険**
`ERROR_CACHE = "public, s-maxage=60, stale-while-revalidate=120"` を 401 レスポンスにそのまま使用しています。Vercel の Edge Network など CDN は `s-maxage` が明示的に指定されている場合に 401 レスポンスをキャッシュする場合があります。認証していないリクエストが先に届くと、その CDN キャッシュが 60 秒間残り、同じ URL を後からリクエストした認証済みユーザーにも 401 が返ってしまいます。認証の成否はリクエストごとの Session 依存なので、401 には `no-store` または `private` を使うべきです。
```suggestion
const user = await getAuthenticatedUser();
if (!user) {
return renderErrorCardResponse({
message: "Unauthorized",
options,
status: 401,
cacheControl: "no-store",
fontUrl,
allowedOrigin,
});
}
```
How can I resolve this? If you propose a fix, please make it concise.| { | ||
| "status": "failed", | ||
| "failedTests": [] | ||
| } No newline at end of file |
There was a problem hiding this comment.
test-results/.last-run.json の "status": "failed" はテスト実行が失敗した状態でコミットされていることを示しています。failedTests 配列は空ですが、テストランナー自体が正常に完了していない可能性があります。また、このファイルは .gitignore に含まれておらず、今後も生成のたびにコミット対象になる恐れがあります。.gitignore に test-results/ を追加することを推奨します。
Prompt To Fix With AI
This is a comment left during a code review.
Path: test-results/.last-run.json
Line: 1-4
Comment:
**テスト失敗状態のファイルがコミットされています**
`test-results/.last-run.json` の `"status": "failed"` はテスト実行が失敗した状態でコミットされていることを示しています。`failedTests` 配列は空ですが、テストランナー自体が正常に完了していない可能性があります。また、このファイルは `.gitignore` に含まれておらず、今後も生成のたびにコミット対象になる恐れがあります。`.gitignore` に `test-results/` を追加することを推奨します。
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
🎯 What: Added authentication checks to the
src/app/api/card/[username]/route.tsAPI endpoint.🛡️ Solution: Integrated the existing
getAuthenticatedUser()utility to protect the route. If a user is not authenticated, the route now correctly returns a 401 Unauthorized status with a rendered error card image. Modified the route to remove the unsupported Edge runtime declaration (since authentication checks require Node APIs here) and updated the corresponding test suite.PR created automatically by Jules for task 11135183214603674343 started by @is0692vs
Greptile Summary
このPRは
/api/card/[username]エンドポイントにgetAuthenticatedUser()による認証チェックを追加し、未認証リクエストに 401 を返すよう変更します。また、Node.js APIが必要なためEdgeランタイム宣言を削除し、テストスイートを更新しています。getAuthenticatedUser()を利用しており、パターン自体は既存コードと一致しています。public, s-maxage=60が適用されており、CDN が 401 をキャッシュした場合、認証済みユーザーへのリクエストも同じキャッシュを受け取るリスクがあります。no-storeへの変更が必要です。test-results/.last-run.jsonが失敗状態のまま新規追加されており、.gitignoreへの追加も必要です。Confidence Score: 3/5
認証チェック自体の実装は正しいが、401 レスポンスのキャッシュ設定を修正せずにマージすると CDN キャッシュ汚染が発生する可能性があり、このままのマージは推奨しない。
401 レスポンスに
public, s-maxage=60が設定されていることで、CDN が認証失敗レスポンスをキャッシュし、認証済みユーザーにも返してしまうリスクがある。また、テスト結果ファイルが失敗状態でコミットされている点も信頼性を下げる要因となっている。主に
src/app/api/card/[username]/route.tsのキャッシュ設定と、test-results/.last-run.jsonの取り扱いに注意が必要。Security Review
src/app/api/card/[username]/route.ts): 401 Unauthorized レスポンスにCache-Control: public, s-maxage=60が設定されており、CDN がこのレスポンスをキャッシュする場合がある。未認証リクエストが先に届いた場合、後続の認証済みリクエストにもキャッシュ済み 401 が返ることで、実質的にサービス拒否が発生しうる。no-storeへの変更で対処可能。Important Files Changed
getAuthenticatedUser()による認証チェックを追加し、edgeランタイム宣言を削除。ただし 401 レスポンスにpublic, s-maxage=60キャッシュを適用しているため、CDN キャッシュ汚染のリスクあり。beforeEachで認証済みユーザーのモックを設定。テスト構造は適切だが、test-results/.last-run.jsonが失敗状態でコミットされている点が懸念。"status": "failed")のファイルが新規追加されており、.gitignoreにも含まれていないため不要なファイルが管理対象になっている。Sequence Diagram
sequenceDiagram participant Client as クライアント participant CDN as CDN (Edge Network) participant Route as /api/card/[username] participant Auth as getAuthenticatedUser() participant Fetcher as fetchCardData() Client->>CDN: GET /api/card/alice CDN->>Route: キャッシュミス → フォワード Route->>Auth: セッション確認 alt 未認証 Auth-->>Route: null Route-->>CDN: "401 + Cache-Control: public, s-maxage=60" CDN-->>Client: 401 (キャッシュ保存) Note over CDN: 60秒間キャッシュ汚染 Client->>CDN: GET /api/card/alice (認証済み) CDN-->>Client: キャッシュ済み401を返却 else 認証済み Auth-->>Route: "{username, token}" Route->>Fetcher: fetchCardData(username) Fetcher-->>Route: CardData Route-->>CDN: "200 + Cache-Control: public, s-maxage=1800" CDN-->>Client: カード画像 endPrompt To Fix All With AI
Reviews (1): Last reviewed commit: "🔒 Fix missing authentication on card AP..." | Re-trigger Greptile
Context used: