From d89ede5b3e9d5693847448b2c5ddcb0fca809a96 Mon Sep 17 00:00:00 2001 From: Shunji Zhan Date: Thu, 1 Aug 2024 14:57:07 +0800 Subject: [PATCH] use forwarded ip first, bump v1.8.5 --- package.json | 2 +- src/consts.ts | 2 +- src/utils/formatter.ts | 11 +++++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 288da05..6eb32df 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "acala-wormhole-relayer", - "version": "1.8.4", + "version": "1.8.5", "description": "", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/consts.ts b/src/consts.ts index 99339aa..2814c4f 100644 --- a/src/consts.ts +++ b/src/consts.ts @@ -266,4 +266,4 @@ export const MINUTE = 60 * SECOND; export const HOUR = 60 * MINUTE; export const DAY = 24 * HOUR; -export const VERSION = '1.8.4'; +export const VERSION = '1.8.5'; diff --git a/src/utils/formatter.ts b/src/utils/formatter.ts index 6c2d775..9e021bb 100644 --- a/src/utils/formatter.ts +++ b/src/utils/formatter.ts @@ -1,8 +1,15 @@ import { Request } from 'express'; export const parseIp = (req: Request): string => { - const rawIp = req.ip - ?? req.headers['x-forwarded-for'] + const forwardedFor = req.headers['x-forwarded-for']; + const forwardedIp = typeof forwardedFor === 'string' + ? forwardedFor.split(',')[0] + : Array.isArray(forwardedFor) + ? forwardedFor[0] + : undefined; + + const rawIp = forwardedIp + ?? req.ip ?? req.socket.remoteAddress ?? 'unknown';