Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
conduwuit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
🥺
conduwuit
Commits
e0419d9c
Commit
e0419d9c
authored
1 year ago
by
🥺
Committed by
🥺
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
custom room ID checks, dont use format! macro due to quotes being added
Signed-off-by:
strawberry
<
strawberry@puppygock.gay
>
parent
7eff572e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/api/client_server/room.rs
+36
-7
36 additions, 7 deletions
src/api/client_server/room.rs
with
36 additions
and
7 deletions
src/api/client_server/room.rs
+
36
−
7
View file @
e0419d9c
...
@@ -28,7 +28,7 @@
...
@@ -28,7 +28,7 @@
};
};
use
serde_json
::{
json
,
value
::
to_raw_value
};
use
serde_json
::{
json
,
value
::
to_raw_value
};
use
std
::{
cmp
::
max
,
collections
::
BTreeMap
,
sync
::
Arc
};
use
std
::{
cmp
::
max
,
collections
::
BTreeMap
,
sync
::
Arc
};
use
tracing
::{
error
,
info
,
warn
};
use
tracing
::{
debug
,
error
,
info
,
warn
};
/// # `POST /_matrix/client/v3/createRoom`
/// # `POST /_matrix/client/v3/createRoom`
///
///
...
@@ -70,12 +70,41 @@ pub async fn create_room_route(
...
@@ -70,12 +70,41 @@ pub async fn create_room_route(
if
let
Some
(
CanonicalJsonValue
::
Object
(
json_body
))
=
&
body
.json_body
{
if
let
Some
(
CanonicalJsonValue
::
Object
(
json_body
))
=
&
body
.json_body
{
match
json_body
.get
(
"room_id"
)
{
match
json_body
.get
(
"room_id"
)
{
Some
(
custom_room_id
)
=>
{
Some
(
custom_room_id
)
=>
{
room_id
=
RoomId
::
parse
(
format!
(
let
custom_room_id_s
=
custom_room_id
.to_string
();
"!{}:{}"
,
custom_room_id
,
// do some checks on the custom room ID similar to room aliases
services
()
.globals
.server_name
()
if
custom_room_id_s
.contains
(
':'
)
{
))
return
Err
(
Error
::
BadRequest
(
.map_err
(|
e
|
{
ErrorKind
::
InvalidParam
,
"Custom room ID contained `:` which is not allowed.
Please note that this expects a localpart, not the full room ID."
,
));
}
else
if
custom_room_id_s
.contains
(
char
::
is_whitespace
)
{
return
Err
(
Error
::
BadRequest
(
ErrorKind
::
InvalidParam
,
"Custom room ID contained spaces which is not valid."
,
));
}
else
if
custom_room_id_s
.len
()
>
255
{
return
Err
(
Error
::
BadRequest
(
ErrorKind
::
InvalidParam
,
"Custom room ID is too long."
,
));
}
let
full_room_id
=
"!"
.to_owned
()
+
custom_room_id_s
.as_str
()
+
":"
+
services
()
.globals
.server_name
()
.as_ref
();
debug!
(
"Full room ID: {}"
,
full_room_id
);
if
full_room_id
.contains
(
'"'
)
{
return
Err
(
Error
::
BadRequest
(
ErrorKind
::
InvalidParam
,
"Custom room ID contained `
\"
` which is not allowed."
,
));
}
room_id
=
RoomId
::
parse
(
full_room_id
)
.map_err
(|
e
|
{
info!
(
info!
(
"User attempted to create room with custom room ID but failed parsing: {}"
,
"User attempted to create room with custom room ID but failed parsing: {}"
,
e
e
...
...
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