trim white space after comma ', ' if several allowed ip in settings field

Created on 7 March 2023, over 1 year ago

Problem/Motivation

If more than one ip are entered in the allowed ips field in settings, one may add a space after comma by habit or for better readability. E.g.: "123.456.789.123, 456.789.101, 127.0.0.1" instead of "123.456.789.123,456.789.101,127.0.0.1". Of course this can happen even with just one ip, e.g. "127.0.0.1 " instead of "127.0.0.1".
When the calling ip is tasted against the allowed ips inside function elysia_cron_run, values of the array obtained by exploding the allowed ips string must be trimmed in order to eliminate possible unwanted white spaces.

Steps to reproduce

Enter an ip with spaces in the allowed ips field as of the examples above, then try to run the cron. Cron fails to run because the allowed ip is not recognized.

Proposed resolution

Around line 1270 of elysia_cron.module:

      // if ($allowed_hosts && !in_array(ip_address(), explode(',', $allowed_hosts))) {
      if ($allowed_hosts && !in_array(ip_address(), array_map('trim', explode(',', $allowed_hosts)))) {

At the same time we can improve the debug message:

        // elysia_cron_debug('Cron ip address mismatch, skipping run');
        elysia_cron_debug('Cron ip address mismatch, skipping run. Calling ip: %ip.', ['%ip' => ip_address()]);

Displaying the calling ip was especially useful to debug when an server send a short ipv6 address while in allowed ip field I had the full ipv6 ip.

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Active

Version

2.9

Component

Code

Created by

🇫🇷France erwangel

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024