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

A Broken slur filter regex can stunlock the site #2900

Closed
makotech222 opened this issue Jun 3, 2023 · 9 comments
Closed

A Broken slur filter regex can stunlock the site #2900

makotech222 opened this issue Jun 3, 2023 · 9 comments
Labels
bug Something isn't working extra: good first issue Good for newcomers

Comments

@makotech222
Copy link
Collaborator

A regex that fails to compile gives the following error

image

Which will prevent people from posting/commenting. Also prevents admins from saving site settings, required admin to make manual changes to db to clear the regex.

@makotech222 makotech222 added the bug Something isn't working label Jun 3, 2023
@dessalines
Copy link
Member

Hrm, could have sworn we validate that it's okay regex before saving, but maybe not. This is a good first issue.

@dessalines dessalines added the extra: good first issue Good for newcomers label Jun 4, 2023
@tuxiqae
Copy link

tuxiqae commented Jun 7, 2023

I would love some pointers on how to confront that issue

@tuxiqae
Copy link

tuxiqae commented Jun 7, 2023

@makotech222 Could you please provide examples to the pattern which caused this issue?

@makotech222
Copy link
Collaborator Author

slrfilter.txt

excuse the slurs, obviously.

@Nutomic
Copy link
Member

Nutomic commented Jun 8, 2023

Slur filter is updated here, so you need to compile the regex from data and return an error if it fails.

https://github.com/LemmyNet/lemmy/blob/main/crates/api_crud/src/site/update.rs#L113

@multiplicitypoe
Copy link

multiplicitypoe commented Jun 12, 2023

This happened to me with a very simple filter, and prevented any user from posting on the site or the admins from updating settings to fix it.

(foo|bar|)

Note how the last part of the regex has nothing after the |, meaning it matches anything.

To fix this for my instance, I followed these steps

ssh you@yourdomain.com
sudo docker ps | grep postgres # This prints the container you'll need to go into 
# Example output: be98b4276de6   postgres:15-alpine           "docker-entrypoint.s…"   3 days ago       Up 3 days       5432/tcp                             website_name_postgres_1
sudo docker exec -it /bin/bash website_name_postgres_1
psql -U lemmy # get into the postgres database
# The following commands are to be typed/pasted into the psql prompt
# Confirms you can see slur_filter_regex as a column in the local site table
SELECT column_name FROM information_schema.columns WHERE table_name   = 'local_site';
# See the value of slur_filter_regex, confirming it's incorrect
SELECT slur_filter_regex FROM local_site;
# Adjust slur filter regex to something that won't soft lock the site. Note that this affects all slur filter regexes, if you have more than one in your psql database for some reason
UPDATE local_site SET slur_filter_regex = '(dont-edit-this)';

And this resolved my issue 😄

Hope this helps anyone seeing this in the future

I'd suggest prioritizing this issue, since new moderators coming from Reddit in the next few days will probably want to import slur filters and make mistakes while doing so.

@ContemporaryArtwork
Copy link

ContemporaryArtwork commented Jun 16, 2023

Hi, I tried my hand at this issue and I seem to have gotten a working solution. When testing locally, it's able to read the inputted regex and return an error if it's invalid. This is pretty much my first time writing Rust code so sorry if it's poorly written. Also, I'm not sure what the procedure is for getting this reviewed or if I need to write any tests.

Code comparison:
main...ContemporaryArtwork:regex-fix

Thanks.

ninanator added a commit to ninanator/lemmy that referenced this issue Jun 16, 2023
…e along with small validation organization
@dcormier
Copy link

dcormier commented Jun 16, 2023

@ContemporaryArtwork, I'd recommend against using catch_unwind() for this. Instead the error should be handled. build_slur_regex() may need to be modified to handle the error, or to return a Result so the error can be handled.

From the catch_unwind() docs:

It is not recommended to use this function for a general try/catch mechanism. The Result type is more appropriate to use for functions that can fail on a regular basis. Additionally, this function is not guaranteed to catch all panics, see the “Notes” section below.

@ContemporaryArtwork
Copy link

ContemporaryArtwork commented Jun 16, 2023

@dcormier Yeah, that makes sense. Somehow I missed that part of the docs.

ContemporaryArtwork pushed a commit to ContemporaryArtwork/lemmy-regex-fix that referenced this issue Jun 17, 2023
…hen a regex fails to compile by returning a LemmyError, also returns a LemmyError when the input regex string reference is None (Not sure if that'll ever happen)
ContemporaryArtwork pushed a commit to ContemporaryArtwork/lemmy-regex-fix that referenced this issue Jun 17, 2023
ContemporaryArtwork pushed a commit to ContemporaryArtwork/lemmy-regex-fix that referenced this issue Jun 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working extra: good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

7 participants