fastly/fastly-magento2

PHP 8.1 Issue with saving rate limiting function

bugcskai opened this issue · 0 comments

System Usage
Version PHP 8.1
Maria Db
Magento 2.4.4
Composer 2

When using the

The line impacted seems to be located here, when the rate limiting path does not exist in the database, the retrieval returns null and the line evaluates into a warning:
https://github.com/fastly/fastly-magento2/blob/master/Controller/Adminhtml/FastlyCdn/RateLimiting/ToggleRateLimiting.php

The warning is as below:

{"status":false,"msg":"Deprecated Functionality: json_decode(): Passing null to parameter #1 ($json) of type string is deprecated in /app/3dnmb2vtbqzfq_stg/vendor/fastly/magento2/Controller/Adminhtml/FastlyCdn/RateLimiting/ToggleRateLimiting.php on line 270"}

Description of the deprecating function is noted here as well:
https://php.watch/versions/8.1/internal-func-non-nullable-null-deprecation

To reproduce the issue you can try saving enabling path protection with PHP81 and it would give you the error if no path is specified, trying to work around this by attempting to insert paths would not work because the path protection needs to be first enabled in order to do so.

image

Additional info:
Similarly this is the data in the DB

select * from core_config_data where path like '%rate_limit%';
+-----------+---------+----------+----------------------------------------------------------------------------------------------------------+-------+---------------------+
| config_id | scope   | scope_id | path                                                                                                     | value | updated_at          |
+-----------+---------+----------+----------------------------------------------------------------------------------------------------------+-------+---------------------+
|      1108 | default |        0 | system/full_page_cache/fastly/fastly_rate_limiting_settings/enable_rate_limiting_master                  | 1     | 2022-07-19 00:25:55 |
|      1111 | default |        0 | system/full_page_cache/fastly/fastly_rate_limiting_settings/enable_rate_limiting_logging                 | 0     | 2020-08-17 09:08:18 |
|      1114 | default |        0 | system/full_page_cache/fastly/fastly_rate_limiting_settings/crawler_protection/enable_crawler_protection | 0     | 2020-08-17 09:08:18 |
|      1117 | default |        0 | system/full_page_cache/fastly/fastly_rate_limiting_settings/crawler_protection/exempt_good_bots          | 1     | 2020-08-17 09:08:18 |
+-----------+---------+----------+----------------------------------------------------------------------------------------------------------+-------+---------------------+
4 rows in set (0.00 sec)
+-----------+---------+----------+----------------------------------------------------------------------------------------------------------+-------+---------------------+
| config_id | scope   | scope_id | path                                                                                                     | value | updated_at          |
+-----------+---------+----------+----------------------------------------------------------------------------------------------------------+-------+---------------------+
|      1108 | default |        0 | system/full_page_cache/fastly/fastly_rate_limiting_settings/enable_rate_limiting_master                  | 1     | 2022-07-19 00:25:55 |
|      1111 | default |        0 | system/full_page_cache/fastly/fastly_rate_limiting_settings/enable_rate_limiting_logging                 | 0     | 2020-08-17 09:08:18 |
|      1114 | default |        0 | system/full_page_cache/fastly/fastly_rate_limiting_settings/crawler_protection/enable_crawler_protection | 0     | 2020-08-17 09:08:18 |
|      1117 | default |        0 | system/full_page_cache/fastly/fastly_rate_limiting_settings/crawler_protection/exempt_good_bots          | 1     | 2020-08-17 09:08:18 |
+-----------+---------+----------+----------------------------------------------------------------------------------------------------------+-------+---------------------+
4 rows in set (0.00 sec)

Can we give this a check and implement a null check if possible for all json_decode functions straight from the database?