ログの出力で X-Forwarded-For が考慮されていない
- Dominant language
- PHP
- Stars
- 13
- Forks
- 26
- PR merge metrics
- No merged PRs in 30d
Description
## 概要(Overview)
下記の部分ですが `REMOTE_ADDR` を返しているためロードバランサー等を使用している環境ではログに出力される IP がすべてロードバランサーの IP になってしまいます。
https://github.com/EC-CUBE/ec-cube3/blob/14cd0cf79cec92be106bccb26eb3b84146b75876/src/Eccube/Log/Monolog/Processor/WebProcessor.php#L51-L54
## 期待する内容(Expect) or 要望 (Requirement)
X-Forwarded-For が存在する場合は X-Forwarded-For の値を返す方が良いのですが、以下の選択肢が出てくると思います。
`,` が増えても問題ないのであれば X-Forwarded-For を返す(`,` でログをパースしている場合に影響が出る可能性あり)
```diff
--- /dev/fd/63 2020-06-28 23:29:21.090798138 +0900
+++ src/Eccube/Log/Monolog/Processor/WebProcessor.php 2020-06-28 23:28:21.496937570 +0900
@@ -50,6 +50,9 @@
public function getClientIp()
{
+ if (!empty($this->serverData['HTTP_X_FORWARDED_FOR'])) {
+ return $this->serverData['HTTP_X_FORWARDED_FOR'];
+ }
return isset($this->serverData['REMOTE_ADDR']) ? $this->serverData['REMOTE_ADDR'] : null;
}
```
`,` が増えると問題になる場合は X-Forwarded-For の一番左を返す(一番左にクライアント IP が入っていることを信頼する場合)
```diff
--- /dev/fd/63 2020-06-28 23:29:21.090798138 +0900
+++ src/Eccube/Log/Monolog/Processor/WebProcessor.php 2020-06-28 23:28:21.496937570 +0900
@@ -50,6 +50,9 @@
public function getClientIp()
{
+ if (!empty($this->serverData['HTTP_X_FORWARDED_FOR'])) {
+ return array_map('trim', explode(',', $this->serverData['HTTP_X_FORWARDED_FOR']))[0];
+ }
return isset($this->serverData['REMOTE_ADDR']) ? $this->serverData['REMOTE_ADDR'] : null;
}
```
ロードバランサー下で使うことを前提としておらず、各々のカスタマイズの範疇ということであればご放念ください。
## 再現手順(Procedure)
ロードバランサーを使用している環境。
### 環境 (environment)
+ EC-CUBE: 3.x.x
+ PHP: 7.x.x
+ DB:
- PostgreSQL x.x.x
- MySQL x.x.x
## 関連情報 (Ref)
Contributor guide
Assessment
This issue has not been assessed yet.