From bf4da27fc6042c9a0031fec0f587a095cf313969 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 4 Apr 2018 14:52:12 -0700 Subject: [PATCH] ircd::m: Ensure X-Matrix content is properly excluded or included for verification. --- ircd/m/request.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ircd/m/request.cc b/ircd/m/request.cc index 915b54122..d5535e097 100644 --- a/ircd/m/request.cc +++ b/ircd/m/request.cc @@ -199,9 +199,18 @@ const 1_MiB }; + // Matrix spec sez that an empty content object {} is excluded entirely + // from the verification. Our JSON only excludes members if they evaluate + // to undefined i.e json::object{}/string_view{} but not json::object{"{}"} + // or even json::object{""}; rather than burdening the caller with ensuring + // their assignment conforms perfectly, we ensure correctness manually. + auto _this(*this); + if(empty(json::get<"content"_>(*this))) + json::get<"content"_>(_this) = json::object{}; + const size_t request_size { - json::serialized(*this) + json::serialized(_this) }; const ctx::critical_assertion ca; @@ -217,7 +226,7 @@ const const json::object object { - stringify(mutable_buffer{buf}, *this) + stringify(mutable_buffer{buf}, _this) }; return verify(pk, sig, object);