fix: trust proxy を設定して req.ip を正しくクライアントIPに解決

nginx リバースプロキシ背後では req.ip がプロキシの内部 IP になる問題を修正。
app.set('trust proxy', 1) で X-Forwarded-For を信頼し、IP ベースの
レート制限(together/ponshu)が実際のクライアント IP で動作するようにする。

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
posimai 2026-04-20 13:34:22 +09:00
parent 548c4fcca2
commit ec51c2ed6b
1 changed files with 2 additions and 0 deletions

View File

@ -116,6 +116,8 @@ async function createSessionJWT(userId) {
}
const app = express();
// nginx リバースプロキシ背後のため X-Forwarded-For を信頼して req.ip を正しく解決
app.set('trust proxy', 1);
// Stripe Webhook は raw body が必要なため、webhook パスのみ json パースをスキップ
app.use((req, res, next) => {
if (req.path === '/brain/api/stripe/webhook' || req.path === '/api/stripe/webhook') {