0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-25 23:14:13 +01:00

modules/federation: Employ check_id() at endpoints claiming event_id path param.

This commit is contained in:
Jason Volk 2019-07-10 00:25:42 -07:00
parent 639b132250
commit 9d5edac0b9
3 changed files with 15 additions and 37 deletions

View file

@ -86,37 +86,15 @@ put__invite(client &client,
request["event"], event_id
};
char check_buf[48];
m::event::id check_id; switch(hash(room_version))
{
case "1"_:
case "2"_:
check_id = json::get<"event_id"_>(event)?
m::event::id{json::get<"event_id"_>(event)}:
event_id;
if(!json::get<"event_id"_>(event))
if(room_version == "1" || room_version == "2")
json::get<"event_id"_>(event) = event_id;
// put back the event_id that synapse stripped
json::get<"event_id"_>(event) = check_id;
assert(json::get<"event_id"_>(event) == check_id);
break;
case "3"_:
check_id = m::event::id::v3{check_buf, event};
break;
case "4"_:
case "5"_:
default:
check_id = m::event::id::v4{check_buf, event};
break;
}
if(!check_id || event_id != check_id)
if(!check_id(event, room_version))
throw m::BAD_REQUEST
{
"Claimed event_id %s does not match %s",
"Claimed event_id %s is incorrect.",
string_view{event_id},
string_view{check_id},
};
if(at<"room_id"_>(event) != room_id)

View file

@ -63,14 +63,14 @@ put__send_join(client &client,
const m::event event
{
request
request, event_id
};
if(at<"event_id"_>(event) != event_id)
throw m::error
if(!check_id(event))
throw m::BAD_REQUEST
{
http::NOT_MODIFIED, "M_MISMATCH_EVENT_ID",
"ID of event in request body does not match path parameter."
"ID of event in request does not match path parameter %s",
string_view{event_id},
};
if(at<"room_id"_>(event) != room_id)

View file

@ -63,14 +63,14 @@ put__send_leave(client &client,
const m::event event
{
request
request, event_id
};
if(at<"event_id"_>(event) != event_id)
throw m::error
if(!check_id(event))
throw m::BAD_REQUEST
{
http::NOT_MODIFIED, "M_MISMATCH_EVENT_ID",
"ID of event in request body does not match path parameter."
"ID of event in request does not match path parameter %s",
string_view{event_id},
};
if(at<"room_id"_>(event) != room_id)