🔒 Fix fallback of allowedOrigin to localhost in production#381
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 10 minutes and 13 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 (1)
✨ 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 improves environment variable validation in the card API route by returning a 500 error in production if the APP_URL environment variable is not configured. The reviewer suggested trimming APP_URL to prevent issues with accidental leading or trailing whitespace.
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.
| const url = new URL(request.url); | ||
| const options = parseCardQueryParams(url.searchParams); | ||
| const allowedOrigin = process.env.APP_URL || "http://localhost:3000"; | ||
| let allowedOrigin = process.env.APP_URL; |
There was a problem hiding this comment.
Trimming the APP_URL environment variable prevents potential issues caused by accidental leading or trailing whitespace in configuration files, which could otherwise result in malformed font URLs or failed origin validation checks.
| let allowedOrigin = process.env.APP_URL; | |
| let allowedOrigin = process.env.APP_URL?.trim(); |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
| let allowedOrigin = process.env.APP_URL; | ||
| if (!allowedOrigin) { | ||
| if (process.env.NODE_ENV === "production") { | ||
| return new Response("Server configuration error: APP_URL environment variable is not set", { status: 500 }); |
There was a problem hiding this comment.
エラーレスポンスのボディに内部の環境変数名 (
APP_URL) がそのまま含まれており、クライアントに不要な実装詳細を公開しています。攻撃者が設定ミスをスキャンする際のヒントになり得るため、汎用的なメッセージに留めることを推奨します。
| return new Response("Server configuration error: APP_URL environment variable is not set", { status: 500 }); | |
| return new Response("Server configuration error", { status: 500 }); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/app/api/card/[username]/route.ts
Line: 23
Comment:
エラーレスポンスのボディに内部の環境変数名 (`APP_URL`) がそのまま含まれており、クライアントに不要な実装詳細を公開しています。攻撃者が設定ミスをスキャンする際のヒントになり得るため、汎用的なメッセージに留めることを推奨します。
```suggestion
return new Response("Server configuration error", { status: 500 });
```
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!
| let allowedOrigin = process.env.APP_URL; | ||
| if (!allowedOrigin) { | ||
| if (process.env.NODE_ENV === "production") { | ||
| return new Response("Server configuration error: APP_URL environment variable is not set", { status: 500 }); |
There was a problem hiding this comment.
このエンドポイントの他のすべてのエラーパス(429・404・503)は renderErrorCardResponse を通じて SVG カードを返しますが、この 500 レスポンスのみプレーンテキストを返します。クライアント(<img> タグ等)が常に SVG を期待している場合、APP_URL が未設定の本番環境でデプロイされたとき破損した表示になります。renderErrorCardResponse で統一するか、Content-Type: image/svg+xml を明示することを検討してください。
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/app/api/card/[username]/route.ts
Line: 23
Comment:
**レスポンス形式の不整合**
このエンドポイントの他のすべてのエラーパス(429・404・503)は `renderErrorCardResponse` を通じて SVG カードを返しますが、この 500 レスポンスのみプレーンテキストを返します。クライアント(`<img>` タグ等)が常に SVG を期待している場合、`APP_URL` が未設定の本番環境でデプロイされたとき破損した表示になります。`renderErrorCardResponse` で統一するか、`Content-Type: image/svg+xml` を明示することを検討してください。
How can I resolve this? If you propose a fix, please make it concise.
🎯 What: The vulnerability fixed
In
src/app/api/card/[username]/route.ts, if theAPP_URLenvironment variable is not explicitly set, theallowedOriginfalls back tohttp://localhost:3000.This insecure fallback might cause fonts or other internal fetch requests to hit a local developer endpoint instead of the intended service in production environments. Crucially, this variable is used via
renderCardResponseas the trustedallowedOrigininisTrustedFontUrl(invalidators.ts), potentially meaning that the production environment would implicitly trustlocalhost:3000URLs when it shouldn't.🛡️ Solution: How the fix addresses the vulnerability
The code now properly verifies the presence of the
APP_URLenvironment variable. IfAPP_URLis empty and the environment isproduction, the server now explicitly returns a500 Server configuration error. In non-production environments, it safely falls back tohttp://localhost:3000.PR created automatically by Jules for task 9766932802489647517 started by @is0692vs
Greptile Summary
本番環境で
APP_URL環境変数が未設定の場合にlocalhost:3000へフォールバックしていた問題を修正するPRです。NODE_ENV === \"production\"のときは明示的に 500 を返し、それ以外の環境では従来通りlocalhost:3000にフォールバックします。APP_URLが未設定かつ本番環境の場合、500 エラーを即時返却するよう変更。http://localhost:3000へのフォールバックを許容。Confidence Score: 4/5
変更は1ファイル・数行のみで、本番環境での設定ミスを早期に検出するための防御的なガードです。マージ自体のリスクは低い。
修正は意図通りに機能しており、ロジックも明確です。ただし 500 レスポンスのボディが内部環境変数名を公開している点と、他のエラーレスポンスと形式が異なる点(プレーンテキスト vs SVG カード)が残っています。
src/app/api/card/[username]/route.ts — 500 エラーのレスポンス形式とメッセージ内容を確認してください。
Security Review
APP_URLがそのまま含まれており、設定ミスの詳細をクライアントに公開しています。汎用的なメッセージ(例:"Server configuration error")に変更することを推奨します。isTrustedFontUrlは HTTPS のみを許可し、getTrustedFontOriginsも HTTPS オリジンのみをホワイトリストに追加するため、旧来のhttp://localhost:3000フォールバックは実際には信頼済みオリジンとして機能しなかった点に注意してください。今回の修正は防御的に正しい方向ですが、実際の悪用経路は限定的でした。Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[GET /api/card/:username] --> B[process.env.APP_URL 取得] B --> C{APP_URL は設定済み?} C -- はい --> G[allowedOrigin = APP_URL] C -- いいえ --> D{NODE_ENV === production?} D -- はい --> E[500 Server configuration error を返す] D -- いいえ 開発環境 --> F[allowedOrigin = http://localhost:3000] F --> G G --> H[fontUrl 組み立て] H --> I{レートリミット超過?} I -- はい --> J[renderErrorCardResponse 429] I -- いいえ --> K[fetchCardData] K --> L{data あり?} L -- いいえ --> M[renderErrorCardResponse 404] L -- はい --> N[renderCardResponse 200] K -- 例外 --> O[renderErrorCardResponse 503]Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "Fix APP_URL environment variable fallbac..." | Re-trigger Greptile