-
Notifications
You must be signed in to change notification settings - Fork 46
Add index.php to proxy opt out HTTP requests + fix regressions in curl support. #37
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, I tested it locally and everything works file.
I left two comments with minor nitpicks.
One more thing that might break (or I am misunderstanding something):
Let's say example.com gets tracked by matomo.example.
While normally the optout cookie is just set to matomo.example, with the proxy, the opt-out will be at example.com.
So will it then set the cookie to example.com?
If no, I guess it will fail as it tries to set a cookie to a foreign domain (I guess)
If yes, does Matomo know to handle the opt-out cookie if it is on another domain as itself?
I guess it should work, but I am not completely sure
proxy.php
Outdated
'timeout' => $timeout | ||
'timeout' => $timeout, | ||
|
||
// 'ignore_errors' => true, // uncomment to debug error code responses |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible that this is the wrong way around? If commenting is for debugging, it shouldn't be uncommitted by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s commented so developers don’t have to look it up next time when there is an error and zero output.
matomo-proxy.php
Outdated
$allParams = $_GET + $_POST; | ||
|
||
if (!in_array("{$allParams['module']}.{$allParams['action']}", $SUPPORTED_METHODS)) { | ||
http_response_code(404); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After trying around a bit I couldn't find a way to circumvent this check.
But I noticed that a simple request to matomo-proxy.php
causes an error (because module
and action
are not set), which is a bit ugly.
And the whole security depends on the order of $_GET + $_POST
and the next person to edit this to know that php adds arrays from right to left overwriting POST
by GET
.
If someone switches this around accidentally, all Matomo modules can be accessed:
curl --data "module=CoreAdminHome&action=optOut" "http://localhost/tracker-proxy/matomo-proxy.php?module=Login&idSite=1&period=day&date=yesterday&action=
So I'd at least add a comment so it is clear that this is important. (at least for me it wasn't clear otherwise)
Re cookies: The proxy will just forward the set-cookie header, so the cookies will be associated w/ the tracker-proxy domain. So as long as tracking is done through the tracker-proxy domain, it will receive the ignore cookie. (Tested locally via /etc/hosts). Also checked to see what will happen if the |
… module/action & empty module/action.
Updated to check |
@diosmosis @mattab see my comments in #29 There are 2 problems:
|
…d $DEBUG_PROXY global that can be set during development.
Updated to support http proxy => https matomo. |
@level420 That's a good idea I think, but this would be a core change and improved in the opt-out iframe I believe. so maybe you can create an issue for this idea in https://github.com/matomo-org/matomo/issues ? |
proxy.php
Outdated
@@ -11,6 +11,8 @@ | |||
exit; // this file is not supposed to be accessed directly | |||
} | |||
|
|||
$DEBUG_PROXY = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be more like $NO_VERIFY_SSL
or maybe better IGNORE_HTTP_ERRORS
? or something? DEBUG_PROXY
is good though as well and maybe best 👍 . Would maybe just explain what it does in a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does a couple other things for debugging. I can split it into DEBUG_PROXY and NO_VERIFY_SSL (DEBUG_PROXY also removes error silencing so file_get_contents will spit out error messages).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 if splitted, it would actually allow someone to use it with a self signed certificate etc without silencing other errors 👍
@@ -260,6 +299,14 @@ function getHttpContentAndStatus($url, $timeout, $user_agent) | |||
curl_setopt($ch, CURLOPT_POSTFIELDS, $stream_options['http']['content']); | |||
} | |||
|
|||
if (isset($stream_options['ssl']['verify_peer']) && $stream_options['ssl']['verify_peer'] == false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the same as using DEBUG_PROXY
in the if
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that's done above, this translates the stream options to curl options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I'm getting it. By the looks they are only set to false when using $DEBUG_PROXY = true
correct? I'm thinking instead of translating it might be easier to read by using if($DEBUG_PROXY)
. May be also less fragile if eg for some reason the stream option changes it doesn't change the curl behaviour etc. But I didn't have a deep look I might be missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The existing code follows the pattern of:
- set stream_options for file_get_contents
- if curl, transform already set stream options to curl options
The stream option name won't change, it's the actual php option name. It might change in a PHP version, but that's different than a developer deciding to rename it (which they can't do).
Changes:
matomo-proxy.php
endpoint that only allows proxying the optout method.handleHeaderLine()
to avoid obscure curl error.Cookie
header.Tested w/ fopen & curl.
Fixes #29