T357772: Investigate: How will `ip_in_range` and `ip_in_ranges` function when temporary accounts are enabled introduces the user_ip variable, which is considered PII and therefore has legal restrictions around retention and viewing. As of writing, AbuseFilter allows filters to be made private but variables and conditions have no concept of being "protected." We should introduce the concept of a protected variable which will then have effect on filter visibility.
This draws from some of the notes and solutions in T234155 but is split off into this ticket as the concept of a CheckUser level filter is a much larger scope than necessary to implement the user_ip variable needed to not break filters when temp accounts roll out.
Proposed Solution:
Variables should be declarable as protected, via a right and the right should be declarable on an individual basis, but isn't required (eg. we might want abusefilter-view-ip and only apply that to user_ip, or we can generalize it later to something like abusefilter-view-pii and have it apply to all protected variables).
The private filter setting shouldn't be changed since it 1. can be toggled on/off, 2. relies on a stricter condition than what user_ip is expected to need, and 3. relies on the user to correctly apply it. Filters should still be able to be made private via the current mechanism and this mechanism should be implemented alongside what already exists.
This mechanism:
- should use a new column, eg. af_protected that takes a running list of user rights which are required to view the filter/logs
- any time a sensitive variable is used, the right required to see that variable should be added to that list
- removing a variable shouldn't remove the right from the list
- should only allow users to add protected variables they have the rights to use (otherwise they'd lock themselves out of their own filter)
- should automatically be enforced on save
- should apply similar permissions to checking edits against filters and other theoretical/testing tools
