Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/app/api/card/[username]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

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.

Suggested change
let allowedOrigin = process.env.APP_URL;
let allowedOrigin = process.env.APP_URL?.trim();

if (!allowedOrigin) {
if (process.env.NODE_ENV === "production") {
return new Response("Server configuration error: APP_URL environment variable is not set", { status: 500 });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 security エラーレスポンスのボディに内部の環境変数名 (APP_URL) がそのまま含まれており、クライアントに不要な実装詳細を公開しています。攻撃者が設定ミスをスキャンする際のヒントになり得るため、汎用的なメッセージに留めることを推奨します。

Suggested change
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!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 レスポンス形式の不整合

このエンドポイントの他のすべてのエラーパス(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.

}
allowedOrigin = "http://localhost:3000";
}
const fontUrl = `${allowedOrigin}/fonts/NotoSans-Regular.ttf`;

const ip = getClientIp(request);
Expand Down
Loading