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

Use https for urls in visitor details if host is defined with https in site #17151

Merged
merged 7 commits into from Mar 11, 2021
32 changes: 32 additions & 0 deletions plugins/Actions/VisitorDetails.php
Expand Up @@ -16,6 +16,7 @@
use Piwik\Piwik;
use Piwik\Plugin;
use Piwik\Plugins\Live\VisitorDetailsAbstract;
use Piwik\Plugins\SitesManager\API as APISitesManager;
use Piwik\Site;
use Piwik\Tracker\Action;
use Piwik\Tracker\PageUrl;
Expand Down Expand Up @@ -160,6 +161,14 @@ public function extendActionDetails(&$action, $nextAction, $visitorDetails)
unset($action['url_prefix']);
}

if (array_key_exists('url', $action) && strpos($action['url'], 'http://') === 0) {
$host = parse_url($action['url'], PHP_URL_HOST);

if ($host && $this->shouldUseHttpsHost($visitorDetails['idSite'], $host)) {
$action['url'] = 'https://' . substr($action['url'], 7);
sgiehl marked this conversation as resolved.
Show resolved Hide resolved
}
}
sgiehl marked this conversation as resolved.
Show resolved Hide resolved

switch ($action['type']) {
case 'goal':
$action['icon'] = 'plugins/Morpheus/images/goal.png';
Expand Down Expand Up @@ -252,6 +261,29 @@ public function extendActionDetails(&$action, $nextAction, $visitorDetails)
unset($action['idlink_va']);
}

private function shouldUseHttpsHost($idSite, $host)
{
static $siteUrlCache = [];
sgiehl marked this conversation as resolved.
Show resolved Hide resolved
static $hostSiteCache = [];

if (empty($siteUrlCache[$idSite])) {
$siteUrlCache[$idSite] = APISitesManager::getInstance()->getSiteUrlsFromId($idSite);
}

if (!isset($hostSiteCache[$idSite][$host])) {
$hostSiteCache[$idSite][$host] = false;

foreach ($siteUrlCache[$idSite] as $siteUrl) {
if (strpos(strtolower($siteUrl), strtolower('https://' . $host)) === 0) {
$hostSiteCache[$idSite][$host] = true;
break;
}
}
}

return $hostSiteCache[$idSite][$host];
}

/**
* @param $idVisit
* @return array
Expand Down