matomo-org / matomo

Empowering People Ethically with the leading open source alternative to Google Analytics that gives you full control over your data. Matomo lets you easily collect data from websites & apps and visualise this data and extract insights. Privacy is built-in. Liberating Web Analytics. Star us on Github? +1. And we love Pull Requests!
https://matomo.org/
GNU General Public License v3.0
19.83k stars 2.64k forks source link

Missing delimiter for preg_match pattern in UrlHelper::inArrayMatchesRegex #22248

Closed jberiksen closed 5 months ago

jberiksen commented 5 months ago

I got this errors in my log preg_match(): Delimiter must not be alphanumeric or backslash in /core/UrlHelper.php:41 preg_match(): Delimiter must not be alphanumeric or backslash in /core/UrlHelper.php:46

Matomo version: 5.0.3 PHP version: 8.1.28

As I see the solution could be this lines insted Line 41: if(@preg_match("/$val/", null) === false) { Line 46: if( preg_match("/$val/", $test) === 1 ) {

michalkleiner commented 5 months ago

Do you know what value is passed in that triggers the error?

michalkleiner commented 5 months ago

Maybe we need to add some preg_quote but that's just a quess.

jberiksen commented 5 months ago

http://analytics.domain.com/js/tracker.php?action_name=Page&idsite=239&rec=1&r=196996&h=0&m=9&s=10&url=https%3A%2F%2Fdomain1.com%2Fpath%2Fto%2F&urlref=https%3A%2F%2Fndomain1.com%path%2F%3Fgad_source%3D1&_id=8f59a8753e5ef63d&_idn=1&send_image=0&_refts=0&pv_id=ReafHI&pf_net=225&pf_srv=1016&pf_tfr=0&pf_dm1=381&uadata=%7B%7D&pdf=1&qt=0&realp=0&wma=0&fla=0&java=0&ag=0&cookie=1&res=414x896

If the value in urlref not contians a query, there is no error.

jberiksen commented 5 months ago

There is another issue

I got also this error preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /core/UrlHelper.php:41

Here my tracker link is, and here there is no error when there isn't any query in url http://analytics.domain.com/js/tracker.php?action_name=Page&idsite=239&rec=1&r=199007&h=9&m=35&s=46&url=https%3A%2F%2Fdomain1.com%2F%3Fgclid%3DEAIaIQobChMIm5qWt-OlhgMVwKaDBx06oxN7EAEYASAAEgKAK_D_BwE&urlref=https%3A%2F%2Fimasdk.googleapis.com%2F&_id=2802b6abea349840&_idn=0&send_image=0&_refts=1716535947&_ref=https%3A%2F%2Fimasdk.googleapis.com%2F&pv_id=xGxHis&pf_net=0&pf_srv=1073&pf_tfr=1&pf_dm1=103&uadata=%7B%22fullVersionList%22%3A%5B%7B%22brand%22%3A%22Chromium%22%2C%22version%22%3A%22122.0.6261.112%22%7D%2C%7B%22brand%22%3A%22Not(A%3ABrand%22%2C%22version%22%3A%2224.0.0.0%22%7D%2C%7B%22brand%22%3A%22Google%20Chrome%22%2C%22version%22%3A%22122.0.6261.112%22%7D%5D%2C%22mobile%22%3Afalse%2C%22model%22%3A%22%22%2C%22platform%22%3A%22macOS%22%2C%22platformVersion%22%3A%2213.1.0%22%7D&pdf=1&qt=0&realp=0&wma=0&fla=0&java=0&ag=0&cookie=1&res=1440x900

Edit: This is only an error that shows with my suggested change, so my first idea didn't fix the issue.

sgiehl commented 5 months ago

The problem is in our code. We are using preg_match($pattern, null) to check if a regex is valid. This might throw a notice on newer php versions. I'll prepare a PR to fix that.