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

strip some unicodes from public username #3365

Merged
merged 3 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [ "master", "next", "stable-*" ]
pull_request:
branches: [ "master", "next" ]
branches: [ "master", "next", "stable-*" ]
schedule:
- cron: '26 15 * * 4'

Expand Down
19 changes: 11 additions & 8 deletions lib/Service/SystemService.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
use Psr\Log\LoggerInterface;

class SystemService {
private const REGEX_INVALID_USERNAME_CHARACTERS = '/[\x{2000}-\x{206F}]/u';

/**
* @psalm-suppress PossiblyUnusedMethod
*/
Expand Down Expand Up @@ -195,6 +197,7 @@ public function getGenericLanguage(): string {
* @return string returns the allowed username
*/
public function validatePublicUsername(string $userName, ?Share $share = null, ?string $token = null): string {
$userName = trim(preg_replace(self::REGEX_INVALID_USERNAME_CHARACTERS, '', $userName));
if (!$userName) {
throw new TooShortException('Username must not be empty');
}
Expand All @@ -205,38 +208,38 @@ public function validatePublicUsername(string $userName, ?Share $share = null, ?
return $userName;
}

$userName = strtolower(trim($userName));
$compareUserName = strtolower($userName);

// reserved usernames
if (str_contains($userName, 'deleted user') || str_contains($userName, 'anonymous')) {
if (str_contains($compareUserName, 'deleted user') || str_contains($compareUserName, 'anonymous')) {
throw new InvalidUsernameException;
}

// get all groups, that include the requested username in their gid
// or displayname and check if any match completely
foreach (Group::search($userName) as $group) {
if ($group->hasName($userName)) {
foreach (Group::search($compareUserName) as $group) {
if ($group->hasName($compareUserName)) {
throw new InvalidUsernameException;
}
}

// get all users
foreach (User::search($userName) as $user) {
if ($user->hasName($userName)) {
foreach (User::search($compareUserName) as $user) {
if ($user->hasName($compareUserName)) {
throw new InvalidUsernameException;
}
}

// get all participants
foreach ($this->voteMapper->findParticipantsByPoll($share->getPollId()) as $vote) {
if ($vote->getUser()->hasName($userName)) {
if ($vote->getUser()->hasName($compareUserName)) {
throw new InvalidUsernameException;
}
}

// get all shares for this poll
foreach ($this->shareMapper->findByPoll($share->getPollId()) as $share) {
if ($share->getType() !== Circle::TYPE && $share->getUser()->hasName($userName)) {
if ($share->getType() !== Circle::TYPE && $share->getUser()->hasName($compareUserName)) {
throw new InvalidUsernameException;
}
}
Expand Down
Loading