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

fixed filtering by array keys instead of array values #28

Merged
merged 7 commits into from May 28, 2021
Merged

fixed filtering by array keys instead of array values #28

merged 7 commits into from May 28, 2021

Conversation

ghost
Copy link

@ghost ghost commented May 24, 2021

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 stklcode changed the base branch from stable to develop May 24, 2021 16:31
@stklcode stklcode added the bug label May 24, 2021
@stklcode
Copy link
Owner

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 stklcode added this to the 1.6.1 milestone May 24, 2021
The user agent filer list is not flipped with the actual values as keys
like the lists for referrer and target. Hence the numeric keys are
compared against the actual user agent. We now flip the values in the
upgrade hook.
@stklcode
Copy link
Owner

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?

@stklcode stklcode merged commit 6ffa650 into stklcode:develop May 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant