Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Timo Ley
synapse
Commits
85eea3de
Commit
85eea3de
authored
2 years ago
by
Tulir Asokan
Browse files
Options
Downloads
Patches
Plain Diff
Allow registering invalid user IDs with admin API
parent
a0d31861
No related branches found
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/handlers/register.py
+30
-20
30 additions, 20 deletions
synapse/handlers/register.py
with
30 additions
and
20 deletions
synapse/handlers/register.py
+
30
−
20
View file @
85eea3de
...
...
@@ -141,22 +141,25 @@ class RegistrationHandler:
localpart
:
str
,
guest_access_token
:
Optional
[
str
]
=
None
,
assigned_user_id
:
Optional
[
str
]
=
None
,
allow_invalid
:
bool
=
False
,
inhibit_user_in_use_error
:
bool
=
False
,
)
->
None
:
if
types
.
contains_invalid_mxid_characters
(
localpart
):
raise
SynapseError
(
400
,
"
User ID can only contain characters a-z, 0-9, or
'
=_-./
'"
,
Codes
.
INVALID_USERNAME
,
)
# meow: allow admins to register invalid user ids
if
not
allow_invalid
:
if
types
.
contains_invalid_mxid_characters
(
localpart
):
raise
SynapseError
(
400
,
"
User ID can only contain characters a-z, 0-9, or
'
=_-./
'"
,
Codes
.
INVALID_USERNAME
,
)
if
not
localpart
:
raise
SynapseError
(
400
,
"
User ID cannot be empty
"
,
Codes
.
INVALID_USERNAME
)
if
not
localpart
:
raise
SynapseError
(
400
,
"
User ID cannot be empty
"
,
Codes
.
INVALID_USERNAME
)
if
localpart
[
0
]
==
"
_
"
:
raise
SynapseError
(
400
,
"
User ID may not begin with _
"
,
Codes
.
INVALID_USERNAME
)
if
localpart
[
0
]
==
"
_
"
:
raise
SynapseError
(
400
,
"
User ID may not begin with _
"
,
Codes
.
INVALID_USERNAME
)
user
=
UserID
(
localpart
,
self
.
hs
.
hostname
)
user_id
=
user
.
to_string
()
...
...
@@ -170,14 +173,16 @@ class RegistrationHandler:
"
A different user ID has already been registered for this session
"
,
)
self
.
check_user_id_not_appservice_exclusive
(
user_id
)
# meow: allow admins to register reserved user ids and long user ids
if
not
allow_invalid
:
self
.
check_user_id_not_appservice_exclusive
(
user_id
)
if
len
(
user_id
)
>
MAX_USERID_LENGTH
:
raise
SynapseError
(
400
,
"
User ID may not be longer than %s characters
"
%
(
MAX_USERID_LENGTH
,),
Codes
.
INVALID_USERNAME
,
)
if
len
(
user_id
)
>
MAX_USERID_LENGTH
:
raise
SynapseError
(
400
,
"
User ID may not be longer than %s characters
"
%
(
MAX_USERID_LENGTH
,),
Codes
.
INVALID_USERNAME
,
)
users
=
await
self
.
store
.
get_users_by_id_case_insensitive
(
user_id
)
if
users
:
...
...
@@ -287,7 +292,12 @@ class RegistrationHandler:
await
self
.
auth_blocking
.
check_auth_blocking
(
threepid
=
threepid
)
if
localpart
is
not
None
:
await
self
.
check_username
(
localpart
,
guest_access_token
=
guest_access_token
)
allow_invalid
=
by_admin
and
self
.
hs
.
config
.
meow
.
admin_api_register_invalid
await
self
.
check_username
(
localpart
,
guest_access_token
=
guest_access_token
,
allow_invalid
=
allow_invalid
,
)
was_guest
=
guest_access_token
is
not
None
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment