stklcode / statify-blacklist

Filter extension for the Statify WordPress plugin
https://wordpress.org/plugins/statify-blacklist/
GNU General Public License v2.0
2 stars 1 forks source link

fixed filtering by array keys instead of array values #28

Closed ghost closed 3 years ago

ghost commented 3 years ago

ua-filter in "keyword"-mode used array keys instead of array values to determine wether to filter request out or not. So for example user-agent "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0" got filtered out on including array keys (0,1,2,3,...).

stklcode commented 3 years ago

Hi @BananaSquishee, thanks very much for your input.

You are right, there is a problem. However your suggested solution breaks referrer and target filters in keyword mode and does not fix the very same issue for other matching modes. I forgot to enable the test action for pull requests in my recent changes, so it's not immediately visible, but all corresponding tests do fail now.

Background: All checks in apply_single_filter (so all but IP) do use array keys by design. That decision was made some way back in time before cron execution for the referrer filter, because isset( $config['blacklist'][ $value ] is the fastest evaluation possible, so the configuration is stored like

array(
    'value1' => 0,
    'value2' => 1,
);

Probably not the best decision, because it's not really intuitive, but that how it works for now.

The actual fault is that the options update does not apply the array_flip() as for referrer URLs, so the user agent names are stored in the wrong order.

stklcode commented 3 years ago

I took the freedom to rework the fix to use uniform storage layout for the options and revert the filter. Requires re-activating the plugin (this is done automatically during update) to migrate existing settings.

I'm somewhat sorry for the not so smooth first-time-contribution experience, but nevertheless I do appreciate bringing this topic up.

Can you verify that the latest solution resolves your problem?