zencart / zencart

Zen Cart® is a full-function e-commerce application for your website.
https://github.com/zencart/zencart/releases
Other
375 stars 233 forks source link

Notices when Non-empty call to navigationHistory->set_snapshot() #4675

Closed mc12345678 closed 2 years ago

mc12345678 commented 2 years ago

Describe the bug If a call to the class navigationHistory->set_snapshot() is made with an array that does not include all four keys (page, mode, get, and post) then a notice is generated in stricter versions of PHP or when PHP is in strict mode.

in the method definition: https://github.com/zencart/zencart/blob/7bd505d5bfb3bf1f471be5f9a6c8edd056d43128/includes/classes/navigation_history.php#L101-L125

all four of the keys must be defined to prevent generating a notice; however, nowhere in a default Zen Cart install are all four keys defined when calling this method. At most 2 keys are given.

Based on how the keys were otherwise treated when not provided, would recommend "presetting" the get and post keys to an empty array if they are not present in passing the array.

Generally, the only time that this appears to be the case is when effectively the customer is not logged in and trying to access specific pages.

Version Zen Cart version: 1.5.7c (see that same exists in 1.5.8) PHP version: 7.4 MySQL version: N/A Plugins that may be related: N/A What older/newer versions were also tested?

To Reproduce Steps to reproduce/demonstrate the behavior:

  1. Add a product to the cart.
  2. Go to: domain.name ?main_page=checkout_confirmation

Expected behavior No logs generated.

Debug/Error Logs

[05-Mar-2022 02:40:40 UTC] Request URI: /index.php?main_page=checkout_confirmation, IP address: XXX.XXX.XXX.XXX
#1  navigationHistory->set_snapshot() called at [//includes/modules/pages/checkout_confirmation/header_php.php:21]
#2  require(//includes/modules/pages/checkout_confirmation/header_php.php) called at [//index.php:35]
--> PHP Notice: Undefined index: get in //includes/classes/navigation_history.php on line 107.

[05-Mar-2022 02:40:40 UTC] Request URI: /index.php?main_page=checkout_confirmation, IP address: XXX.XXX.XXX.XXX
#1  navigationHistory->set_snapshot() called at [//includes/modules/pages/checkout_confirmation/header_php.php:21]
#2  require(//includes/modules/pages/checkout_confirmation/header_php.php) called at [//index.php:35]
--> PHP Notice: Undefined index: post in //includes/classes/navigation_history.php on line 108.
scottcwilson commented 2 years ago

Can't repro on PHP 7.4 or PHP 8.0. What are you doing to put your cart into strict mode?

lat9 commented 2 years ago

Can't repro on PHP 7.4 or PHP 8.0. What are you doing to put your cart into strict mode?

Just like @mc12345678 indicated. While not logged in, place an item into the cart, then navigate (via change to the browser's address) to /index.php?main_page=checkout_confirmation; the logs were generated in that case.

scottcwilson commented 2 years ago

I tried this and didn't get a log, but as long as you have fixed and verified, I'm happy.