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

Add more options for global URL parameter exclusions #22729

Open
wants to merge 63 commits into
base: 5.x-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
3abdabe
Update global settings to support excluding common PII params
caddoo Oct 30, 2024
6ff6084
Clean up TS
caddoo Nov 4, 2024
baf1d9d
Add UI screenshots (with some commented)
caddoo Nov 4, 2024
d0fb658
Remove empty test
caddoo Nov 4, 2024
0f30e6d
Fix broken UI test
caddoo Nov 4, 2024
8efbeef
Fix broken UI test
caddoo Nov 4, 2024
8269536
Fix broken integration test
caddoo Nov 4, 2024
4d9cd4d
Merge branch '5.x-dev' into dev-18646-add-button-add-list-of-exclusio…
caddoo Nov 4, 2024
75db8c4
Build vue files
innocraft-automation Nov 4, 2024
639ddcc
Update UI to hide the list of common exclusions
caddoo Nov 4, 2024
cd39b1a
Build vue files
innocraft-automation Nov 4, 2024
84dfef1
Update UI screenshot
caddoo Nov 4, 2024
297f59e
Update UI screenshot
caddoo Nov 4, 2024
7a5b07a
Update API interface to keep data integrity
caddoo Nov 6, 2024
8949a69
Switch to using whitelist validator
caddoo Nov 6, 2024
a53ba24
Update exceptions to be translated, add missing integration test
caddoo Nov 6, 2024
21b31db
Restore commented out UI tests
caddoo Nov 6, 2024
e414625
Remove redundant switch statement
caddoo Nov 7, 2024
73c8350
Add return type
caddoo Nov 7, 2024
a6fec12
Move common PII exclusions to config
caddoo Nov 7, 2024
c8d080d
Translate button text
caddoo Nov 7, 2024
36161ad
Add common PII to config
caddoo Nov 7, 2024
da7bd72
Deprecate setGlobalExcludedQueryParameters
caddoo Nov 7, 2024
b623614
Fix CS issues
caddoo Nov 7, 2024
9288ac5
Build vue files
innocraft-automation Nov 7, 2024
4869ad7
Fix deprecated test and update changelog
caddoo Nov 7, 2024
6b93491
Use test config data for test, remove static copy of common PII
caddoo Nov 7, 2024
c5d3fad
Add missing translation key
caddoo Nov 7, 2024
9ea605a
Update UI screenshots
caddoo Nov 7, 2024
b541e1a
Fix tests
caddoo Nov 7, 2024
4c305c7
Merge branch '5.x-dev' into dev-18646-add-button-add-list-of-exclusio…
caddoo Nov 7, 2024
3af38c1
Update plugins/SitesManager/API.php
caddoo Nov 10, 2024
1476f50
Update plugins/SitesManager/API.php
caddoo Nov 10, 2024
d9236c8
Update plugins/SitesManager/API.php
caddoo Nov 10, 2024
69169d2
Update plugins/SitesManager/vue/src/ManageGlobalSettings/ManageGlobal…
caddoo Nov 10, 2024
31864a1
Reorder and remove duplicates for CommonPII params
caddoo Nov 10, 2024
b80ece9
Clear query parameters when custom_exclusions selected
caddoo Nov 11, 2024
2334c8d
Add missing prop type include
caddoo Nov 11, 2024
0998402
Make old API method more compatible with new methods
caddoo Nov 11, 2024
8200473
Merge branch '5.x-dev' into dev-18646-add-button-add-list-of-exclusio…
caddoo Nov 11, 2024
4f8e909
Fix syntax error
caddoo Nov 11, 2024
b4a9eb9
Fix UI screenshot
caddoo Nov 11, 2024
caa50ca
Build vue files
innocraft-automation Nov 11, 2024
643fa6f
Fix UI screenshot
caddoo Nov 11, 2024
bfca00e
Update plugins/SitesManager/API.php
caddoo Nov 12, 2024
dc7251b
Make sure URL params are cleaned before validation, and add tests
caddoo Nov 13, 2024
54ef856
Remove redundant check
caddoo Nov 13, 2024
a26b1c9
Update naming for the exclusion types
caddoo Nov 13, 2024
69dc3fa
Build vue files
innocraft-automation Nov 14, 2024
a121d18
Update wording once more
caddoo Nov 14, 2024
f973c0c
Update ui screenshots
caddoo Nov 14, 2024
4ab0b83
Update ui screenshots
caddoo Nov 14, 2024
14302c9
Update ui screenshots
caddoo Nov 14, 2024
f9aed0e
Update ui screenshots
caddoo Nov 14, 2024
3afa175
Update expected integration test
caddoo Nov 14, 2024
0787133
Update language again
caddoo Nov 14, 2024
4714d7e
Update integration test expected result
caddoo Nov 14, 2024
ca8ab48
Temp split test to get all screenshots
caddoo Nov 14, 2024
f278b42
Fix broken tests
caddoo Nov 14, 2024
cf3f647
Merge branch '5.x-dev' into dev-18646-add-button-add-list-of-exclusio…
caddoo Nov 14, 2024
f141197
Remove temp tests
caddoo Nov 14, 2024
9463b5c
Split UI tests to "one screenshot per test" for ease of updating
mneudert Nov 14, 2024
af112f5
Remove duplicated translation
mneudert Nov 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The Product Changelog at **[matomo.org/changelog](https://matomo.org/changelog)*

* The methods `Db::isOptimizeInnoDBSupported`, `Db::optimizeTables` have been deprecated. Use `Db\Schema::getInstance()->isOptimizeInnoDBSupported` and `Db\Schema::getInstance()->optimizeTables` instead
* The method `TransactionLevel::setUncommitted` has been deprecated. Use `TransactionLevel::setTransactionLevelForNonLockingReads` instead
* The method `Piwik\Plugins\SitesManager\API::setGlobalExcludedQueryParameters` has been deprecated. Use `Piwik\Plugins\SitesManager\API::setGlobalQueryParamExclusion` instead

### New commands

Expand Down
161 changes: 161 additions & 0 deletions config/global.ini.php
Original file line number Diff line number Diff line change
Expand Up @@ -1325,4 +1325,165 @@
SDK_batch_size = 10
SDK_interval_value = 30

[SitesManager]
CommonPIIParams[] = account
CommonPIIParams[] = accountnum
CommonPIIParams[] = address
CommonPIIParams[] = address1
CommonPIIParams[] = address2
CommonPIIParams[] = address3
CommonPIIParams[] = addressline1
CommonPIIParams[] = addressline2
CommonPIIParams[] = adres
CommonPIIParams[] = adresse
CommonPIIParams[] = age
CommonPIIParams[] = alter
CommonPIIParams[] = auth
CommonPIIParams[] = authpw
CommonPIIParams[] = bic
CommonPIIParams[] = billingaddress
CommonPIIParams[] = billingaddress1
CommonPIIParams[] = billingaddress2
CommonPIIParams[] = calle
CommonPIIParams[] = cardnumber
CommonPIIParams[] = cc
CommonPIIParams[] = ccc
CommonPIIParams[] = cccsc
CommonPIIParams[] = cccvc
CommonPIIParams[] = cccvv
CommonPIIParams[] = ccexpiry
CommonPIIParams[] = ccexpmonth
CommonPIIParams[] = ccexpyear
CommonPIIParams[] = ccname
CommonPIIParams[] = ccnumber
CommonPIIParams[] = cctype
CommonPIIParams[] = cell
CommonPIIParams[] = cellphone
CommonPIIParams[] = city
CommonPIIParams[] = clientid
CommonPIIParams[] = clientsecret
CommonPIIParams[] = company
CommonPIIParams[] = consumerkey
CommonPIIParams[] = consumersecret
CommonPIIParams[] = contrasenya
CommonPIIParams[] = contraseña
CommonPIIParams[] = creditcard
CommonPIIParams[] = creditcardnumber
CommonPIIParams[] = cvc
CommonPIIParams[] = cvv
CommonPIIParams[] = dateofbirth
CommonPIIParams[] = debitcard
CommonPIIParams[] = dirección
CommonPIIParams[] = dob
CommonPIIParams[] = domain
CommonPIIParams[] = ebost
CommonPIIParams[] = email
CommonPIIParams[] = emailaddress
CommonPIIParams[] = emailadresse
CommonPIIParams[] = epos
CommonPIIParams[] = epost
CommonPIIParams[] = eposta
CommonPIIParams[] = exp
CommonPIIParams[] = familyname
CommonPIIParams[] = firma
CommonPIIParams[] = firstname
CommonPIIParams[] = formlogin
CommonPIIParams[] = fullname
CommonPIIParams[] = gender
CommonPIIParams[] = geschlecht
CommonPIIParams[] = gst
CommonPIIParams[] = gstnumber
CommonPIIParams[] = handynummer
CommonPIIParams[] = hasło
CommonPIIParams[] = heslo
CommonPIIParams[] = iban
CommonPIIParams[] = ibanaccountnum
CommonPIIParams[] = ibanaccountnumber
CommonPIIParams[] = id
CommonPIIParams[] = identifier
CommonPIIParams[] = indirizzo
CommonPIIParams[] = kartakredytowa
CommonPIIParams[] = kennwort
CommonPIIParams[] = keyconsumerkey
CommonPIIParams[] = keyconsumersecret
CommonPIIParams[] = konto
CommonPIIParams[] = kontonr
CommonPIIParams[] = kontonummer
CommonPIIParams[] = kredietkaart
CommonPIIParams[] = kreditkarte
CommonPIIParams[] = kreditkort
CommonPIIParams[] = lastname
CommonPIIParams[] = login
CommonPIIParams[] = mail
CommonPIIParams[] = mobiili
CommonPIIParams[] = mobile
CommonPIIParams[] = mobilne
CommonPIIParams[] = nachname
CommonPIIParams[] = name
CommonPIIParams[] = nickname
CommonPIIParams[] = off
CommonPIIParams[] = osoite
CommonPIIParams[] = parole
CommonPIIParams[] = pass
CommonPIIParams[] = passord
CommonPIIParams[] = password
CommonPIIParams[] = passwort
CommonPIIParams[] = pasword
CommonPIIParams[] = paswort
CommonPIIParams[] = paword
CommonPIIParams[] = phone
CommonPIIParams[] = pin
CommonPIIParams[] = plz
CommonPIIParams[] = postalcode
CommonPIIParams[] = postcode
CommonPIIParams[] = postleitzahl
CommonPIIParams[] = privatekey
CommonPIIParams[] = publickey
CommonPIIParams[] = pw
CommonPIIParams[] = pwd
CommonPIIParams[] = pword
CommonPIIParams[] = pwrd
CommonPIIParams[] = rue
CommonPIIParams[] = secret
CommonPIIParams[] = secretq
CommonPIIParams[] = secretquestion
CommonPIIParams[] = shippingaddress
CommonPIIParams[] = shippingaddress1
CommonPIIParams[] = shippingaddress2
CommonPIIParams[] = socialsec
CommonPIIParams[] = socialsecuritynumber
CommonPIIParams[] = socsec
CommonPIIParams[] = sokak
CommonPIIParams[] = ssn
CommonPIIParams[] = steuernummer
CommonPIIParams[] = strasse
CommonPIIParams[] = street
CommonPIIParams[] = surname
CommonPIIParams[] = swift
CommonPIIParams[] = tax
CommonPIIParams[] = taxnumber
CommonPIIParams[] = tel
CommonPIIParams[] = telefon
CommonPIIParams[] = telefonnr
CommonPIIParams[] = telefonnummer
CommonPIIParams[] = telefono
CommonPIIParams[] = telephone
CommonPIIParams[] = token
CommonPIIParams[] = token_auth
CommonPIIParams[] = tokenauth
CommonPIIParams[] = téléphone
CommonPIIParams[] = ulica
CommonPIIParams[] = user
CommonPIIParams[] = username
CommonPIIParams[] = vat
CommonPIIParams[] = vatnumber
CommonPIIParams[] = via
CommonPIIParams[] = vorname
CommonPIIParams[] = wachtwoord
CommonPIIParams[] = wagwoord
CommonPIIParams[] = webhooksecret
CommonPIIParams[] = website
CommonPIIParams[] = zip
CommonPIIParams[] = zipcode

; NOTE: do not directly edit this file! See notice at the top
4 changes: 2 additions & 2 deletions plugins/MobileMessaging/vue/dist/umd.metadata.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 86 additions & 6 deletions plugins/SitesManager/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Matomo\Network\IPUtils;
use Piwik\Access;
use Piwik\Common;
use Piwik\Config;
use Piwik\Container\StaticContainer;
use Piwik\DataAccess\Model as CoreModel;
use Piwik\Date;
Expand All @@ -40,6 +41,7 @@
use Piwik\Translation\Translator;
use Piwik\Url;
use Piwik\UrlHelper;
use Piwik\Validators\WhitelistedValue;

/**
* The SitesManager API gives you full control on Websites in Matomo (create, update and delete), and many methods to retrieve websites based on various attributes.
Expand Down Expand Up @@ -69,6 +71,7 @@ class API extends \Piwik\Plugin\API
public const OPTION_EXCLUDED_USER_AGENTS_GLOBAL = 'SitesManager_ExcludedUserAgentsGlobal';
public const OPTION_EXCLUDED_REFERRERS_GLOBAL = 'SitesManager_ExcludedReferrersGlobal';
public const OPTION_KEEP_URL_FRAGMENTS_GLOBAL = 'SitesManager_KeepURLFragmentsGlobal';
public const OPTION_EXCLUDE_TYPE_QUERY_PARAMS_GLOBAL = 'SitesManager_ExcludeTypeQueryParamsGlobal';

/**
* @var SettingsProvider
Expand Down Expand Up @@ -1123,10 +1126,18 @@ public function getExcludedQueryParameters(int $idSite): array
*
* @return string Comma separated list of URL parameters
*/
public function getExcludedQueryParametersGlobal()
public function getExcludedQueryParametersGlobal(): string
{
Piwik::checkUserHasSomeViewAccess();
return Option::get(self::OPTION_EXCLUDED_QUERY_PARAMETERS_GLOBAL);

switch ($this->getExclusionTypeForQueryParams()) {
case SitesManager::URL_PARAM_EXCLUSION_TYPE_NAME_NO_EXCLUSIONS:
return '';
case SitesManager::URL_PARAM_EXCLUSION_TYPE_NAME_COMMON_PII_EXCLUSIONS:
return implode(',', Config::getInstance()->SitesManager['CommonPIIParams']);
default:
return Option::get(self::OPTION_EXCLUDED_QUERY_PARAMETERS_GLOBAL);
}
}

/**
Expand Down Expand Up @@ -1266,14 +1277,19 @@ public function setKeepURLFragmentsGlobal($enabled)
* Will also apply to websites created in the future.
*
* @param string $excludedQueryParameters Comma separated list of URL query parameters to exclude from URLs
* @deprecated Use self::setGlobalQueryParamExclusion() instead.
caddoo marked this conversation as resolved.
Show resolved Hide resolved
* @return bool
*/
public function setGlobalExcludedQueryParameters($excludedQueryParameters)
{
Piwik::checkUserHasSuperUserAccess();
$excludedQueryParameters = $this->checkAndReturnCommaSeparatedStringList($excludedQueryParameters);
Option::set(self::OPTION_EXCLUDED_QUERY_PARAMETERS_GLOBAL, $excludedQueryParameters);
Cache::deleteTrackerCache();
if (empty($excludedQueryParameters)) {
$this->setGlobalQueryParamExclusion(SitesManager::URL_PARAM_EXCLUSION_TYPE_NAME_NO_EXCLUSIONS);
return;
caddoo marked this conversation as resolved.
Show resolved Hide resolved
}
$this->setGlobalQueryParamExclusion(
SitesManager::URL_PARAM_EXCLUSION_TYPE_NAME_CUSTOM_EXCLUSIONS,
$excludedQueryParameters
);
return true;
}

Expand Down Expand Up @@ -1346,6 +1362,70 @@ public function setDefaultTimezone($defaultTimezone)
return true;
}

/**
* Sets global query parameter exclusion based on the specified exclusion type.
*
* @param string $exclusionType The type of query param exclusion, must be of the following:
* - no_exclusions
* - common_pii_exclusions
* - custom_exclusions
* @param string|null $queryParamsToExclude (Optional) Comma separated list of query parameters to exclude when $exclusionType is 'custom'.
* Ignored if $exclusionType is not 'custom'.
* @return void
* @throws Exception
*/
public function setGlobalQueryParamExclusion(string $exclusionType, ?string $queryParamsToExclude = null): void
caddoo marked this conversation as resolved.
Show resolved Hide resolved
{
Piwik::checkUserHasSuperUserAccess();

$whiteListValidator = new WhitelistedValue(SitesManager::URL_PARAM_EXCLUSION_TYPES);
$whiteListValidator->validate($exclusionType);

if ($exclusionType === SitesManager::URL_PARAM_EXCLUSION_TYPE_NAME_CUSTOM_EXCLUSIONS && empty($queryParamsToExclude)) {
throw new Exception($this->translator->translate('SitesManager_ExceptionEmptyQueryParamsForCustomType'));
}

if ($exclusionType !== SitesManager::URL_PARAM_EXCLUSION_TYPE_NAME_CUSTOM_EXCLUSIONS && !empty($queryParamsToExclude)) {
throw new Exception($this->translator->translate('SitesManager_ExceptionNonEmptyQueryParamsForNonCustomType'));
}

Option::set(self::OPTION_EXCLUDE_TYPE_QUERY_PARAMS_GLOBAL, $exclusionType);

if ($exclusionType !== SitesManager::URL_PARAM_EXCLUSION_TYPE_NAME_CUSTOM_EXCLUSIONS) {
Option::delete(self::OPTION_EXCLUDED_QUERY_PARAMETERS_GLOBAL);
Cache::deleteTrackerCache();
return;
}

$excludedQueryParameters = $this->checkAndReturnCommaSeparatedStringList($queryParamsToExclude);
caddoo marked this conversation as resolved.
Show resolved Hide resolved
Option::set(self::OPTION_EXCLUDED_QUERY_PARAMETERS_GLOBAL, $excludedQueryParameters);
Cache::deleteTrackerCache();
}

/**
* Gets the exclusion type, if the option is not present in the store then it infers the type based on if there are
* custom exclusions already defined.
*
* @return string
*/
public function getExclusionTypeForQueryParams(): string
{
Piwik::checkUserHasSomeViewAccess();

$result = Option::get(self::OPTION_EXCLUDE_TYPE_QUERY_PARAMS_GLOBAL);

if (!empty($result)) {
return $result;
}

$excludedQueryParamsGlobal = Option::get(self::OPTION_EXCLUDED_QUERY_PARAMETERS_GLOBAL);

if (empty($excludedQueryParamsGlobal)) {
return SitesManager::URL_PARAM_EXCLUSION_TYPE_NAME_NO_EXCLUSIONS;
}
return SitesManager::URL_PARAM_EXCLUSION_TYPE_NAME_CUSTOM_EXCLUSIONS;
}

/**
* Update an existing website.
* If only one URL is specified then only the main url will be updated.
Expand Down
16 changes: 14 additions & 2 deletions plugins/SitesManager/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Exception;
use Piwik\API\ResponseBuilder;
use Piwik\Common;
use Piwik\Config;
use Piwik\DataTable\Renderer\Json;
use Piwik\Piwik;
use Piwik\Plugin\Manager;
Expand Down Expand Up @@ -54,7 +55,12 @@ public function globalSettings()
{
Piwik::checkUserHasSuperUserAccess();

return $this->renderTemplate('globalSettings');
return $this->renderTemplate(
'globalSettings',
[
'commonSensitiveQueryParams' => Config::getInstance()->SitesManager['CommonPIIParams']
]
);
}

public function getGlobalSettings()
Expand All @@ -73,6 +79,11 @@ public function getGlobalSettings()
$globalSettings['excludedQueryParametersGlobal'] = API::getInstance()->getExcludedQueryParametersGlobal();
$globalSettings['excludedUserAgentsGlobal'] = API::getInstance()->getExcludedUserAgentsGlobal();
$globalSettings['excludedReferrersGlobal'] = API::getInstance()->getExcludedReferrersGlobal();
$globalSettings['exclusionTypeForQueryParams'] = API::getInstance()->getExclusionTypeForQueryParams();

if ($globalSettings['exclusionTypeForQueryParams'] !== 'custom_exclusions') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ($globalSettings['exclusionTypeForQueryParams'] !== 'custom_exclusions') {
if ($globalSettings['exclusionTypeForQueryParams'] !== SitesManager::URL_PARAM_EXCLUSION_TYPE_NAME_CUSTOM_EXCLUSIONS) {

We should prefer the constant if we have it.

Though I am wondering why we need that check here, and not also in another place where the query parameters are accessed:

public static function getTrackerExcludedQueryParameters($website)
{
$excludedQueryParameters = $website['excluded_parameters'];
$globalExcludedQueryParameters = API::getInstance()->getExcludedQueryParametersGlobal();
$excludedQueryParameters .= ',' . $globalExcludedQueryParameters;
return self::filterBlankFromCommaSepList($excludedQueryParameters);
}

Is there any special case where these two areas should differ in a way that cannot be managed inside the API methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, the controller should be dumb, so I've removed that check. The API handles this already. Take a look and let me know if that's what you are thinking, and you can resolve the thread.

$globalSettings['excludedQueryParametersGlobal'] = '';
}

return $response->getResponse($globalSettings);
}
Expand All @@ -95,16 +106,17 @@ public function setGlobalSettings()
$searchKeywordParameters = Common::getRequestVar('searchKeywordParameters', $default = "");
$searchCategoryParameters = Common::getRequestVar('searchCategoryParameters', $default = "");
$keepURLFragments = Common::getRequestVar('keepURLFragments', $default = 0);
$exclusionTypeForQueryParams = Common::getRequestVar('exclusionTypeForQueryParams', $default = "");

$api = API::getInstance();
$api->setDefaultTimezone($timezone);
$api->setDefaultCurrency($currency);
$api->setGlobalExcludedQueryParameters($excludedQueryParameters);
$api->setGlobalExcludedIps($excludedIps);
$api->setGlobalExcludedUserAgents($excludedUserAgents);
$api->setGlobalExcludedReferrers($excludedReferrers);
$api->setGlobalSearchParameters($searchKeywordParameters, $searchCategoryParameters);
$api->setKeepURLFragmentsGlobal($keepURLFragments);
$api->setGlobalQueryParamExclusion($exclusionTypeForQueryParams, $excludedQueryParameters);

$toReturn = $response->getResponse();
} catch (Exception $e) {
Expand Down
Loading
Loading