feat(auth): check if X-Matrix destination is correct if present
This commit is contained in:
parent
b4a60c3f9a
commit
63ba157ef6
1 changed files with 13 additions and 0 deletions
|
@ -175,6 +175,15 @@ where
|
||||||
Error::BadRequest(ErrorKind::Forbidden, msg)
|
Error::BadRequest(ErrorKind::Forbidden, msg)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
if let Some(dest) = x_matrix.destination {
|
||||||
|
if dest != services().globals.server_name() {
|
||||||
|
return Err(Error::BadRequest(
|
||||||
|
ErrorKind::Unauthorized,
|
||||||
|
"X-Matrix destination field does not match server name.",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let origin_signatures = BTreeMap::from_iter([(
|
let origin_signatures = BTreeMap::from_iter([(
|
||||||
x_matrix.key.clone(),
|
x_matrix.key.clone(),
|
||||||
CanonicalJsonValue::String(x_matrix.sig),
|
CanonicalJsonValue::String(x_matrix.sig),
|
||||||
|
@ -332,6 +341,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
struct XMatrix {
|
struct XMatrix {
|
||||||
|
destination: Option<OwnedServerName>,
|
||||||
origin: OwnedServerName,
|
origin: OwnedServerName,
|
||||||
key: String, // KeyName?
|
key: String, // KeyName?
|
||||||
sig: String,
|
sig: String,
|
||||||
|
@ -353,6 +363,7 @@ impl Credentials for XMatrix {
|
||||||
let mut origin = None;
|
let mut origin = None;
|
||||||
let mut key = None;
|
let mut key = None;
|
||||||
let mut sig = None;
|
let mut sig = None;
|
||||||
|
let mut destination = None;
|
||||||
|
|
||||||
for entry in parameters.split_terminator(',') {
|
for entry in parameters.split_terminator(',') {
|
||||||
let (name, value) = entry.split_once('=')?;
|
let (name, value) = entry.split_once('=')?;
|
||||||
|
@ -369,6 +380,7 @@ impl Credentials for XMatrix {
|
||||||
"origin" => origin = Some(value.try_into().ok()?),
|
"origin" => origin = Some(value.try_into().ok()?),
|
||||||
"key" => key = Some(value.to_owned()),
|
"key" => key = Some(value.to_owned()),
|
||||||
"sig" => sig = Some(value.to_owned()),
|
"sig" => sig = Some(value.to_owned()),
|
||||||
|
"destination" => destination = Some(value.try_into().ok()?),
|
||||||
_ => debug!(
|
_ => debug!(
|
||||||
"Unexpected field `{}` in X-Matrix Authorization header",
|
"Unexpected field `{}` in X-Matrix Authorization header",
|
||||||
name
|
name
|
||||||
|
@ -377,6 +389,7 @@ impl Credentials for XMatrix {
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(Self {
|
Some(Self {
|
||||||
|
destination,
|
||||||
origin: origin?,
|
origin: origin?,
|
||||||
key: key?,
|
key: key?,
|
||||||
sig: sig?,
|
sig: sig?,
|
||||||
|
|
Loading…
Add table
Reference in a new issue