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

PHP Deprecation - fnmatch(): Passing null to parameter #2 ($filename) of type string is deprecated #13270

Closed
1 task done
csgerg opened this issue Jan 27, 2024 · 4 comments · Fixed by #13615
Closed
1 task done
Labels
bug Issues or PR's relating to bugs T1 Low difficulty to fix (issue) or test (PR) tracking Anything related to tracking

Comments

@csgerg
Copy link

csgerg commented Jan 27, 2024

Mautic Version

5.0.x series

PHP version

8.1.27

What browsers are you seeing the problem on?

Firefox

What happened?

After visit the login pages it creates journal entry in the error_log what is in installation root folder.

Mautic version: 5.0.2

How can we reproduce this issue?

Open login url: /s/login

Relevant log output

PHP Deprecation - fnmatch(): Passing null to parameter #2 ($filename) of type string is deprecated - in file /app/middlewares/CORSMiddleware.php - at line 107
PHP Deprecated:  fnmatch(): Passing null to parameter #2 ($filename) of type string is deprecated in /app/middlewares/CORSMiddleware.php on line 107

Code of Conduct

  • I confirm that I have read and agree to follow this project's Code of Conduct




Care about this issue? Want to get it resolved sooner? If you are a member of Mautic, you can add some funds to the Bounties Project so that the person who completes this task can claim those funds once it is merged by a member of the core team! Read the docs here.

@csgerg csgerg added bug Issues or PR's relating to bugs needs-triage For new issues/PRs that need to be triaged labels Jan 27, 2024
@J-Wick4
Copy link

J-Wick4 commented Feb 23, 2024

This code got rid of the error in the logs.
Can someone verify it?

The error message indicates that passing null as the $filename parameter to the fnmatch() function is deprecated. This is happening because the $origin variable may be null in some cases.

To fix this error, you can add a check to ensure that $origin is not null before calling fnmatch(). Here's an updated version of the code:

 // Check the domains using shell wildcard patterns
 $validCorsDomainFilter = function ($validCorsDomain) use ($origin) {
     if ($origin === null) {
         return false;
     }
     return fnmatch($validCorsDomain, $origin, FNM_CASEFOLD);
 };

 if (array_filter($this->validCORSDomains, $validCorsDomainFilter)) {
     $this->requestOriginIsValid = true;
     $this->corsHeaders['Vary']  = 'Origin';

     return $origin;
 }

 $this->requestOriginIsValid = false;

 return null;

This adds an additional check to ensure that $origin is not null before calling fnmatch(). If $origin is null, the filter will return false and the function will continue as before.

@back-2-95
Copy link

I just setup a new Mautic install for production and our logs are filled with this deprecation notice.

@RCheesley RCheesley added tracking Anything related to tracking T1 Low difficulty to fix (issue) or test (PR) and removed needs-triage For new issues/PRs that need to be triaged labels Apr 9, 2024
@RCheesley
Copy link
Sponsor Member

Looks like we have a fix in #13270 folks - please check and test, and remember to leave your review!

Docs here for how to review & test: https://mau.tc/tester (you can do it in the browser using Gitpod).

Thanks in advance for helping get this into a future release of Mautic!

escopecz added a commit that referenced this issue May 2, 2024
* If $origin is null, return false. Fixes issue #13270. Credit to @J-Wick4.

* Yoda style coding standards.

* Change return value to null to match @return annotation

Co-authored-by: John Linhart <jan@linhart.email>

---------

Co-authored-by: John Linhart <jan@linhart.email>
Co-authored-by: Ruth Cheesley <ruth@ruthcheesley.co.uk>
Copy link
Contributor

github-actions bot commented May 2, 2024

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If this issue is continuing with the lastest stable version of Mautic, please open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues or PR's relating to bugs T1 Low difficulty to fix (issue) or test (PR) tracking Anything related to tracking
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants