-
Notifications
You must be signed in to change notification settings - Fork 0
🔒 Fix fallback of allowedOrigin to localhost in production #381
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -17,7 +17,13 @@ export async function GET( | |||||
| const { username } = await params; | ||||||
| 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; | ||||||
| if (!allowedOrigin) { | ||||||
| if (process.env.NODE_ENV === "production") { | ||||||
| return new Response("Server configuration error: APP_URL environment variable is not set", { status: 500 }); | ||||||
|
Contributor
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.
Suggested change
Prompt To Fix With AIThis 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!
Contributor
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. このエンドポイントの他のすべてのエラーパス(429・404・503)は Prompt To Fix With AIThis 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. |
||||||
| } | ||||||
| allowedOrigin = "http://localhost:3000"; | ||||||
| } | ||||||
| const fontUrl = `${allowedOrigin}/fonts/NotoSans-Regular.ttf`; | ||||||
|
|
||||||
| const ip = getClientIp(request); | ||||||
|
|
||||||
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.
Trimming the
APP_URLenvironment 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.