codeigniter4 / CodeIgniter4

Open Source PHP Framework (originally from EllisLab)
https://codeigniter.com/
MIT License
5.4k stars 1.9k forks source link

Bug: app.proxyIPs must be array and can't be loaded from dotenv. #7034

Closed runnermatthew closed 1 year ago

runnermatthew commented 1 year ago

PHP Version

8.0

CodeIgniter4 Version

4.2.11

CodeIgniter4 Installation Method

Composer (as dependency to an existing project)

Which operating systems have you tested for this bug?

Linux

Which server did you use?

apache

Database

PostgreSQL 13.9

What happened?

4.2.11 set the following requirement for in Config/App.php for public $proxyIPs

@var array<string, string>

CodeIgniter4 has no way to set arrays from dotenv. This forces an App.php config file in addition to dotenv for each deploy.

Steps to Reproduce

In Config/App.php set public $proxyIPs = [];

In dotenv set app.proxyIPs =['172.25.0.1/16'=>'X-Forwarded-For'] where 172.25.0.1/16 covers your reverse proxy IPs. $request->getIPAddress() still returns proxy IP address

Expected Output

$request->getIPAddress() to return the IP set by the proxy server in the X-Forwarded-For header.

Anything else?

No response

kenjis commented 1 year ago

This is not a bug.

Environment variables are not PHP variables. dotenv dose not support array like this: app.proxyIPs = ['172.25.0.1/16'=>'X-Forwarded-For']

Why don't you set them in the Config file?

kenjis commented 1 year ago

Workaround is to add the constructor in Config\App, and set $proxyIPs from environment variables.

runnermatthew commented 1 year ago

Why don't you set them in the Config file?

I'd like to limit the configuration of each stack to their dotenv file.

Workaround is to add the constructor in Config\App, and set $proxyIPs from environment variables.

This is the route I'll take. Thank you for the suggestion.