-
-
Notifications
You must be signed in to change notification settings - Fork 885
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
Improved validation of display names (Fixes #3436) #3437
Conversation
Fixed validation of display names: reject names beginning with invisible unicode characters.
Formatting fix.
crates/utils/src/utils/validation.rs
Outdated
@@ -24,6 +24,9 @@ const BIO_MAX_LENGTH: usize = 300; | |||
const SITE_NAME_MAX_LENGTH: usize = 20; | |||
const SITE_NAME_MIN_LENGTH: usize = 1; | |||
const SITE_DESCRIPTION_MAX_LENGTH: usize = 150; | |||
const FORBIDDEN_DISPLAY_CHARS: [char; 7] = [ | |||
'@', '\u{180e}', '\u{200b}', '\u{2060}', '\u{2800}', '\u{3164}', '\u{ffef}', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a reference for this list? The site below lists even more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used this: https://unicode-explorer.com/articles/space-characters and manually tested most of them, added those that worked. Your list is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please include a comment with the link as well, and mention that these are specifically invisible chars.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
crates/utils/src/utils/validation.rs
Outdated
@@ -42,8 +45,7 @@ pub fn is_valid_actor_name(name: &str, actor_name_max_length: usize) -> LemmyRes | |||
|
|||
// Can't do a regex here, reverse lookarounds not supported | |||
pub fn is_valid_display_name(name: &str, actor_name_max_length: usize) -> LemmyResult<()> { | |||
let check = !name.starts_with('@') | |||
&& !name.starts_with('\u{200b}') | |||
let check = !name.starts_with(FORBIDDEN_DISPLAY_CHARS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about disallowing these chars anywhere in the name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented. Check for '@' is still done only for the first letter.
…for disallowed characters anywhere in the name.
Updated with expanded list of forbidden characters and check for occurrences anywhere in the name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I'll let nutomic also approve.
Fixed validation of display names: reject names beginning with invisible unicode characters.
Fixes #3436