Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matomo recording the same IP for all clients #280

Closed
jefferya opened this issue Jun 6, 2023 · 1 comment · Fixed by #281
Closed

Matomo recording the same IP for all clients #280

jefferya opened this issue Jun 6, 2023 · 1 comment · Fixed by #281

Comments

@jefferya
Copy link
Contributor

jefferya commented Jun 6, 2023

When using Isle-buildkit Tag 2.0.0, regardless of the client IP used to access the Drupal site, Matomo is recording a 172.22.0.0 IP address as opposed to the client IP. Are others experiencing this?

Diagnostics:

$_SERVER['HTTP_X_FORWARDED_FOR'] is correct within the Matomo container. Verified by checking Matomo->Administration->Diagnotics->phpinfo -- $_SERVER['HTTP_X_FORWARDED_FOR'] = my_routable_public_ip_address. Traefik appears to be properly forwarding the client IP in the header.

Checking to see if Matomo is setup correctly:

$ ./console config:get General.proxy_client_headers
"HTTP_X_FORWARDED_FOR"

The above looks correct as per:

Trying an experiment, let's set an array instead of a single value for proxy_client_headers:

  • create array value via "proxy_client_headers[]" (note the [])
$ ./console config:set --section="General" --key="proxy_client_headers[]" --value="${MATOMO_PROXY_CLIENT_HEADERS}"

$ ./console config:get General.proxy_client_headers
["HTTP_X_FORWARDED_FOR"]

Matomo is now recording the correct client IP (i.e., 172.22.0.0 private IP representing Docker)

A fix might be changing

add_setting General proxy_client_headers "${MATOMO_PROXY_CLIENT_HEADERS}"

To (untested) a version with [] as part of the key

    add_setting General "proxy_client_headers[]" "${MATOMO_PROXY_CLIENT_HEADERS}"

I think the reason the array works but not the single value assignment of proxy_client_headers is the the Matomo code is clobbering the value here (though I might be misunderstanding the usage of the @ in this context):

        $general = Config::getInstance()->General;
        $clientHeaders = @$general['proxy_client_headers'];
        if (!is_array($clientHeaders)) {
            $clientHeaders = array();
        }

https://github.com/matomo-org/matomo/blob/5505608c6504f80e5f4bcbc609370180489d420c/core/IP.php#L48-L52

@nigelgbanks
Copy link
Contributor

I've tested your suggested fix and it works. I'll raise a pull request and tag you on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants