diff --git a/changelog.d/SEC28.bugfix.md b/changelog.d/SEC28.bugfix.md new file mode 100644 index 000000000..71a68f2a2 --- /dev/null +++ b/changelog.d/SEC28.bugfix.md @@ -0,0 +1 @@ +Fixed an issue that allowed an attacker to take over another account on the same server under certain conditions. ([GHSA-v2x6-m99h-vqxx](https://github.com/continuwuity/continuwuity/security/advisories/GHSA-v2x6-m99h-vqxx)) Contributed by @gingershaped and reported by GlitchedAxiom. diff --git a/src/service/threepid/mod.rs b/src/service/threepid/mod.rs index 7913980da..c096e6d55 100644 --- a/src/service/threepid/mod.rs +++ b/src/service/threepid/mod.rs @@ -127,6 +127,10 @@ impl Service { // If a validation session already exists for this client secret, we can either // reuse it with a new token or return early because it's already valid. | Some(session) => { + if session.email != recipient.email { + return Err!(Request(InvalidParam("Wrong email for session."))); + } + match session.validation_state { | ValidationState::Validated => { // If the existing session is already valid, don't send an email. @@ -134,7 +138,7 @@ impl Service { }, | ValidationState::Pending(ref mut token) => { // Check ratelimiting for the target address. - if self.ratelimiter.check_key(&recipient.email).is_err() { + if self.ratelimiter.check_key(&session.email).is_err() { return Err(Error::BadRequest( ErrorKind::LimitExceeded(LimitExceededErrorData::new()), "You're sending emails too fast, try again in a few minutes.",